Skip to content

Commit 3231b2a

Browse files
Properly check arguments of #[test_runner]
1 parent bd6212f commit 3231b2a

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
210210
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
211211
let single = cx.single_element_list(args, cx.attr_span)?;
212212

213-
let Some(meta) = single.meta_item() else {
213+
let Some(meta) = single.meta_item_no_args() else {
214214
cx.adcx().expected_not_literal(single.span());
215215
return None;
216216
};

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))]
@@ -63,4 +69,4 @@ trait T {
6369
//~^ ERROR malformed
6470
enum E {
6571

66-
}
72+
}

tests/ui/attributes/args-checked.stderr

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
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+
| help: must be of the form: `#![test_runner(path)]`
9+
10+
error[E0565]: malformed `test_runner` attribute input
11+
--> $DIR/args-checked.rs:9:1
12+
|
13+
LL | #![test_runner(x(x,y,z))]
14+
| ^^^^^^^^^^^^^^^--------^^
15+
| | |
16+
| | didn't expect a literal here
17+
| help: must be of the form: `#![test_runner(path)]`
18+
119
error[E0539]: malformed `inline` attribute input
2-
--> $DIR/args-checked.rs:6:1
20+
--> $DIR/args-checked.rs:12:1
321
|
422
LL | #[inline(always = 5)]
523
| ^^^^^^^^^----------^^
@@ -20,7 +38,7 @@ LL + #[inline]
2038
|
2139

2240
error[E0539]: malformed `inline` attribute input
23-
--> $DIR/args-checked.rs:8:1
41+
--> $DIR/args-checked.rs:14:1
2442
|
2543
LL | #[inline(always(x, y, z))]
2644
| ^^^^^^^^^---------------^^
@@ -41,7 +59,7 @@ LL + #[inline]
4159
|
4260

4361
error[E0539]: malformed `instruction_set` attribute input
44-
--> $DIR/args-checked.rs:10:1
62+
--> $DIR/args-checked.rs:16:1
4563
|
4664
LL | #[instruction_set(arm::a32 = 5)]
4765
| ^^^^^^^^^^^^^^^^^^------------^^
@@ -52,7 +70,7 @@ LL | #[instruction_set(arm::a32 = 5)]
5270
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>
5371

5472
error[E0539]: malformed `instruction_set` attribute input
55-
--> $DIR/args-checked.rs:12:1
73+
--> $DIR/args-checked.rs:18:1
5674
|
5775
LL | #[instruction_set(arm::a32(x, y, z))]
5876
| ^^^^^^^^^^^^^^^^^^-----------------^^
@@ -63,7 +81,7 @@ LL | #[instruction_set(arm::a32(x, y, z))]
6381
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>
6482

6583
error[E0539]: malformed `optimize` attribute input
66-
--> $DIR/args-checked.rs:14:1
84+
--> $DIR/args-checked.rs:20:1
6785
|
6886
LL | #[optimize(size = 5)]
6987
| ^^^^^^^^^^^--------^^
@@ -83,7 +101,7 @@ LL + #[optimize(speed)]
83101
|
84102

85103
error[E0539]: malformed `optimize` attribute input
86-
--> $DIR/args-checked.rs:16:1
104+
--> $DIR/args-checked.rs:22:1
87105
|
88106
LL | #[optimize(size(x, y, z))]
89107
| ^^^^^^^^^^^-------------^^
@@ -103,7 +121,7 @@ LL + #[optimize(speed)]
103121
|
104122

105123
error[E0539]: malformed `coverage` attribute input
106-
--> $DIR/args-checked.rs:18:1
124+
--> $DIR/args-checked.rs:24:1
107125
|
108126
LL | #[coverage(off = 5)]
109127
| ^^^^^^^^^^^-------^^
@@ -120,7 +138,7 @@ LL + #[coverage(on)]
120138
|
121139

122140
error[E0539]: malformed `coverage` attribute input
123-
--> $DIR/args-checked.rs:20:1
141+
--> $DIR/args-checked.rs:26:1
124142
|
125143
LL | #[coverage(off(x, y, z))]
126144
| ^^^^^^^^^^^------------^^
@@ -137,7 +155,7 @@ LL + #[coverage(on)]
137155
|
138156

139157
error[E0539]: malformed `rustc_abi` attribute input
140-
--> $DIR/args-checked.rs:22:1
158+
--> $DIR/args-checked.rs:28:1
141159
|
142160
LL | #[rustc_abi(debug = 5)]
143161
| ^^^^^^^^^^^-----------^
@@ -154,7 +172,7 @@ LL + #[rustc_abi(debug)]
154172
|
155173

