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

needless_pub_self lint when necessary for crate macros #12808

Open
jgh713 opened this issue May 16, 2024 · 1 comment
Open

needless_pub_self lint when necessary for crate macros #12808

jgh713 opened this issue May 16, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@jgh713
Copy link

jgh713 commented May 16, 2024

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 jgh713 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 16, 2024
@jgh713
Copy link
Author

jgh713 commented May 16, 2024

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant