rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.02k stars 1.48k forks source link

needless_pub_self lint when necessary for crate macros #12808

Open jgh713 opened 1 month ago

jgh713 commented 1 month ago

Summary

Simple false positive. needless_pub_self lint is giving warnings when pub(self) is actually necessary to import macros anywhere below crate level. Removing the pub(self) causes compilation error on unresolved import.

Lint Name

needless_pub_self

Reproducer

I tried this code:

// In mod.rs:
macro_rules! vis_methods {
}

pub(self) use vis_methods;

// In submodule:
use super::{vis_methods, other_imports};

I saw this happen:

unnecessary `pub(self)`
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pub_self
`#[warn(clippy::needless_pub_self)]` on by default

I expected to see this happen:

Lint shouldn't trigger.

Version

rustc 1.79.0-nightly (7f2fc33da 2024-04-22)
binary: rustc
commit-hash: 7f2fc33da6633f5a764ddc263c769b6b2873d167
commit-date: 2024-04-22
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.4

Additional Labels

@rustbot label +l-suggestion-causes-error

jgh713 commented 1 month ago

Additionally it seems like there's something else screwy with this lint. Attempting to ignore it with:

#[allow(clippy::needless_pub_self)]
pub(self) use vis_methods;

causes a compile error with the following text:

useless lint attribute
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute
`#[deny(clippy::useless_attribute)]` on by default

You have to go all the way and use both:

#[allow(clippy::useless_attribute)]
#[allow(clippy::needless_pub_self)]
pub(self) use vis_methods;