156174
error[E0539]: malformed `rustc_abi` attribute input
157-
--> $DIR/args-checked.rs:24:1
175+
--> $DIR/args-checked.rs:30:1
158176
|
159177
LL | #[rustc_abi(debug(x, y, z))]
160178
| ^^^^^^^^^^^----------------^
@@ -171,19 +189,19 @@ LL + #[rustc_abi(debug)]
171189
|
172190

173191
error: `rustc_allow_const_fn_unstable` expects feature names
174-
--> $DIR/args-checked.rs:40:33
192+
--> $DIR/args-checked.rs:46:33
175193
|
176194
LL | #[rustc_allow_const_fn_unstable(x = 5)]
177195
| ^^^^^
178196

179197
error: `rustc_allow_const_fn_unstable` expects feature names
180-
--> $DIR/args-checked.rs:42:33
198+
--> $DIR/args-checked.rs:48:33
181199
|
182200
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
183201
| ^^^^^^^^^^
184202

185203
error[E0539]: malformed `used` attribute input
186-
--> $DIR/args-checked.rs:46:1
204+
--> $DIR/args-checked.rs:52:1
187205
|
188206
LL | #[used(always = 5)]
189207
| ^^^^^^^----------^^
@@ -203,7 +221,7 @@ LL + #[used]
203221
|
204222

205223
error[E0539]: malformed `used` attribute input
206-
--> $DIR/args-checked.rs:48:1
224+
--> $DIR/args-checked.rs:54:1
207225
|
208226
LL | #[used(always(x, y, z))]
209227
| ^^^^^^^---------------^^
@@ -223,7 +241,7 @@ LL + #[used]
223241
|
224242

225243
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
226-
--> $DIR/args-checked.rs:52:1
244+
--> $DIR/args-checked.rs:58:1
227245
|
228246
LL | #[rustc_must_implement_one_of(eq = 5, neq)]
229247
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^
@@ -232,7 +250,7 @@ LL | #[rustc_must_implement_one_of(eq = 5, neq)]
232250
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
233251

234252
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
235-
--> $DIR/args-checked.rs:54:1
253+
--> $DIR/args-checked.rs:60:1
236254
|
237255
LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
238256
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^^^^
@@ -241,23 +259,23 @@ LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
241259
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
242260

243261
error[E0565]: malformed `rustc_dump_layout` attribute input
244-
--> $DIR/args-checked.rs:60:1
262+
--> $DIR/args-checked.rs:66:1
245263
|
246264
LL | #[rustc_dump_layout(debug = 5)]
247265
| ^^^^^^^^^^^^^^^^^^^^---------^^
248266
| |
249267
| didn't expect a literal here
250268

251269
error[E0565]: malformed `rustc_dump_layout` attribute input
252-
--> $DIR/args-checked.rs:62:1
270+
--> $DIR/args-checked.rs:68:1
253271
|
254272
LL | #[rustc_dump_layout(debug(x, y, z))]
255273
| ^^^^^^^^^^^^^^^^^^^^--------------^^
256274
| |
257275
| didn't expect a literal here
258276

259277
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
260-
--> $DIR/args-checked.rs:30:1
278+
--> $DIR/args-checked.rs:36:1
261279
|
262280
LL | #[macro_export(local_inner_macros = 5)]
263281
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -267,21 +285,21 @@ LL | #[macro_export(local_inner_macros = 5)]
267285
= note: `#[deny(invalid_macro_export_arguments)]` (part of `#[deny(future_incompatible)]`) on by default
268286

269287
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
270-
--> $DIR/args-checked.rs:33:1
288+
--> $DIR/args-checked.rs:39:1
271289
|
272290
LL | #[macro_export(local_inner_macros(x, y, z))]
273291
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
274292
|
275293
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
276294
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
277295

278-
error: aborting due to 20 previous errors
296+
error: aborting due to 22 previous errors
279297

280298
Some errors have detailed explanations: E0539, E0565.
281299
For more information about an error, try `rustc --explain E0539`.
282300
Future incompatibility report: Future breakage diagnostic:
283301
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
284-
--> $DIR/args-checked.rs:30:1
302+
--> $DIR/args-checked.rs:36:1
285303
|
286304
LL | #[macro_export(local_inner_macros = 5)]
287305
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -292,7 +310,7 @@ LL | #[macro_export(local_inner_macros = 5)]
292310

293311
Future breakage diagnostic:
294312
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
295-
--> $DIR/args-checked.rs:33:1
313+
--> $DIR/args-checked.rs:39:1
296314
|
297315
LL | #[macro_export(local_inner_macros(x, y, z))]
298316
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)