Skip to content

Commit 0d2a92f

Browse files
Properly check arguments of #[rustc_abi]
1 parent 56ba158 commit 0d2a92f

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
@@ -157,7 +157,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcAbiParser {
157157
let mut fail_incorrect_argument =
158158
|span| cx.adcx().expected_specific_argument(span, &[sym::assert_eq, sym::debug]);
159159

160-
let Some(arg) = arg.meta_item() else {
160+
let Some(arg) = arg.meta_item_no_args() else {
161161
fail_incorrect_argument(args.span);
162162
return None;
163163
};

tests/ui/attributes/args-checked.rs

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

2428
}

tests/ui/attributes/args-checked.stderr

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

139+
error[E0539]: malformed `rustc_abi` attribute input
140+
--> $DIR/args-checked.rs:22:1
141+
|
142+
LL | #[rustc_abi(debug = 5)]
143+
| ^^^^^^^^^^^-----------^
144+
| |
145+
| valid arguments are `assert_eq` or `debug`
146+
|
147+
help: try changing it to one of the following valid forms of the attribute
148+
|
149+
LL - #[rustc_abi(debug = 5)]
150+
LL + #[rustc_abi(assert_eq)]
151+
|
152+
LL - #[rustc_abi(debug = 5)]
153+
LL + #[rustc_abi(debug)]
154+
|
155+
156+
error[E0539]: malformed `rustc_abi` attribute input
157+
--> $DIR/args-checked.rs:24:1
158+
|
159+
LL | #[rustc_abi(debug(x, y, z))]
160+
| ^^^^^^^^^^^----------------^
161+
| |
162+
| valid arguments are `assert_eq` or `debug`
163+
|
164+
help: try changing it to one of the following valid forms of the attribute
165+
|
166+
LL - #[rustc_abi(debug(x, y, z))]
167+
LL + #[rustc_abi(assert_eq)]
168+
|
169+
LL - #[rustc_abi(debug(x, y, z))]
170+
LL + #[rustc_abi(debug)]
171+
|
172+
139173
error: `rustc_allow_const_fn_unstable` expects feature names
140-
--> $DIR/args-checked.rs:36:33
174+
--> $DIR/args-checked.rs:40:33
141175
|
142176
LL | #[rustc_allow_const_fn_unstable(x = 5)]
143177
| ^^^^^
144178

145179
error: `rustc_allow_const_fn_unstable` expects feature names
146-
--> $DIR/args-checked.rs:38:33
180+
--> $DIR/args-checked.rs:42:33
147181
|
148182
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
149183
| ^^^^^^^^^^
150184

151185
error[E0539]: malformed `used` attribute input
152-
--> $DIR/args-checked.rs:42:1
186+
--> $DIR/args-checked.rs:46:1
153187
|
154188
LL | #[used(always = 5)]
155189
| ^^^^^^^----------^^
@@ -169,7 +203,7 @@ LL + #[used]
169203
|
170204

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

191225
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
192-
--> $DIR/args-checked.rs:48:1
226+
--> $DIR/args-checked.rs:52:1
193227
|
194228
LL | #[rustc_must_implement_one_of(eq = 5, neq)]
195229
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^
@@ -198,7 +232,7 @@ LL | #[rustc_must_implement_one_of(eq = 5, neq)]
198232
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
199233

200234
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
201-
--> $DIR/args-checked.rs:50:1
235+
--> $DIR/args-checked.rs:54:1
202236
|
203237
LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
204238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^^^^
@@ -207,23 +241,23 @@ LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
207241
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
208242

209243
error[E0565]: malformed `rustc_dump_layout` attribute input
210-
--> $DIR/args-checked.rs:56:1
244+
--> $DIR/args-checked.rs:60:1
211245
|
212246
LL | #[rustc_dump_layout(debug = 5)]
213247
| ^^^^^^^^^^^^^^^^^^^^---------^^
214248
| |
215249
| didn't expect a literal here
216250

217251
error[E0565]: malformed `rustc_dump_layout` attribute input
218-
--> $DIR/args-checked.rs:58:1
252+
--> $DIR/args-checked.rs:62:1
219253
|
220254
LL | #[rustc_dump_layout(debug(x, y, z))]
221255
| ^^^^^^^^^^^^^^^^^^^^--------------^^
222256
| |
223257
| didn't expect a literal here
224258

225259
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
226-
--> $DIR/args-checked.rs:26:1
260+
--> $DIR/args-checked.rs:30:1
227261
|
228262
LL | #[macro_export(local_inner_macros = 5)]
229263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -233,21 +267,21 @@ LL | #[macro_export(local_inner_macros = 5)]
233267
= note: `#[deny(invalid_macro_export_arguments)]` (part of `#[deny(future_incompatible)]`) on by default
234268

235269
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
236-
--> $DIR/args-checked.rs:29:1
270+
--> $DIR/args-checked.rs:33:1
237271
|
238272
LL | #[macro_export(local_inner_macros(x, y, z))]
239273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
240274
|
241275
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
242276
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
243277

244-
error: aborting due to 18 previous errors
278+
error: aborting due to 20 previous errors
245279

246280
Some errors have detailed explanations: E0539, E0565.
247281
For more information about an error, try `rustc --explain E0539`.
248282
Future incompatibility report: Future breakage diagnostic:
249283
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
250-
--> $DIR/args-checked.rs:26:1
284+
--> $DIR/args-checked.rs:30:1
251285
|
252286
LL | #[macro_export(local_inner_macros = 5)]
253287
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -258,7 +292,7 @@ LL | #[macro_export(local_inner_macros = 5)]
258292

259293
Future breakage diagnostic:
260294
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
261-
--> $DIR/args-checked.rs:29:1
295+
--> $DIR/args-checked.rs:33:1
262296
|
263297
LL | #[macro_export(local_inner_macros(x, y, z))]
264298
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)