diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 754dc3a06ae7..3d5e487fc4e0 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -50,9 +50,9 @@ declare_clippy_lint! { /// **What it does:** Checks for `extern crate` and `use` items annotated with /// lint attributes. /// - /// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on - /// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a - /// `#[macro_use]` attribute. + /// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and + /// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on + /// `extern crate` items with a `#[macro_use]` attribute. /// /// **Why is this bad?** Lint attributes have no effect on crate imports. Most /// likely a `!` was forgotten. @@ -240,13 +240,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { if let Some(ident) = attr.ident() { match &*ident.as_str() { "allow" | "warn" | "deny" | "forbid" => { - // whitelist `unused_imports` and `deprecated` for `use` items + // whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items // and `unused_imports` for `extern crate` items with `macro_use` for lint in lint_list { match item.node { ItemKind::Use(..) => { if is_word(lint, *sym::unused_imports) || is_word(lint, *sym::deprecated) + || is_word(lint, *sym::unreachable_pub) { return; } diff --git a/clippy_lints/src/utils/sym.rs b/clippy_lints/src/utils/sym.rs index 263d2d42ff4f..c592906a61ad 100644 --- a/clippy_lints/src/utils/sym.rs +++ b/clippy_lints/src/utils/sym.rs @@ -363,6 +363,7 @@ symbols_simple! { uninit, uninitialized, unreachable, + unreachable_pub, unused_extern_crates, unused_imports, unwrap, diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 2ef1ec7dad46..dd84b1b2c1c3 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,6 +1,7 @@ // aux-build:proc_macro_derive.rs #![warn(clippy::useless_attribute)] +#![warn(unreachable_pub)] #[allow(dead_code)] #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] @@ -32,4 +33,16 @@ pub use foo::Bar; #[derive(DeriveSomething)] struct Baz; +// don't lint on unreachable_pub for `use` items +mod a { + mod b { + #[allow(dead_code)] + #[allow(unreachable_pub)] + pub struct C {} + } + + #[allow(unreachable_pub)] + pub use self::b::C; +} + fn main() {} diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index 50ba3d1b0162..bf7ea1698d35 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -1,5 +1,5 @@ error: useless lint attribute - --> $DIR/useless_attribute.rs:5:1 + --> $DIR/useless_attribute.rs:6:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` @@ -7,7 +7,7 @@ LL | #[allow(dead_code)] = note: `-D clippy::useless-attribute` implied by `-D warnings` error: useless lint attribute - --> $DIR/useless_attribute.rs:6:1 + --> $DIR/useless_attribute.rs:7:1 | LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)`