mbe: Add parser test for macro attribute recovery

This commit is contained in:
Josh Triplett 2025-08-08 10:17:43 -07:00
parent 1500195799
commit 9a9ccc0edb
2 changed files with 50 additions and 0 deletions

View file

@ -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;

View file

@ -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