Skip to content

Commit 2d59f53

Browse files
authored
Rollup merge of rust-lang#147813 - JonathanBrouwer:unused_attributes, r=jdonszelmann
Warn on unused_attributes in uitests r? ```@jdonszelmann``` Because: - unused_attributes warnings are usually actual mistakes, rather than just unused code, and we want to notify test writers they may be accidentally making a mistake - Because the lint was allowed by default previously, we missed real bugs, because the test coverage is worse 1. rust-lang#147417 2. rust-lang#147411
2 parents e53b361 + 66b8a9d commit 2d59f53

File tree

52 files changed

+901
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+901
-207
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,8 +1838,9 @@ impl<'test> TestCx<'test> {
18381838

18391839
// Add `-A unused` before `config` flags and in-test (`props`) flags, so that they can
18401840
// overwrite this.
1841+
// Don't allow `unused_attributes` since these are usually actual mistakes, rather than just unused code.
18411842
if let AllowUnused::Yes = allow_unused {
1842-
rustc.args(&["-A", "unused"]);
1843+
rustc.args(&["-A", "unused", "-W", "unused_attributes"]);
18431844
}
18441845

18451846
// Allow tests to use internal features.

tests/ui/attributes/attr-mix-new.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#[rustc_dummy(bar)]
66
mod foo {
77
#![feature(globs)]
8+
//~^ WARN crate-level attribute should be in the root module
89
}
910

1011
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: crate-level attribute should be in the root module
2+
--> $DIR/attr-mix-new.rs:7:3
3+
|
4+
LL | #![feature(globs)]
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: requested on the command line with `-W unused-attributes`
8+
9+
warning: 1 warning emitted
10+

tests/ui/attributes/crate-type-macro-empty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Tests for the issue in #137589
22
#[crate_type = foo!()]
33
//~^ ERROR cannot find macro `foo` in this scope
4+
//~| WARN crate-level attribute should be an inner attribute
45

56
macro_rules! foo {} //~ ERROR macros must contain at least one rule
67

tests/ui/attributes/crate-type-macro-empty.stderr

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: macros must contain at least one rule
2-
--> $DIR/crate-type-macro-empty.rs:5:1
2+
--> $DIR/crate-type-macro-empty.rs:6:1
33
|
44
LL | macro_rules! foo {}
55
| ^^^^^^^^^^^^^^^^^^^
@@ -11,10 +11,22 @@ LL | #[crate_type = foo!()]
1111
| ^^^ consider moving the definition of `foo` before this call
1212
|
1313
note: a macro with the same name exists, but it appears later
14-
--> $DIR/crate-type-macro-empty.rs:5:14
14+
--> $DIR/crate-type-macro-empty.rs:6:14
1515
|
1616
LL | macro_rules! foo {}
1717
| ^^^
1818

19-
error: aborting due to 2 previous errors
19+
warning: crate-level attribute should be an inner attribute
20+
--> $DIR/crate-type-macro-empty.rs:2:1
21+
|
22+
LL | #[crate_type = foo!()]
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: requested on the command line with `-W unused-attributes`
26+
help: add a `!`
27+
|
28+
LL | #![crate_type = foo!()]
29+
| +
30+
31+
error: aborting due to 2 previous errors; 1 warning emitted
2032

tests/ui/attributes/crate-type-macro-not-found.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Tests for the issue in #137589
22
#[crate_type = foo!()] //~ ERROR cannot find macro `foo` in this scope
3+
//~| WARN crate-level attribute should be an inner attribute
34

45
macro_rules! foo {
56
($x:expr) => {"rlib"}

tests/ui/attributes/crate-type-macro-not-found.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@ LL | #[crate_type = foo!()]
55
| ^^^ consider moving the definition of `foo` before this call
66
|
77
note: a macro with the same name exists, but it appears later
8-
--> $DIR/crate-type-macro-not-found.rs:4:14
8+
--> $DIR/crate-type-macro-not-found.rs:5:14
99
|
1010
LL | macro_rules! foo {
1111
| ^^^
1212

13-
error: aborting due to 1 previous error
13+
warning: crate-level attribute should be an inner attribute
14+
--> $DIR/crate-type-macro-not-found.rs:2:1
15+
|
16+
LL | #[crate_type = foo!()]
17+
| ^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= note: requested on the command line with `-W unused-attributes`
20+
help: add a `!`
21+
|
22+
LL | #![crate_type = foo!()]
23+
| +
24+
25+
error: aborting due to 1 previous error; 1 warning emitted
1426

tests/ui/attributes/inline/attr-usage-inline.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ struct S;
99

1010
struct I {
1111
#[inline]
12+
//~^ WARN attribute cannot be used on
13+
//~| WARN previously accepted
1214
i: u8,
1315
}
1416

1517
#[macro_export]
1618
#[inline]
19+
//~^ WARN attribute cannot be used on
20+
//~| WARN previously accepted
1721
macro_rules! m_e {
1822
() => {};
1923
}
2024

2125
#[inline] //~ ERROR: attribute should be applied to function or closure
26+
//~^ WARN attribute cannot be used on
27+
//~| WARN previously accepted
2228
macro_rules! m {
2329
() => {};
2430
}

tests/ui/attributes/inline/attr-usage-inline.stderr

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,39 @@ LL | #[inline]
77
= help: `#[inline]` can only be applied to functions
88

99
error[E0518]: attribute should be applied to function or closure
10-
--> $DIR/attr-usage-inline.rs:21:1
10+
--> $DIR/attr-usage-inline.rs:25:1
1111
|
1212
LL | #[inline]
1313
| ^^^^^^^^^ not a function or closure
1414

15-
error: aborting due to 2 previous errors
15+
warning: `#[inline]` attribute cannot be used on struct fields
16+
--> $DIR/attr-usage-inline.rs:11:5
17+
|
18+
LL | #[inline]
19+
| ^^^^^^^^^
20+
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22+
= help: `#[inline]` can only be applied to functions
23+
= note: requested on the command line with `-W unused-attributes`
24+
25+
warning: `#[inline]` attribute cannot be used on macro defs
26+
--> $DIR/attr-usage-inline.rs:18:1
27+
|
28+
LL | #[inline]
29+
| ^^^^^^^^^
30+
|
31+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
32+
= help: `#[inline]` can only be applied to functions
33+
34+
warning: `#[inline]` attribute cannot be used on macro defs
35+
--> $DIR/attr-usage-inline.rs:25:1
36+
|
37+
LL | #[inline]
38+
| ^^^^^^^^^
39+
|
40+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
41+
= help: `#[inline]` can only be applied to functions
42+
43+
error: aborting due to 2 previous errors; 3 warnings emitted
1644

1745
For more information about this error, try `rustc --explain E0518`.

tests/ui/attributes/link-dl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@ revisions: default_fcw allowed
1010
//@[allowed] check-pass
1111

12-
#[cfg_attr(allowed, allow(ill_formed_attribute_input))]
12+
#![cfg_attr(allowed, allow(ill_formed_attribute_input))]
1313

1414
#[link="dl"]
1515
//[default_fcw]~^ ERROR valid forms for the attribute are

0 commit comments

Comments
 (0)