diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-08-08 10:17:43 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-08-08 11:01:12 -0700 |
| commit | 9a9ccc0edbf50428d0f12441cf50f32d5ea0f558 (patch) | |
| tree | 3496f481b9418499f55154a148c51d320efcbd85 | |
| parent | 150019579979ecd6121204f735e525063c184b5d (diff) | |
| download | rust-9a9ccc0edbf50428d0f12441cf50f32d5ea0f558.tar.gz rust-9a9ccc0edbf50428d0f12441cf50f32d5ea0f558.zip | |
mbe: Add parser test for macro attribute recovery
| -rw-r--r-- | tests/ui/parser/macro/macro-attr-recovery.rs | 19 | ||||
| -rw-r--r-- | tests/ui/parser/macro/macro-attr-recovery.stderr | 31 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/parser/macro/macro-attr-recovery.rs b/tests/ui/parser/macro/macro-attr-recovery.rs new file mode 100644 index 00000000000..dbb795f57aa --- /dev/null +++ b/tests/ui/parser/macro/macro-attr-recovery.rs @@ -0,0 +1,19 @@ +#![crate_type = "lib"] +#![feature(macro_attr)] + +macro_rules! attr { + attr[$($args:tt)*] { $($body:tt)* } => { + //~^ ERROR: macro attribute argument matchers require parentheses + //~v ERROR: attr: + compile_error!(concat!( + "attr: args=\"", + stringify!($($args)*), + "\" body=\"", + stringify!($($body)*), + "\"", + )); + }; +} + +#[attr] +struct S; diff --git a/tests/ui/parser/macro/macro-attr-recovery.stderr b/tests/ui/parser/macro/macro-attr-recovery.stderr new file mode 100644 index 00000000000..ab3a0b7c607 --- /dev/null +++ b/tests/ui/parser/macro/macro-attr-recovery.stderr @@ -0,0 +1,31 @@ +error: macro attribute argument matchers require parentheses + --> $DIR/macro-attr-recovery.rs:5:9 + | +LL | attr[$($args:tt)*] { $($body:tt)* } => { + | ^^^^^^^^^^^^^^ + | +help: the delimiters should be `(` and `)` + | +LL - attr[$($args:tt)*] { $($body:tt)* } => { +LL + attr($($args:tt)*) { $($body:tt)* } => { + | + +error: attr: args="" body="struct S;" + --> $DIR/macro-attr-recovery.rs:8:9 + | +LL | / compile_error!(concat!( +LL | | "attr: args=\"", +LL | | stringify!($($args)*), +LL | | "\" body=\"", +LL | | stringify!($($body)*), +LL | | "\"", +LL | | )); + | |__________^ +... +LL | #[attr] + | ------- in this attribute macro expansion + | + = note: this error originates in the attribute macro `attr` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + |
