Skip to content

Trying to access public function with same name as private field gives confusing error #26472

Closed
@stephenmw

Description

@stephenmw

When trying to access the len of a Vec I forgot the parens. This led to an error message about using a private field which confused me. (Thanks to the IRC for helping me find the problem!)

Code:

use std::vec::Vec;

fn main() {
    let xs: Vec<i32> = Vec::new();
    xs.len;
}

Error:

baderror.rs:5:2: 5:8 error: field `len` of struct `collections::vec::Vec` is private
baderror.rs:5   xs.len;
                ^~~~~~
error: aborting due to previous error
Illegal instruction

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions