-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manually cleanup token stream when macro expansion aborts.
- Loading branch information
Showing
3 changed files
with
71 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
macro_rules! values { | ||
($($token:ident($value:literal) $(as $inner:ty)? => $attr:meta,)*) => { | ||
#[derive(Debug)] | ||
pub enum TokenKind { | ||
$( | ||
#[$attr] | ||
$token $($inner)? = $value, | ||
)* | ||
} | ||
}; | ||
} | ||
//~^^^^^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found `(String)` | ||
//~| ERROR macro expansion ignores token `(String)` and any following | ||
|
||
values!(STRING(1) as (String) => cfg(test),); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: expected one of `(`, `,`, `=`, `{`, or `}`, found `(String)` | ||
--> $DIR/syntax-error-recovery.rs:7:26 | ||
| | ||
LL | $token $($inner)? = $value, | ||
| ^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}` | ||
... | ||
LL | values!(STRING(1) as (String) => cfg(test),); | ||
| -------------------------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: macro expansion ignores token `(String)` and any following | ||
--> $DIR/syntax-error-recovery.rs:7:26 | ||
| | ||
LL | $token $($inner)? = $value, | ||
| ^^^^^^ | ||
... | ||
LL | values!(STRING(1) as (String) => cfg(test),); | ||
| -------------------------------------------- caused by the macro expansion here | ||
| | ||
= note: the usage of `values!` is likely invalid in item context | ||
|
||
error: aborting due to 2 previous errors | ||
|