Skip to content

unreachable_pub false negative when type is referenced in a public field, even if it is not reachable #135134

Closed
@djmitche

Description

@djmitche

Code

#![deny(unreachable_pub)]
mod config {
    pub struct AccessMode;
}

pub enum StorageConfig {
    OnDisk(config::AccessMode),
}

Current output

Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.50s

Desired output

error: unreachable `pub` item
 --> src/lib.rs:4:5
  |
4 |     pub struct AccessMode;
  |     ---^^^^^^^^^^^^^^^^^^
  |     |
  |     help: consider restricting its visibility: `pub(crate)`
  |
  = help: or consider exporting it for use by other crates

Rationale and extra context

Changing StorageConfig to

pub struct StorageConfig(config::AccessMode);

produces the desired output, so this is a difference between a reference to a type from an enum variant and a reference to a type from a struct.

Other cases

The same occurs if the enum variant and struct are defined with a named field (`access_mode: config::AccessMode`)

Rust Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-discussionCategory: Discussion or questions that doesn't represent real issues.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