Skip to content

Better error message for 'is private' #63942

Open
@gilescope

Description

@gilescope
mod foo {
    use bar::A;
    
    mod bar {
        pub struct A {}
    }
}

use foo::A;

fn main() {}

Produces the error:

error[E0603]: struct `A` is private
 --> src/main.rs:9:10
  |
9 | use foo::A;
  |          ^

playground link

It would be great if the error message said why the pub struct 'A' is private.
For example something like this:

error[E0603]: struct `A` is private because it is not exported by module foo

This would remove the head scratching time as one looks at the definition of the struct and sees the pub visibility modifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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