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

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

Open
jamesmunns opened this issue May 8, 2023 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name resolution A-visibility Area: Visibility / privacy C-bug Category: This is a bug. L-unreachable_pub Lint: unreachable_pub T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jamesmunns
Copy link
Member

jamesmunns commented May 8, 2023

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

@jamesmunns jamesmunns added the C-bug Category: This is a bug. label May 8, 2023
@jamesmunns
Copy link
Member Author

jamesmunns commented May 8, 2023

Edit: This additional claim was not true because of a typo. Above points are still correct.

@jamesmunns
Copy link
Member Author

Potentially related to #111336 - someone mentioned unreachable_pub as a workaround for introducing a new lint for glob shadowing, but this issue reports shortcomings of unreachable_pub when there is only partial shadowing instead of complete shadowing.

@obi1kenobi
Copy link
Member

I believe unreachable_pub shouldn't affect #111336 in the general case because the shadowed type may be reachable in another way (but still not namable because of shadowing) — for example as the return value of a reachable, namable pub fn.

But it would be good to make sure there are test cases for this, since it's an interesting edge case.

@jyn514 jyn514 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-visibility Area: Visibility / privacy A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 10, 2023
@jieyouxu jieyouxu added the L-unreachable_pub Lint: unreachable_pub label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name resolution A-visibility Area: Visibility / privacy C-bug Category: This is a bug. L-unreachable_pub Lint: unreachable_pub T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants