forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#100250 - cjgillot:recover-token-stream, r=A…
…aron1011 Manually cleanup token stream when macro expansion aborts. In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE. In this case, this PR manually cleans up the token stream by closing all currently open delimiters. Fixes rust-lang#96818. Fixes rust-lang#80447. Fixes rust-lang#81920. Fixes rust-lang#91023.
- Loading branch information
Showing
4 changed files
with
84 additions
and
29 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
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,18 @@ | ||
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),); | ||
//~^ ERROR expected one of `!` or `::`, found `<eof>` | ||
|
||
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,30 @@ | ||
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: expected one of `!` or `::`, found `<eof>` | ||
--> $DIR/syntax-error-recovery.rs:15:9 | ||
| | ||
LL | values!(STRING(1) as (String) => cfg(test),); | ||
| ^^^^^^ expected one of `!` or `::` | ||
|
||
error: aborting due to 3 previous errors | ||
|