Skip to content

unreachable_pub lint does not fire in the case of partial wildcard shadowing #111360

Open
@jamesmunns

Description

I tried this code:

#![deny(unreachable_pub)]

pub use berp::*;

// 1.
// use darp::Foo;

pub fn example() {
    let _ = Foo;
}

pub mod berp {
    pub struct Foo;
    // 2.
    // pub struct Bar;

    impl Foo {
        pub fn hah(&self) {}
        pub fn hoh(&self) {}
    }
}

pub mod darp {
    pub struct Foo;
}

I expected to see this happen:

When I uncomment 1. (but not 2.) above, the lint correctly fires, and says:

error: unreachable `pub` item
 --> /tmp/breaky/breaky/src/lib.rs:3:9
  |
3 | pub use berp::*;
  | ---     ^^^^
  | |
  | help: consider restricting its visibility: `pub(crate)`
  |
  = help: or consider exporting it for use by other crates
note: the lint level is defined here
 --> /tmp/breaky/breaky/src/lib.rs:1:8
  |
1 | #[deny(unreachable_pub)]
  |        ^^^^^^^^^^^^^^^

When I uncomment 1. AND 2. above, the lint no longer fires, despite the export being shadowed (though - it is still otherwise reachable).

   Compiling breaky v0.1.0 (/tmp/breaky/breaky)
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s

Meta

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.68.0 (2c8cc3432 2023-03-06)

Context from discussion on reddit, and other wildcard shadowing shenanigans

edit: made it #![deny(unreachable_pub)] not #[deny(unreachable_pub)]

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.L-unreachable_pubLint: unreachable_pubT-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