Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message for 'is private' #63942

Open
gilescope opened this issue Aug 27, 2019 · 3 comments
Open

Better error message for 'is private' #63942

gilescope opened this issue Aug 27, 2019 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gilescope
Copy link
Contributor

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.

@gilescope
Copy link
Contributor Author

(Bonus points for a suggestion that foo::bar::A is public and maybe you meant to use that one.)

@varkor varkor added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Aug 27, 2019
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-visibility Area: Visibility / privacy. labels Aug 27, 2019
@kornelski
Copy link
Contributor

Similar to #42909

@steveklabnik
Copy link
Member

Triage:

note: the struct import `A` is defined here...
 --> src/main.rs:2:9
  |
2 |     use bar::A;
  |         ^^^^^^
note: ...and refers to the struct `A` which is defined here
 --> src/main.rs:5:9
  |
5 |         pub struct A {}
  |         ^^^^^^^^^^^^ consider importing it directly

is very similar to

(Bonus points for a suggestion that foo::bar::A is public and maybe you meant to use that one.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants