Skip to content

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

Closed
@mcy

Description

@mcy

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.)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.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