Skip to content

Commit 0417a0a

Browse files
committed
Auto merge of #4107 - taiki-e:useless_attribute, r=flip1995
useless_attribute: Add unreachable_pub to whitelists Fixes #4106 changelog: `useless_attribute`: whitelist `unreachable_pub` on `use` items
2 parents 4071b29 + 40fc725 commit 0417a0a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

clippy_lints/src/attrs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ declare_clippy_lint! {
4949
/// **What it does:** Checks for `extern crate` and `use` items annotated with
5050
/// lint attributes.
5151
///
52-
/// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
53-
/// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
54-
/// `#[macro_use]` attribute.
52+
/// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
53+
/// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
54+
/// `extern crate` items with a `#[macro_use]` attribute.
5555
///
5656
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most
5757
/// likely a `!` was forgotten.
@@ -239,13 +239,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
239239
if let Some(ident) = attr.ident() {
240240
match &*ident.as_str() {
241241
"allow" | "warn" | "deny" | "forbid" => {
242-
// whitelist `unused_imports` and `deprecated` for `use` items
242+
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
243243
// and `unused_imports` for `extern crate` items with `macro_use`
244244
for lint in lint_list {
245245
match item.node {
246246
ItemKind::Use(..) => {
247247
if is_word(lint, sym!(unused_imports))
248248
|| is_word(lint, sym!(deprecated))
249+
|| is_word(lint, sym!(unreachable_pub))
249250
{
250251
return;
251252
}

tests/ui/useless_attribute.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// aux-build:proc_macro_derive.rs
22

33
#![warn(clippy::useless_attribute)]
4+
#![warn(unreachable_pub)]
45

56
#[allow(dead_code)]
67
#[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
@@ -32,4 +33,16 @@ pub use foo::Bar;
3233
#[derive(DeriveSomething)]
3334
struct Baz;
3435

36+
// don't lint on unreachable_pub for `use` items
37+
mod a {
38+
mod b {
39+
#[allow(dead_code)]
40+
#[allow(unreachable_pub)]
41+
pub struct C {}
42+
}
43+
44+
#[allow(unreachable_pub)]
45+
pub use self::b::C;
46+
}
47+
3548
fn main() {}

tests/ui/useless_attribute.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: useless lint attribute
2-
--> $DIR/useless_attribute.rs:5:1
2+
--> $DIR/useless_attribute.rs:6:1
33
|
44
LL | #[allow(dead_code)]
55
| ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]`
66
|
77
= note: `-D clippy::useless-attribute` implied by `-D warnings`
88

99
error: useless lint attribute
10-
--> $DIR/useless_attribute.rs:6:1
10+
--> $DIR/useless_attribute.rs:7:1
1111
|
1212
LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)`

0 commit comments

Comments
 (0)