Skip to content

Commit 2913754

Browse files
Properly check arguments of #[rustc_dump_layout]
1 parent 8d9a24b commit 2913754

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcDumpLayoutParser {
110110

111111
let mut result = Vec::new();
112112
for item in items.mixed() {
113-
let Some(arg) = item.meta_item() else {
113+
let Some(arg) = item.meta_item_no_args() else {
114114
cx.adcx().expected_not_literal(item.span());
115115
continue;
116116
};

tests/ui/attributes/args-checked.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ static H: u64 = 5;
5151
//~^ ERROR malformed
5252
trait T {
5353

54+
}
55+
56+
#[rustc_dump_layout(debug = 5)]
57+
//~^ ERROR malformed
58+
#[rustc_dump_layout(debug(x, y, z))]
59+
//~^ ERROR malformed
60+
enum E {
61+
5462
}

tests/ui/attributes/args-checked.stderr

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
206206
| | expected a valid identifier here
207207
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
208208

209+
error[E0565]: malformed `rustc_dump_layout` attribute input
210+
--> $DIR/args-checked.rs:56:1
211+
|
212+
LL | #[rustc_dump_layout(debug = 5)]
213+
| ^^^^^^^^^^^^^^^^^^^^---------^^
214+
| |
215+
| didn't expect a literal here
216+
217+
error[E0565]: malformed `rustc_dump_layout` attribute input
218+
--> $DIR/args-checked.rs:58:1
219+
|
220+
LL | #[rustc_dump_layout(debug(x, y, z))]
221+
| ^^^^^^^^^^^^^^^^^^^^--------------^^
222+
| |
223+
| didn't expect a literal here
224+
209225
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
210226
--> $DIR/args-checked.rs:26:1
211227
|
@@ -225,9 +241,10 @@ LL | #[macro_export(local_inner_macros(x, y, z))]
225241
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
226242
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
227243

228-
error: aborting due to 16 previous errors
244+
error: aborting due to 18 previous errors
229245

230-
For more information about this error, try `rustc --explain E0539`.
246+
Some errors have detailed explanations: E0539, E0565.
247+
For more information about an error, try `rustc --explain E0539`.
231248
Future incompatibility report: Future breakage diagnostic:
232249
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
233250
--> $DIR/args-checked.rs:26:1

0 commit comments

Comments
 (0)