Skip to content

Commit e8f33c2

Browse files
Regression test for attributes on macro calls
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 3851e6c commit e8f33c2

File tree

7 files changed

+302
-42
lines changed

7 files changed

+302
-42
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//@ check-pass
2+
// Regression test for https://github.com/rust-lang/rust/issues/145779
3+
#![warn(unused_attributes)]
4+
5+
fn main() {
6+
#[export_name = "x"]
7+
//~^ WARN attribute cannot be used on macro calls
8+
//~| WARN previously accepted
9+
#[unsafe(naked)]
10+
//~^ WARN attribute cannot be used on macro calls
11+
//~| WARN previously accepted
12+
#[track_caller]
13+
//~^ WARN attribute cannot be used on macro calls
14+
//~| WARN previously accepted
15+
#[used]
16+
//~^ WARN attribute cannot be used on macro calls
17+
//~| WARN previously accepted
18+
#[target_feature(enable = "x")]
19+
//~^ WARN attribute cannot be used on macro calls
20+
//~| WARN previously accepted
21+
#[deprecated]
22+
//~^ WARN attribute cannot be used on macro calls
23+
//~| WARN previously accepted
24+
#[inline]
25+
//~^ WARN attribute cannot be used on macro calls
26+
//~| WARN previously accepted
27+
#[link_name = "x"]
28+
//~^ WARN attribute cannot be used on macro calls
29+
//~| WARN previously accepted
30+
#[link_section = "x"]
31+
//~^ WARN attribute cannot be used on macro calls
32+
//~| WARN previously accepted
33+
#[link_ordinal(42)]
34+
//~^ WARN attribute cannot be used on macro calls
35+
//~| WARN previously accepted
36+
#[non_exhaustive]
37+
//~^ WARN attribute cannot be used on macro calls
38+
//~| WARN previously accepted
39+
#[proc_macro]
40+
//~^ WARN attribute cannot be used on macro calls
41+
//~| WARN previously accepted
42+
#[cold]
43+
//~^ WARN attribute cannot be used on macro calls
44+
//~| WARN previously accepted
45+
#[no_mangle]
46+
//~^ WARN attribute cannot be used on macro calls
47+
//~| WARN previously accepted
48+
#[deprecated]
49+
//~^ WARN attribute cannot be used on macro calls
50+
//~| WARN previously accepted
51+
#[automatically_derived]
52+
//~^ WARN attribute cannot be used on macro calls
53+
//~| WARN previously accepted
54+
#[macro_use]
55+
//~^ WARN attribute cannot be used on macro calls
56+
//~| WARN previously accepted
57+
#[must_use]
58+
//~^ WARN attribute cannot be used on macro calls
59+
//~| WARN previously accepted
60+
#[no_implicit_prelude]
61+
//~^ WARN attribute cannot be used on macro calls
62+
//~| WARN previously accepted
63+
#[path = ""]
64+
//~^ WARN attribute cannot be used on macro calls
65+
//~| WARN previously accepted
66+
#[ignore]
67+
//~^ WARN attribute cannot be used on macro calls
68+
//~| WARN previously accepted
69+
#[should_panic]
70+
//~^ WARN attribute cannot be used on macro calls
71+
//~| WARN previously accepted
72+
unreachable!();
73+
}
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
warning: `#[export_name]` attribute cannot be used on macro calls
2+
--> $DIR/attr-on-mac-call.rs:6:5
3+
|
4+
LL | #[export_name = "x"]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= help: `#[export_name]` can be applied to functions and statics
9+
note: the lint level is defined here
10+
--> $DIR/attr-on-mac-call.rs:3:9
11+
|
12+
LL | #![warn(unused_attributes)]
13+
| ^^^^^^^^^^^^^^^^^
14+
15+
warning: `#[naked]` attribute cannot be used on macro calls
16+
--> $DIR/attr-on-mac-call.rs:9:5
17+
|
18+
LL | #[unsafe(naked)]
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: `#[naked]` can only be applied to functions
23+
24+
warning: `#[track_caller]` attribute cannot be used on macro calls
25+
--> $DIR/attr-on-mac-call.rs:12:5
26+
|
27+
LL | #[track_caller]
28+
| ^^^^^^^^^^^^^^^
29+
|
30+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
= help: `#[track_caller]` can only be applied to functions
32+
33+
warning: `#[used]` attribute cannot be used on macro calls
34+
--> $DIR/attr-on-mac-call.rs:15:5
35+
|
36+
LL | #[used]
37+
| ^^^^^^^
38+
|
39+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
40+
= help: `#[used]` can only be applied to statics
41+
42+
warning: `#[target_feature]` attribute cannot be used on macro calls
43+
--> $DIR/attr-on-mac-call.rs:18:5
44+
|
45+
LL | #[target_feature(enable = "x")]
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49+
= help: `#[target_feature]` can only be applied to functions
50+
51+
warning: `#[deprecated]` attribute cannot be used on macro calls
52+
--> $DIR/attr-on-mac-call.rs:21:5
53+
|
54+
LL | #[deprecated]
55+
| ^^^^^^^^^^^^^
56+
|
57+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
58+
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
59+
60+
warning: `#[inline]` attribute cannot be used on macro calls
61+
--> $DIR/attr-on-mac-call.rs:24:5
62+
|
63+
LL | #[inline]
64+
| ^^^^^^^^^
65+
|
66+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
67+
= help: `#[inline]` can only be applied to functions
68+
69+
warning: `#[link_name]` attribute cannot be used on macro calls
70+
--> $DIR/attr-on-mac-call.rs:27:5
71+
|
72+
LL | #[link_name = "x"]
73+
| ^^^^^^^^^^^^^^^^^^
74+
|
75+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
76+
= help: `#[link_name]` can be applied to foreign functions and foreign statics
77+
78+
warning: `#[link_section]` attribute cannot be used on macro calls
79+
--> $DIR/attr-on-mac-call.rs:30:5
80+
|
81+
LL | #[link_section = "x"]
82+
| ^^^^^^^^^^^^^^^^^^^^^
83+
|
84+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
85+
= help: `#[link_section]` can be applied to statics and functions
86+
87+
warning: `#[link_ordinal]` attribute cannot be used on macro calls
88+
--> $DIR/attr-on-mac-call.rs:33:5
89+
|
90+
LL | #[link_ordinal(42)]
91+
| ^^^^^^^^^^^^^^^^^^^
92+
|
93+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
94+
= help: `#[link_ordinal]` can be applied to foreign functions and foreign statics
95+
96+
warning: `#[non_exhaustive]` attribute cannot be used on macro calls
97+
--> $DIR/attr-on-mac-call.rs:36:5
98+
|
99+
LL | #[non_exhaustive]
100+
| ^^^^^^^^^^^^^^^^^
101+
|
102+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
103+
= help: `#[non_exhaustive]` can be applied to data types and enum variants
104+
105+
warning: `#[proc_macro]` attribute cannot be used on macro calls
106+
--> $DIR/attr-on-mac-call.rs:39:5
107+
|
108+
LL | #[proc_macro]
109+
| ^^^^^^^^^^^^^
110+
|
111+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
112+
= help: `#[proc_macro]` can only be applied to functions
113+
114+
warning: `#[cold]` attribute cannot be used on macro calls
115+
--> $DIR/attr-on-mac-call.rs:42:5
116+
|
117+
LL | #[cold]
118+
| ^^^^^^^
119+
|
120+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
121+
= help: `#[cold]` can only be applied to functions
122+
123+
warning: `#[no_mangle]` attribute cannot be used on macro calls
124+
--> $DIR/attr-on-mac-call.rs:45:5
125+
|
126+
LL | #[no_mangle]
127+
| ^^^^^^^^^^^^
128+
|
129+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
130+
= help: `#[no_mangle]` can be applied to functions and statics
131+
132+
warning: `#[deprecated]` attribute cannot be used on macro calls
133+
--> $DIR/attr-on-mac-call.rs:48:5
134+
|
135+
LL | #[deprecated]
136+
| ^^^^^^^^^^^^^
137+
|
138+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
139+
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
140+
141+
warning: `#[automatically_derived]` attribute cannot be used on macro calls
142+
--> $DIR/attr-on-mac-call.rs:51:5
143+
|
144+
LL | #[automatically_derived]
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^
146+
|
147+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
148+
= help: `#[automatically_derived]` can only be applied to trait impl blocks
149+
150+
warning: `#[macro_use]` attribute cannot be used on macro calls
151+
--> $DIR/attr-on-mac-call.rs:54:5
152+
|
153+
LL | #[macro_use]
154+
| ^^^^^^^^^^^^
155+
|
156+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
157+
= help: `#[macro_use]` can be applied to modules, extern crates, and crates
158+
159+
warning: `#[must_use]` attribute cannot be used on macro calls
160+
--> $DIR/attr-on-mac-call.rs:57:5
161+
|
162+
LL | #[must_use]
163+
| ^^^^^^^^^^^
164+
|
165+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
166+
= help: `#[must_use]` can be applied to functions, data types, unions, and traits
167+
168+
warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
169+
--> $DIR/attr-on-mac-call.rs:60:5
170+
|
171+
LL | #[no_implicit_prelude]
172+
| ^^^^^^^^^^^^^^^^^^^^^^
173+
|
174+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175+
= help: `#[no_implicit_prelude]` can be applied to modules and crates
176+
177+
warning: `#[path]` attribute cannot be used on macro calls
178+
--> $DIR/attr-on-mac-call.rs:63:5
179+
|
180+
LL | #[path = ""]
181+
| ^^^^^^^^^^^^
182+
|
183+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
184+
= help: `#[path]` can only be applied to modules
185+
186+
warning: `#[ignore]` attribute cannot be used on macro calls
187+
--> $DIR/attr-on-mac-call.rs:66:5
188+
|
189+
LL | #[ignore]
190+
| ^^^^^^^^^
191+
|
192+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
193+
= help: `#[ignore]` can only be applied to functions
194+
195+
warning: `#[should_panic]` attribute cannot be used on macro calls
196+
--> $DIR/attr-on-mac-call.rs:69:5
197+
|
198+
LL | #[should_panic]
199+
| ^^^^^^^^^^^^^^^
200+
|
201+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
202+
= help: `#[should_panic]` can only be applied to functions
203+
204+
warning: 22 warnings emitted
205+

