Skip to content

Commit 9a9ccc0

Browse files
committed
mbe: Add parser test for macro attribute recovery
1 parent 1500195 commit 9a9ccc0

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![crate_type = "lib"]
2+
#![feature(macro_attr)]
3+
4+
macro_rules! attr {
5+
attr[$($args:tt)*] { $($body:tt)* } => {
6+
//~^ ERROR: macro attribute argument matchers require parentheses
7+
//~v ERROR: attr:
8+
compile_error!(concat!(
9+
"attr: args=\"",
10+
stringify!($($args)*),
11+
"\" body=\"",
12+
stringify!($($body)*),
13+
"\"",
14+
));
15+
};
16+
}
17+
18+
#[attr]
19+
struct S;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: macro attribute argument matchers require parentheses
2+
--> $DIR/macro-attr-recovery.rs:5:9
3+
|
4+
LL | attr[$($args:tt)*] { $($body:tt)* } => {
5+
| ^^^^^^^^^^^^^^
6+
|
7+
help: the delimiters should be `(` and `)`
8+
|
9+
LL - attr[$($args:tt)*] { $($body:tt)* } => {
10+
LL + attr($($args:tt)*) { $($body:tt)* } => {
11+
|
12+
13+
error: attr: args="" body="struct S;"
14+
--> $DIR/macro-attr-recovery.rs:8:9
15+
|
16+
LL | / compile_error!(concat!(
17+
LL | | "attr: args=\"",
18+
LL | | stringify!($($args)*),
19+
LL | | "\" body=\"",
20+
LL | | stringify!($($body)*),
21+
LL | | "\"",
22+
LL | | ));
23+
| |__________^
24+
...
25+
LL | #[attr]
26+
| ------- in this attribute macro expansion
27+
|
28+
= note: this error originates in the attribute macro `attr` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
30+
error: aborting due to 2 previous errors
31+

0 commit comments

Comments
 (0)