Skip to content

Commit 6eba665

Browse files
committed
Add regression test for useless_attribute lint
1 parent 9ea17d4 commit 6eba665

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

tests/ui/useless_attribute.fixed

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// run-rustfix
2+
// aux-build:proc_macro_derive.rs
3+
4+
#![warn(clippy::useless_attribute)]
5+
#![warn(unreachable_pub)]
6+
#![feature(rustc_private)]
7+
8+
#![allow(dead_code)]
9+
#![cfg_attr(feature = "cargo-clippy", allow(dead_code))]
10+
#[rustfmt::skip]
11+
#[allow(unused_imports)]
12+
#[allow(unused_extern_crates)]
13+
#[macro_use]
14+
extern crate rustc;
15+
16+
#[macro_use]
17+
extern crate proc_macro_derive;
18+
19+
// don't lint on unused_import for `use` items
20+
#[allow(unused_imports)]
21+
use std::collections;
22+
23+
// don't lint on deprecated for `use` items
24+
mod foo {
25+
#[deprecated]
26+
pub struct Bar;
27+
}
28+
#[allow(deprecated)]
29+
pub use foo::Bar;
30+
31+
// This should not trigger the lint. There's lint level definitions inside the external derive
32+
// that would trigger the useless_attribute lint.
33+
#[derive(DeriveSomething)]
34+
struct Baz;
35+
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+
48+
fn test_indented_attr() {
49+
#![allow(clippy::almost_swapped)]
50+
use std::collections::HashSet;
51+
52+
let _ = HashSet::<u32>::default();
53+
}
54+
55+
fn main() {
56+
test_indented_attr();
57+
}

tests/ui/useless_attribute.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
// aux-build:proc_macro_derive.rs
23

34
#![warn(clippy::useless_attribute)]
@@ -44,4 +45,13 @@ mod a {
4445
pub use self::b::C;
4546
}
4647

47-
fn main() {}
48+
fn test_indented_attr() {
49+
#[allow(clippy::almost_swapped)]
50+
use std::collections::HashSet;
51+
52+
let _ = HashSet::<u32>::default();
53+
}
54+
55+
fn main() {
56+
test_indented_attr();
57+
}

tests/ui/useless_attribute.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
error: useless lint attribute
2-
--> $DIR/useless_attribute.rs:7:1
2+
--> $DIR/useless_attribute.rs:8: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:8:1
10+
--> $DIR/useless_attribute.rs:9: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)`
1414

15-
error: aborting due to 2 previous errors
15+
error: useless lint attribute
16+
--> $DIR/useless_attribute.rs:49:5
17+
|
18+
LL | #[allow(clippy::almost_swapped)]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]`
20+
21+
error: aborting due to 3 previous errors
1622

0 commit comments

Comments
 (0)