Skip to content

Invalid unreachable_pub suggestion for enum with fields #103317

Closed
@l4l

Description

@l4l

Given the following code:

#[warn(unreachable_pub)]
mod inner {
    #[allow(unused)]
    pub enum T {
        A(u32),
    }
}

The current output is:

warning: unreachable `pub` item
 --> src/main.rs:4:5
  |
4 |     pub enum T {
  |     ---^^^^^^^
  |     |
  |     help: consider restricting its visibility: `pub(crate)`
  |
note: the lint level is defined here
 --> src/main.rs:1:8
  |
1 | #[warn(unreachable_pub)]
  |        ^^^^^^^^^^^^^^^
  = help: or consider exporting it for use by other crates

warning: unreachable `pub` field
 --> src/main.rs:5:11
  |
5 |         A(u32),
  |           -^^
  |           |
  |           help: consider restricting its visibility: `pub(crate)`

Which basically brokes cargo-fix, i.e cargo fix --broken-code produces invalid code:

#[warn(unreachable_pub)]
mod inner {
    #[allow(unused)]
    pub(crate) enum T {
        A(pub(crate)u32),
    }
}

That seems to affect any enum with variant fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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