Skip to content

Error message shows type of private field #57320

Closed
@killercup

Description

@killercup

The code below yields two errors:

  1. The field is private
  2. Type error in if expression because type is <type of private field> instead of bool

This means a user can observe the type of a private field of a dependency in their error messages. It doesn't mean they can actually use that information, but it seems weird at least.

Is this actually an issue? If you don't consider it one, feel free to close this.


fn main() {
    let x = foo::Foo::default();
    if x.len {
        println!("foo");
    }
}

mod foo {
    #[derive(Default)]
    pub struct Foo {
        len: String,
    }
    
    impl Foo {
        pub fn len(&self) -> usize {
            42
        }
    }
}

playground

(originally seen on reddit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions