Skip to content

Commit 10dede4

Browse files
Add target checking to #[register_tool]
1 parent 53509ca commit 10dede4

5 files changed

Lines changed: 73 additions & 32 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl CombineAttributeParser for RegisterToolParser {
314314
const PATH: &[Symbol] = &[sym::register_tool];
315315
type Item = Ident;
316316
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
317-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
317+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
318318
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
319319
const STABILITY: AttributeStability = unstable!(register_tool);
320320

tests/ui/attributes/attr-on-mac-call.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ check-pass
22
// Regression test for https://github.com/rust-lang/rust/issues/145779
33
#![warn(unused_attributes)]
4+
#![feature(register_tool)]
45

56
fn main() {
67
#[export_name = "x"]
@@ -100,4 +101,7 @@ fn main() {
100101
//~^ WARN attribute cannot be used on macro calls
101102
//~| WARN previously accepted
102103
unreachable!();
104+
#[register_tool(xyz)]
105+
//~^ WARN crate-level attribute should be an inner attribute
106+
unreachable!();
103107
}

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: `#[export_name]` attribute cannot be used on macro calls
2-
--> $DIR/attr-on-mac-call.rs:6:5
2+
--> $DIR/attr-on-mac-call.rs:7:5
33
|
44
LL | #[export_name = "x"]
55
| ^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL | #![warn(unused_attributes)]
1313
| ^^^^^^^^^^^^^^^^^
1414

1515
warning: `#[naked]` attribute cannot be used on macro calls
16-
--> $DIR/attr-on-mac-call.rs:9:5
16+
--> $DIR/attr-on-mac-call.rs:10:5
1717
|
1818
LL | #[unsafe(naked)]
1919
| ^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | #[unsafe(naked)]
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323

2424
warning: `#[track_caller]` attribute cannot be used on macro calls
25-
--> $DIR/attr-on-mac-call.rs:12:5
25+
--> $DIR/attr-on-mac-call.rs:13:5
2626
|
2727
LL | #[track_caller]
2828
| ^^^^^^^^^^^^^^^
@@ -31,7 +31,7 @@ LL | #[track_caller]
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232

3333
warning: `#[used]` attribute cannot be used on macro calls
34-
--> $DIR/attr-on-mac-call.rs:15:5
34+
--> $DIR/attr-on-mac-call.rs:16:5
3535
|
3636
LL | #[used]
3737
| ^^^^^^^
@@ -40,7 +40,7 @@ LL | #[used]
4040
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4141

4242
warning: `#[target_feature]` attribute cannot be used on macro calls
43-
--> $DIR/attr-on-mac-call.rs:18:5
43+
--> $DIR/attr-on-mac-call.rs:19:5
4444
|
4545
LL | #[target_feature(enable = "x")]
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL | #[target_feature(enable = "x")]
4949
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5050

5151
warning: `#[deprecated]` attribute cannot be used on macro calls
52-
--> $DIR/attr-on-mac-call.rs:21:5
52+
--> $DIR/attr-on-mac-call.rs:22:5
5353
|
5454
LL | #[deprecated]
5555
| ^^^^^^^^^^^^^
@@ -58,7 +58,7 @@ LL | #[deprecated]
5858
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5959

6060
warning: `#[inline]` attribute cannot be used on macro calls
61-
--> $DIR/attr-on-mac-call.rs:24:5
61+
--> $DIR/attr-on-mac-call.rs:25:5
6262
|
6363
LL | #[inline]
6464
| ^^^^^^^^^
@@ -67,7 +67,7 @@ LL | #[inline]
6767
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6868

6969
warning: `#[link_name]` attribute cannot be used on macro calls
70-
--> $DIR/attr-on-mac-call.rs:27:5
70+
--> $DIR/attr-on-mac-call.rs:28:5
7171
|
7272
LL | #[link_name = "x"]
7373
| ^^^^^^^^^^^^^^^^^^
@@ -76,7 +76,7 @@ LL | #[link_name = "x"]
7676
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7777

7878
warning: `#[link_section]` attribute cannot be used on macro calls
79-
--> $DIR/attr-on-mac-call.rs:30:5
79+
--> $DIR/attr-on-mac-call.rs:31:5
8080
|
8181
LL | #[link_section = "__TEXT,__text"]
8282
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL | #[link_section = "__TEXT,__text"]
8585
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8686

8787
warning: `#[link_ordinal]` attribute cannot be used on macro calls
88-
--> $DIR/attr-on-mac-call.rs:33:5
88+
--> $DIR/attr-on-mac-call.rs:34:5
8989
|
9090
LL | #[link_ordinal(42)]
9191
| ^^^^^^^^^^^^^^^^^^^
@@ -94,7 +94,7 @@ LL | #[link_ordinal(42)]
9494
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9595

9696
warning: `#[non_exhaustive]` attribute cannot be used on macro calls
97-
--> $DIR/attr-on-mac-call.rs:36:5
97+
--> $DIR/attr-on-mac-call.rs:37:5
9898
|
9999
LL | #[non_exhaustive]
100100
| ^^^^^^^^^^^^^^^^^
@@ -103,7 +103,7 @@ LL | #[non_exhaustive]
103103
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
104104

105105
warning: `#[proc_macro]` attribute cannot be used on macro calls
106-
--> $DIR/attr-on-mac-call.rs:39:5
106+
--> $DIR/attr-on-mac-call.rs:40:5
107107
|
108108
LL | #[proc_macro]
109109
| ^^^^^^^^^^^^^
@@ -112,7 +112,7 @@ LL | #[proc_macro]
112112
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
113113

114114
warning: `#[cold]` attribute cannot be used on macro calls
115-
--> $DIR/attr-on-mac-call.rs:42:5
115+
--> $DIR/attr-on-mac-call.rs:43:5
116116
|
117117
LL | #[cold]
118118
| ^^^^^^^
@@ -121,7 +121,7 @@ LL | #[cold]
121121
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
122122

123123
warning: `#[no_mangle]` attribute cannot be used on macro calls
124-
--> $DIR/attr-on-mac-call.rs:45:5
124+
--> $DIR/attr-on-mac-call.rs:46:5
125125
|
126126
LL | #[no_mangle]
127127
| ^^^^^^^^^^^^
@@ -130,7 +130,7 @@ LL | #[no_mangle]
130130
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
131131

132132
warning: `#[deprecated]` attribute cannot be used on macro calls
133-
--> $DIR/attr-on-mac-call.rs:48:5
133+
--> $DIR/attr-on-mac-call.rs:49:5
134134
|
135135
LL | #[deprecated]
136136
| ^^^^^^^^^^^^^
@@ -139,7 +139,7 @@ LL | #[deprecated]
139139
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
140140

141141
warning: `#[automatically_derived]` attribute cannot be used on macro calls
142-
--> $DIR/attr-on-mac-call.rs:51:5
142+
--> $DIR/attr-on-mac-call.rs:52:5
143143
|
144144
LL | #[automatically_derived]
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -148,7 +148,7 @@ LL | #[automatically_derived]
148148
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
149149

150150
warning: `#[macro_use]` attribute cannot be used on macro calls
151-
--> $DIR/attr-on-mac-call.rs:54:5
151+
--> $DIR/attr-on-mac-call.rs:55:5
152152
|
153153
LL | #[macro_use]
154154
| ^^^^^^^^^^^^
@@ -157,7 +157,7 @@ LL | #[macro_use]
157157
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
158158

159159
warning: `#[must_use]` attribute cannot be used on macro calls
160-
--> $DIR/attr-on-mac-call.rs:57:5
160+
--> $DIR/attr-on-mac-call.rs:58:5
161161
|
162162
LL | #[must_use]
163163
| ^^^^^^^^^^^
@@ -166,7 +166,7 @@ LL | #[must_use]
166166
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
167167

168168
warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
169-
--> $DIR/attr-on-mac-call.rs:60:5
169+
--> $DIR/attr-on-mac-call.rs:61:5
170170
|
171171
LL | #[no_implicit_prelude]
172172
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -175,7 +175,7 @@ LL | #[no_implicit_prelude]
175175
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
176176

177177
warning: `#[path]` attribute cannot be used on macro calls
178-
--> $DIR/attr-on-mac-call.rs:63:5
178+
--> $DIR/attr-on-mac-call.rs:64:5
179179
|
180180
LL | #[path = ""]
181181
| ^^^^^^^^^^^^
@@ -184,7 +184,7 @@ LL | #[path = ""]
184184
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
185185

186186
warning: `#[ignore]` attribute cannot be used on macro calls
187-
--> $DIR/attr-on-mac-call.rs:66:5
187+
--> $DIR/attr-on-mac-call.rs:67:5
188188
|
189189
LL | #[ignore]
190190
| ^^^^^^^^^
@@ -193,7 +193,7 @@ LL | #[ignore]
193193
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
194194

195195
warning: `#[should_panic]` attribute cannot be used on macro calls
196-
--> $DIR/attr-on-mac-call.rs:69:5
196+
--> $DIR/attr-on-mac-call.rs:70:5
197197
|
198198
LL | #[should_panic]
199199
| ^^^^^^^^^^^^^^^
@@ -202,7 +202,7 @@ LL | #[should_panic]
202202
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
203203

204204
warning: `#[repr()]` attribute cannot be used on macro calls
205-
--> $DIR/attr-on-mac-call.rs:74:5
205+
--> $DIR/attr-on-mac-call.rs:75:5
206206
|
207207
LL | #[repr()]
208208
| ^^^^^^^^^
@@ -211,15 +211,15 @@ LL | #[repr()]
211211
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
212212

213213
warning: unused attribute
214-
--> $DIR/attr-on-mac-call.rs:74:5
214+
--> $DIR/attr-on-mac-call.rs:75:5
215215
|
216216
LL | #[repr()]
217217
| ^^^^^^^^^ help: remove this attribute
218218
|
219219
= note: using `repr` with an empty list has no effect
220220

221221
warning: `#[repr(u8)]` attribute cannot be used on macro calls
222-
--> $DIR/attr-on-mac-call.rs:79:5
222+
--> $DIR/attr-on-mac-call.rs:80:5
223223
|
224224
LL | #[repr(u8)]
225225
| ^^^^^^^^^^^
@@ -228,7 +228,7 @@ LL | #[repr(u8)]
228228
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
229229

230230
warning: `#[repr(align(...))]` attribute cannot be used on macro calls
231-
--> $DIR/attr-on-mac-call.rs:83:5
231+
--> $DIR/attr-on-mac-call.rs:84:5
232232
|
233233
LL | #[repr(align(8))]
234234
| ^^^^^^^^^^^^^^^^^
@@ -237,7 +237,7 @@ LL | #[repr(align(8))]
237237
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
238238

239239
warning: `#[repr(packed)]` attribute cannot be used on macro calls
240-
--> $DIR/attr-on-mac-call.rs:87:5
240+
--> $DIR/attr-on-mac-call.rs:88:5
241241
|
242242
LL | #[repr(packed)]
243243
| ^^^^^^^^^^^^^^^
@@ -246,7 +246,7 @@ LL | #[repr(packed)]
246246
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
247247

248248
warning: `#[repr(C)]` attribute cannot be used on macro calls
249-
--> $DIR/attr-on-mac-call.rs:91:5
249+
--> $DIR/attr-on-mac-call.rs:92:5
250250
|
251251
LL | #[repr(C)]
252252
| ^^^^^^^^^^
@@ -255,7 +255,7 @@ LL | #[repr(C)]
255255
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
256256

257257
warning: `#[repr(Rust)]` attribute cannot be used on macro calls
258-
--> $DIR/attr-on-mac-call.rs:95:5
258+
--> $DIR/attr-on-mac-call.rs:96:5
259259
|
260260
LL | #[repr(Rust)]
261261
| ^^^^^^^^^^^^^
@@ -264,13 +264,25 @@ LL | #[repr(Rust)]
264264
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
265265

266266
warning: `#[repr(simd)]` attribute cannot be used on macro calls
267-
--> $DIR/attr-on-mac-call.rs:99:5
267+
--> $DIR/attr-on-mac-call.rs:100:5
268268
|
269269
LL | #[repr(simd)]
270270
| ^^^^^^^^^^^^^
271271
|
272272
= help: `#[repr(simd)]` can only be applied to structs
273273
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
274274

275-
warning: 30 warnings emitted
275+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
276+
--> $DIR/attr-on-mac-call.rs:104:5
277+
|
278+
LL | #[register_tool(xyz)]
279+
| ^^^^^^^^^^^^^^^^^^^^^
280+
|
281+
note: this attribute does not have an `!`, which means it is applied to this macro call
282+
--> $DIR/attr-on-mac-call.rs:106:5
283+
|
284+
LL | unreachable!();
285+
| ^^^^^^^^^^^^^^
286+
287+
warning: 31 warnings emitted
276288

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ check-pass
2+
#![feature(register_tool)]
3+
4+
#[register_tool(no_valid_target)]
5+
//~^ WARN crate-level attribute should be an inner attribute
6+
fn main() {
7+
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
2+
--> $DIR/register-tool-target.rs:4:1
3+
|
4+
LL | #[register_tool(no_valid_target)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: this attribute does not have an `!`, which means it is applied to this function
8+
--> $DIR/register-tool-target.rs:6:1
9+
|
10+
LL | / fn main() {
11+
LL | |
12+
LL | | }
13+
| |_^
14+
= note: requested on the command line with `-W unused-attributes`
15+
16+
warning: 1 warning emitted
17+

0 commit comments

Comments
 (0)