tests/ui/lint/inert-attr-macro.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
//@ check-pass
22

3-
#![feature(rustc_attrs)]
43
#![warn(unused)]
54

65
macro_rules! foo {
76
() => {}
87
}
98

109
fn main() {
11-
#[rustc_dummy] foo!(); //~ WARN unused attribute `rustc_dummy`
10+
#[inline] foo!(); //~ WARN `#[inline]` attribute cannot be used on macro calls
11+
//~^ WARN previously accepted
1212

1313
// This does nothing, since `#[allow(warnings)]` is itself
1414
// an inert attribute on a macro call
15-
#[allow(warnings)] #[rustc_dummy] foo!(); //~ WARN unused attribute `allow`
16-
//~^ WARN unused attribute `rustc_dummy`
15+
#[allow(warnings)] #[inline] foo!(); //~ WARN unused attribute `allow`
16+
//~^ WARN `#[inline]` attribute cannot be used on macro calls
17+
//~| WARN previously accepted
1718

1819
// This does work, since the attribute is on a parent
1920
// of the macro invocation.
20-
#[allow(warnings)] { #[rustc_dummy] foo!(); }
21+
#[allow(warnings)] { #[inline] foo!(); }
2122

2223
// Ok, `cfg` and `cfg_attr` are expanded eagerly and do not warn.
2324
#[cfg(true)] foo!();

tests/ui/lint/inert-attr-macro.stderr

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
warning: unused attribute `rustc_dummy`
2-
--> $DIR/inert-attr-macro.rs:11:5
1+
warning: `#[inline]` attribute cannot be used on macro calls
2+
--> $DIR/inert-attr-macro.rs:10:5
33
|
4-
LL | #[rustc_dummy] foo!();
5-
| ^^^^^^^^^^^^^^
4+
LL | #[inline] foo!();
5+
| ^^^^^^^^^
66
|
7-
note: the built-in attribute `rustc_dummy` will be ignored, since it's applied to the macro invocation `foo`
8-
--> $DIR/inert-attr-macro.rs:11:20
9-
|
10-
LL | #[rustc_dummy] foo!();
11-
| ^^^
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= help: `#[inline]` can only be applied to functions
129
note: the lint level is defined here
13-
--> $DIR/inert-attr-macro.rs:4:9
10+
--> $DIR/inert-attr-macro.rs:3:9
1411
|
1512
LL | #![warn(unused)]
1613
| ^^^^^^
@@ -19,26 +16,23 @@ LL | #![warn(unused)]
1916
warning: unused attribute `allow`
2017
--> $DIR/inert-attr-macro.rs:15:5
2118
|
22-
LL | #[allow(warnings)] #[rustc_dummy] foo!();
19+
LL | #[allow(warnings)] #[inline] foo!();
2320
| ^^^^^^^^^^^^^^^^^^
2421
|
2522
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
26-
--> $DIR/inert-attr-macro.rs:15:39
23+
--> $DIR/inert-attr-macro.rs:15:34
2724
|
28-
LL | #[allow(warnings)] #[rustc_dummy] foo!();
29-
| ^^^
25+
LL | #[allow(warnings)] #[inline] foo!();
26+
| ^^^
3027

31-
warning: unused attribute `rustc_dummy`
28+
warning: `#[inline]` attribute cannot be used on macro calls
3229
--> $DIR/inert-attr-macro.rs:15:24
3330
|
34-
LL | #[allow(warnings)] #[rustc_dummy] foo!();
35-
| ^^^^^^^^^^^^^^
36-
|
37-
note: the built-in attribute `rustc_dummy` will be ignored, since it's applied to the macro invocation `foo`
38-
--> $DIR/inert-attr-macro.rs:15:39
31+
LL | #[allow(warnings)] #[inline] foo!();
32+
| ^^^^^^^^^
3933
|
40-
LL | #[allow(warnings)] #[rustc_dummy] foo!();
41-
| ^^^
34+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
35+
= help: `#[inline]` can only be applied to functions
4236

4337
warning: 3 warnings emitted
4438

tests/ui/lint/unused/unused_attributes-must_use.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ extern "Rust" {
6565
fn foreign_foo() -> i64;
6666
}
6767

68-
//~ ERROR unused attribute
6968
//~^ ERROR `#[must_use]` attribute cannot be used on macro calls
7069
//~| WARN this was previously accepted by the compiler but is being phased out
7170
global_asm!("");

tests/ui/lint/unused/unused_attributes-must_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern "Rust" {
6565
fn foreign_foo() -> i64;
6666
}
6767

68-
#[must_use] //~ ERROR unused attribute
68+
#[must_use]
6969
//~^ ERROR `#[must_use]` attribute cannot be used on macro calls
7070
//~| WARN this was previously accepted by the compiler but is being phased out
7171
global_asm!("");

0 commit comments

Comments
 (0)