From 40fc725298a7e2e5ffda169b5af25c5b739e389f Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 17 May 2019 19:42:43 +0900 Subject: [PATCH] useless_attribute: Add unreachable_pub to whitelists --- clippy_lints/src/attrs.rs | 9 +++++---- tests/ui/useless_attribute.rs | 13 +++++++++++++ tests/ui/useless_attribute.stderr | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 36fc4b94385f9..38731c08084e6 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -49,9 +49,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. @@ -239,13 +239,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/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 2ef1ec7dad468..dd84b1b2c1c38 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 50ba3d1b01625..bf7ea1698d354 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)`