Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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