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

rustc incorrectly suggests a pub(crate) on an enum variant or trait item is "unnecessary", implying it is permitted #109822

Closed
mcy opened this issue Mar 31, 2023 · 1 comment · Fixed by #109923
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-visibility Area: Visibility / privacy D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mcy
Copy link
Contributor

mcy commented Mar 31, 2023

See https://godbolt.org/z/8bWh445hh

Given

enum Foo {
  pub(crate) Bar,
  Baz {
    pub(crate) x: i32,
  },
}

I get

error[E0449]: unnecessary visibility qualifier
 --> <source>:2:3
  |
2 |   pub(crate) Bar,
  |   ^^^^^^^^^^

error[E0449]: unnecessary visibility qualifier
 --> <source>:4:5
  |
4 |     pub(crate) x: i32,
  |     ^^^^^^^^^^

error: aborting due to 2 previous errors

rustc correctly describes these as "unnecessary" when they are a plain pub:

error[E0449]: unnecessary visibility qualifier
 --> <source>:2:3
  |
2 |   pub Bar,
  |   ^^^ `pub` not permitted here because it's implied

rustc should instead state that non-pub visibility qualifiers are not permitted, rather than being unnecessary. I suggest a diagnostic like

error[E0449]: visibility qualifiers are not permitted inside of enums
 --> <source>:2:3
  |
2 |   pub(crate) Bar,
  |   ^^^^^^^^^^ 

(There is a similar diagnostic bug around putting pub(crate) or pub(self) on trait items.)

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-visibility Area: Visibility / privacy T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Apr 3, 2023
@ElectrifyPro
Copy link
Contributor

@rustbot claim

JohnTitor added a commit to JohnTitor/rust that referenced this issue Apr 11, 2023
…iser

Update `error [E0449]: unnecessary visibility qualifier` to be more clear

This updates the error message `error[E0449]: unnecessary visibility qualifier` by clearly indicating that visibility qualifiers already inherit their visibility from a parent item. The error message previously implied that the qualifiers were permitted, which is not the case anymore.

Resolves rust-lang#109822.
@bors bors closed this as completed in 788de47 Apr 11, 2023
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-visibility Area: Visibility / privacy D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. 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.

3 participants