Skip to content

Commit 5bee968

Browse files
Properly check arguments of #[rustc_abi]
1 parent 29b5a16 commit 5bee968

3 files changed

Lines changed: 52 additions & 14 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
@@ -123,7 +123,7 @@ impl SingleAttributeParser for RustcAbiParser {
123123
let mut fail_incorrect_argument =
124124
|span| cx.adcx().expected_specific_argument(span, &[sym::assert_eq, sym::debug]);
125125

126-
let Some(arg) = arg.meta_item() else {
126+
let Some(arg) = arg.meta_item_no_args() else {
127127
fail_incorrect_argument(args.span);
128128
return None;
129129
};

tests/ui/attributes/args-checked.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
//~^ ERROR malformed
2121
#[coverage(off(x, y, z))]
2222
//~^ ERROR malformed
23+
#[rustc_abi(debug = 5)]
24+
//~^ ERROR malformed
25+
#[rustc_abi(debug(x, y, z))]
26+
//~^ ERROR malformed
2327
fn main() {
2428

2529
}

tests/ui/attributes/args-checked.stderr

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,54 @@ LL - #[coverage(off(x, y, z))]
156156
LL + #[coverage(on)]
157157
|
158158

159+
error[E0539]: malformed `rustc_abi` attribute input
160+
--> $DIR/args-checked.rs:23:1
161+
|
162+
LL | #[rustc_abi(debug = 5)]
163+
| ^^^^^^^^^^^-----------^
164+
| |
165+
| valid arguments are `assert_eq` or `debug`
166+
|
167+
help: try changing it to one of the following valid forms of the attribute
168+
|
169+
LL - #[rustc_abi(debug = 5)]
170+
LL + #[rustc_abi(assert_eq)]
171+
|
172+
LL - #[rustc_abi(debug = 5)]
173+
LL + #[rustc_abi(debug)]
174+
|
175+
176+
error[E0539]: malformed `rustc_abi` attribute input
177+
--> $DIR/args-checked.rs:25:1
178+
|
179+
LL | #[rustc_abi(debug(x, y, z))]
180+
| ^^^^^^^^^^^----------------^
181+
| |
182+
| valid arguments are `assert_eq` or `debug`
183+
|
184+
help: try changing it to one of the following valid forms of the attribute
185+
|
186+
LL - #[rustc_abi(debug(x, y, z))]
187+
LL + #[rustc_abi(assert_eq)]
188+
|
189+
LL - #[rustc_abi(debug(x, y, z))]
190+
LL + #[rustc_abi(debug)]
191+
|
192+
159193
error: `rustc_allow_const_fn_unstable` expects feature names
160-
--> $DIR/args-checked.rs:37:33
194+
--> $DIR/args-checked.rs:41:33
161195
|
162196
LL | #[rustc_allow_const_fn_unstable(x = 5)]
163197
| ^^^^^
164198

165199
error: `rustc_allow_const_fn_unstable` expects feature names
166-
--> $DIR/args-checked.rs:39:33
200+
--> $DIR/args-checked.rs:43:33
167201
|
168202
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
169203
| ^^^^^^^^^^
170204

171205
error[E0539]: malformed `used` attribute input
172-
--> $DIR/args-checked.rs:43:1
206+
--> $DIR/args-checked.rs:47:1
173207
|
174208
LL | #[used(always = 5)]
175209
| ^^^^^^^----------^^
@@ -189,7 +223,7 @@ LL + #[used]
189223
|
190224

191225
error[E0539]: malformed `used` attribute input
192-
--> $DIR/args-checked.rs:45:1
226+
--> $DIR/args-checked.rs:49:1
193227
|
194228
LL | #[used(always(x, y, z))]
195229
| ^^^^^^^---------------^^
@@ -209,7 +243,7 @@ LL + #[used]
209243
|
210244

211245
error[E0565]: malformed `rustc_must_implement_one_of` attribute input
212-
--> $DIR/args-checked.rs:49:1
246+
--> $DIR/args-checked.rs:53:1
213247
|
214248
LL | #[rustc_must_implement_one_of(eq = 5, neq)]
215249
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^
@@ -223,7 +257,7 @@ LL + #[rustc_must_implement_one_of(function1, function2, ...)]
223257
|
224258

225259
error[E0565]: malformed `rustc_must_implement_one_of` attribute input
226-
--> $DIR/args-checked.rs:51:1
260+
--> $DIR/args-checked.rs:55:1
227261
|
228262
LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
229263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^^^^
@@ -237,23 +271,23 @@ LL + #[rustc_must_implement_one_of(function1, function2, ...)]
237271
|
238272

239273
error[E0565]: malformed `rustc_dump_layout` attribute input
240-
--> $DIR/args-checked.rs:57:1
274+
--> $DIR/args-checked.rs:61:1
241275
|
242276
LL | #[rustc_dump_layout(debug = 5)]
243277
| ^^^^^^^^^^^^^^^^^^^^---------^^
244278
| |
245279
| didn't expect a literal here
246280

247281
error[E0565]: malformed `rustc_dump_layout` attribute input
248-
--> $DIR/args-checked.rs:59:1
282+
--> $DIR/args-checked.rs:63:1
249283
|
250284
LL | #[rustc_dump_layout(debug(x, y, z))]
251285
| ^^^^^^^^^^^^^^^^^^^^--------------^^
252286
| |
253287
| didn't expect a literal here
254288

255289
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
256-
--> $DIR/args-checked.rs:27:1
290+
--> $DIR/args-checked.rs:31:1
257291
|
258292
LL | #[macro_export(local_inner_macros = 5)]
259293
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -263,21 +297,21 @@ LL | #[macro_export(local_inner_macros = 5)]
263297
= note: `#[deny(invalid_macro_export_arguments)]` (part of `#[deny(future_incompatible)]`) on by default
264298

265299
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
266-
--> $DIR/args-checked.rs:30:1
300+
--> $DIR/args-checked.rs:34:1
267301
|
268302
LL | #[macro_export(local_inner_macros(x, y, z))]
269303
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270304
|
271305
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
272306
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
273307

274-
error: aborting due to 19 previous errors
308+
error: aborting due to 21 previous errors
275309

276310
Some errors have detailed explanations: E0539, E0565.
277311
For more information about an error, try `rustc --explain E0539`.
278312
Future incompatibility report: Future breakage diagnostic:
279313
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
280-
--> $DIR/args-checked.rs:27:1
314+
--> $DIR/args-checked.rs:31:1
281315
|
282316
LL | #[macro_export(local_inner_macros = 5)]
283317
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -288,7 +322,7 @@ LL | #[macro_export(local_inner_macros = 5)]
288322

289323
Future breakage diagnostic:
290324
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
291-
--> $DIR/args-checked.rs:30:1
325+
--> $DIR/args-checked.rs:34:1
292326
|
293327
LL | #[macro_export(local_inner_macros(x, y, z))]
294328
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)