Skip to content

Commit 85caaf5

Browse files
committed
Fix useless_attribute to also whitelist unused_extern_crates.
1 parent 9219fc6 commit 85caaf5

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

clippy_lints/src/attrs.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
180180
|| is_word(lint, "deprecated") {
181181
return
182182
},
183-
ItemKind::ExternCrate(..) => if is_word(lint, "unused_imports")
184-
&& skip_unused_imports {
183+
ItemKind::ExternCrate(..) => {
184+
if is_word(lint, "unused_imports")
185+
&& skip_unused_imports {
186+
return
187+
}
188+
if is_word(lint, "unused_extern_crates") {
185189
return
186-
},
190+
}
191+
}
187192
_ => {},
188193
}
189194
}

tests/ui/useless_attribute.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
#![warn(clippy::useless_attribute)]
44

5-
#[allow(dead_code, unused_extern_crates)]
6-
#[cfg_attr(feature = "cargo-clippy", allow(dead_code, unused_extern_crates))]
5+
#[allow(dead_code)]
6+
#[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
77
#[cfg_attr(feature = "cargo-clippy",
8-
allow(dead_code, unused_extern_crates))]
8+
allow(dead_code))]
99
#[allow(unused_imports)]
10+
#[allow(unused_extern_crates)]
1011
#[macro_use]
1112
extern crate clippy_lints;
1213

tests/ui/useless_attribute.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error: useless lint attribute
22
--> $DIR/useless_attribute.rs:5:1
33
|
4-
5 | #[allow(dead_code, unused_extern_crates)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code, unused_extern_crates)]`
4+
5 | #[allow(dead_code)]
5+
| ^^^^^^^^^^^^^^^^^^^ 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
1010
--> $DIR/useless_attribute.rs:6:1
1111
|
12-
6 | #[cfg_attr(feature = "cargo-clippy", allow(dead_code, unused_extern_crates))]
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code, unused_extern_crates))`
12+
6 | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code))`
1414

1515
error: aborting due to 2 previous errors
1616

0 commit comments

Comments
 (0)