rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.32k stars 12.72k forks source link

unreachable_pub lint false positive #101169

Open laralove143 opened 2 years ago

laralove143 commented 2 years ago

I tried this code:

#![warn(unreachable_pub)]

mod foo {
    pub struct Foo;
}

use foo::Foo;

Here's a link for the same code on playground

I expected to see this happen: No warning, as the item is actually accessible from the root crate

Instead, this happened: It says the item is unreachable, even though it isn't

PatchMixolydic commented 2 years ago

unreachable_pub trips when a pub item would be unreachable from a different crate using the current crate as a dependency, even if it can be reached in the current crate. The solution here is to either mark Foo as pub(crate) or allow unreachable_pub (which is nice for binaries where the distinction between pub and pub(crate) doesn't matter as much).

laralove143 commented 2 years ago

This is for a library but nothing in this module should be public, I prefer this way and if I do pub(crate) clippy complains with https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate so these lints are conflicting? Which one should I listen

PatchMixolydic commented 2 years ago

It seems like that's is a known bug in clippy::redundant_pub_crate, which caused the lint to be moved to the clippy::nursery category.