Skip to content

Commit 3fcbca4

Browse files
Properly check arguments of #[test_runner]
1 parent 5bee968 commit 3fcbca4

3 files changed

Lines changed: 61 additions & 27 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl SingleAttributeParser for TestRunnerParser {
173173
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
174174
let single = cx.expect_single_element_list(args, cx.attr_span)?;
175175

176-
let Some(meta) = single.meta_item() else {
176+
let Some(meta) = single.meta_item_no_args() else {
177177
cx.adcx().expected_not_literal(single.span());
178178
return None;
179179
};

tests/ui/attributes/args-checked.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#![feature(rustc_attrs)]
22
#![feature(optimize_attribute)]
33
#![feature(coverage_attribute)]
4+
#![feature(custom_test_frameworks)]
45
#![allow(unused_attributes)]
56

7+
#![test_runner(x = 5)]
8+
//~^ ERROR malformed
9+
#![test_runner(x(x,y,z))]
10+
//~^ ERROR malformed
11+
612
#[inline(always = 5)]
713
//~^ ERROR malformed
814
#[inline(always(x, y, z))]
@@ -64,4 +70,4 @@ trait T {
6470
//~^ ERROR malformed
6571
enum E {
6672

67-
}
73+
}

tests/ui/attributes/args-checked.stderr

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
error[E0565]: malformed `test_runner` attribute input
2+
--> $DIR/args-checked.rs:7:1
3+
|
4+
LL | #![test_runner(x = 5)]
5+
| ^^^^^^^^^^^^^^^-----^^
6+
| |
7+
| didn't expect a literal here
8+
|
9+
help: must be of the form
10+
|
11+
LL - #![test_runner(x = 5)]
12+
LL + #![test_runner(path)]
13+
|
14+
15+
error[E0565]: malformed `test_runner` attribute input
16+
--> $DIR/args-checked.rs:9:1
17+
|
18+
LL | #![test_runner(x(x,y,z))]
19+
| ^^^^^^^^^^^^^^^--------^^
20+
| |
21+
| didn't expect a literal here
22+
|
23+
help: must be of the form
24+
|
25+
LL - #![test_runner(x(x,y,z))]
26+
LL + #![test_runner(path)]
27+
|
28+
129
error[E0539]: malformed `inline` attribute input
2-
--> $DIR/args-checked.rs:6:1
30+
--> $DIR/args-checked.rs:12:1
331
|
432
LL | #[inline(always = 5)]
533
| ^^^^^^^^^----------^^
@@ -20,7 +48,7 @@ LL + #[inline]
2048
|
2149

2250
error[E0539]: malformed `inline` attribute input
23-
--> $DIR/args-checked.rs:8:1
51+
--> $DIR/args-checked.rs:14:1
2452
|
2553
LL | #[inline(always(x, y, z))]
2654
| ^^^^^^^^^---------------^^
@@ -41,7 +69,7 @@ LL + #[inline]
4169
|
4270

4371
error[E0539]: malformed `instruction_set` attribute input
44-
--> $DIR/args-checked.rs:10:1
72+
--> $DIR/args-checked.rs:16:1
4573
|
4674
LL | #[instruction_set(arm::a32 = 5)]
4775
| ^^^^^^^^^^^^^^^^^^------------^^
@@ -56,7 +84,7 @@ LL + #[instruction_set(set)]
5684
|
5785

5886
error[E0539]: malformed `instruction_set` attribute input
59-
--> $DIR/args-checked.rs:12:1
87+
--> $DIR/args-checked.rs:18:1
6088
|
6189
LL | #[instruction_set(arm::a32(x, y, z))]
6290
| ^^^^^^^^^^^^^^^^^^-----------------^^
@@ -71,7 +99,7 @@ LL + #[instruction_set(set)]
7199
|
72100

73101
error[E0539]: malformed `optimize` attribute input
74-
--> $DIR/args-checked.rs:14:1
102+
--> $DIR/args-checked.rs:20:1
75103
|
76104
LL | #[optimize(size = 5)]
77105
| ^^^^^^^^^^^--------^^
@@ -91,7 +119,7 @@ LL + #[optimize(speed)]
91119
|
92120

93121
error[E0539]: malformed `optimize` attribute input
94-
--> $DIR/args-checked.rs:16:1
122+
--> $DIR/args-checked.rs:22:1
95123
|
96124
LL | #[optimize(size(x, y, z))]
97125
| ^^^^^^^^^^^-------------^^
@@ -111,19 +139,19 @@ LL + #[optimize(speed)]
111139
|
112140

113141
error: multiple `optimize` attributes
114-
--> $DIR/args-checked.rs:16:1
142+
--> $DIR/args-checked.rs:22:1
115143
|
116144
LL | #[optimize(size(x, y, z))]
117145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
118146
|
119147
note: attribute also specified here
120-
--> $DIR/args-checked.rs:14:1
148+
--> $DIR/args-checked.rs:20:1
121149
|
122150
LL | #[optimize(size = 5)]
123151
| ^^^^^^^^^^^^^^^^^^^^^
124152

125153
error[E0539]: malformed `coverage` attribute input
126-
--> $DIR/args-checked.rs:19:1
154+
--> $DIR/args-checked.rs:25:1
127155
|
128156
LL | #[coverage(off = 5)]
129157
| ^^^^^^^^^^^-------^^
@@ -140,7 +168,7 @@ LL + #[coverage(on)]
140168
|
141169

142170
error[E0539]: malformed `coverage` attribute input
143-
--> $DIR/args-checked.rs:21:1
171+
--> $DIR/args-checked.rs:27:1
144172
|
145173
LL | #[coverage(off(x, y, z))]
146174
| ^^^^^^^^^^^------------^^
@@ -157,7 +185,7 @@ LL + #[coverage(on)]
157185
|
158186

159187
error[E0539]: malformed `rustc_abi` attribute input
160-
--> $DIR/args-checked.rs:23:1
188+
--> $DIR/args-checked.rs:29:1
161189
|
162190
LL | #[rustc_abi(debug = 5)]
163191
| ^^^^^^^^^^^-----------^
@@ -174,7 +202,7 @@ LL + #[rustc_abi(debug)]
174202
|
175203

176204
error[E0539]: malformed `rustc_abi` attribute input
177-
--> $DIR/args-checked.rs:25:1
205+
--> $DIR/args-checked.rs:31:1
178206
|
179207
LL | #[rustc_abi(debug(x, y, z))]
180208
| ^^^^^^^^^^^----------------^
@@ -191,19 +219,19 @@ LL + #[rustc_abi(debug)]
191219
|
192220

193221
error: `rustc_allow_const_fn_unstable` expects feature names
194-
--> $DIR/args-checked.rs:41:33
222+
--> $DIR/args-checked.rs:47:33
195223
|
196224
LL | #[rustc_allow_const_fn_unstable(x = 5)]
197225
| ^^^^^
198226

199227
error: `rustc_allow_const_fn_unstable` expects feature names
200-
--> $DIR/args-checked.rs:43:33
228+
--> $DIR/args-checked.rs:49:33
201229
|
202230
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
203231
| ^^^^^^^^^^
204232

205233
error[E0539]: malformed `used` attribute input
206-
--> $DIR/args-checked.rs:47:1
234+
--> $DIR/args-checked.rs:53:1
207235
|
208236
LL | #[used(always = 5)]
209237
| ^^^^^^^----------^^
@@ -223,7 +251,7 @@ LL + #[used]
223251
|
224252

225253
error[E0539]: malformed `used` attribute input
226-
--> $DIR/args-checked.rs:49:1
254+
--> $DIR/args-checked.rs:55:1
227255
|
228256
LL | #[used(always(x, y, z))]
229257
| ^^^^^^^---------------^^
@@ -243,7 +271,7 @@ LL + #[used]
243271
|
244272

245273
error[E0565]: malformed `rustc_must_implement_one_of` attribute input
246-
--> $DIR/args-checked.rs:53:1
274+
--> $DIR/args-checked.rs:59:1
247275
|
248276
LL | #[rustc_must_implement_one_of(eq = 5, neq)]
249277
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^
@@ -257,7 +285,7 @@ LL + #[rustc_must_implement_one_of(function1, function2, ...)]
257285
|
258286

259287
error[E0565]: malformed `rustc_must_implement_one_of` attribute input
260-
--> $DIR/args-checked.rs:55:1
288+
--> $DIR/args-checked.rs:61:1
261289
|
262290
LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
263291
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^^^^
@@ -271,23 +299,23 @@ LL + #[rustc_must_implement_one_of(function1, function2, ...)]
271299
|
272300

273301
error[E0565]: malformed `rustc_dump_layout` attribute input
274-
--> $DIR/args-checked.rs:61:1
302+
--> $DIR/args-checked.rs:67:1
275303
|
276304
LL | #[rustc_dump_layout(debug = 5)]
277305
| ^^^^^^^^^^^^^^^^^^^^---------^^
278306
| |
279307
| didn't expect a literal here
280308

281309
error[E0565]: malformed `rustc_dump_layout` attribute input
282-
--> $DIR/args-checked.rs:63:1
310+
--> $DIR/args-checked.rs:69:1
283311
|
284312
LL | #[rustc_dump_layout(debug(x, y, z))]
285313
| ^^^^^^^^^^^^^^^^^^^^--------------^^
286314
| |
287315
| didn't expect a literal here
288316

289317
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
290-
--> $DIR/args-checked.rs:31:1
318+
--> $DIR/args-checked.rs:37:1
291319
|
292320
LL | #[macro_export(local_inner_macros = 5)]
293321
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -297,21 +325,21 @@ LL | #[macro_export(local_inner_macros = 5)]
297325
= note: `#[deny(invalid_macro_export_arguments)]` (part of `#[deny(future_incompatible)]`) on by default
298326

299327
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
300-
--> $DIR/args-checked.rs:34:1
328+
--> $DIR/args-checked.rs:40:1
301329
|
302330
LL | #[macro_export(local_inner_macros(x, y, z))]
303331
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
304332
|
305333
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
306334
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
307335

308-
error: aborting due to 21 previous errors
336+
error: aborting due to 23 previous errors
309337

310338
Some errors have detailed explanations: E0539, E0565.
311339
For more information about an error, try `rustc --explain E0539`.
312340
Future incompatibility report: Future breakage diagnostic:
313341
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
314-
--> $DIR/args-checked.rs:31:1
342+
--> $DIR/args-checked.rs:37:1
315343
|
316344
LL | #[macro_export(local_inner_macros = 5)]
317345
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -322,7 +350,7 @@ LL | #[macro_export(local_inner_macros = 5)]
322350

323351
Future breakage diagnostic:
324352
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
325-
--> $DIR/args-checked.rs:34:1
353+
--> $DIR/args-checked.rs:40:1
326354
|
327355
LL | #[macro_export(local_inner_macros(x, y, z))]
328356
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)