-
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.
Rollup merge of #105141 - ohno418:fix-ice-on-invalid-var-decl-in-macr…
…o-call, r=compiler-errors Fix ICE on invalid variable declarations in macro calls This fixes ICE that happens with invalid variable declarations in macro calls like: ```rust macro_rules! m { ($s:stmt) => {} } m! { var x } m! { auto x } m! { mut x } ``` Found this is because of not collecting tokens on recovery, so I changed to force collect them. Fixes #103529.
- Loading branch information
Showing
3 changed files
with
76 additions
and
19 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,13 @@ | ||
macro_rules! m { | ||
($s:stmt) => {} | ||
} | ||
|
||
m! { mut x } | ||
//~^ ERROR expected expression, found keyword `mut` | ||
//~| ERROR expected a statement | ||
m! { auto x } | ||
//~^ ERROR invalid variable declaration | ||
m! { var x } | ||
//~^ ERROR invalid variable declaration | ||
|
||
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,39 @@ | ||
error: expected expression, found keyword `mut` | ||
--> $DIR/issue-103529.rs:5:6 | ||
| | ||
LL | m! { mut x } | ||
| ^^^ expected expression | ||
|
||
error: expected a statement | ||
--> $DIR/issue-103529.rs:5:10 | ||
| | ||
LL | ($s:stmt) => {} | ||
| ------- while parsing argument for this `stmt` macro fragment | ||
... | ||
LL | m! { mut x } | ||
| ^ | ||
|
||
error: invalid variable declaration | ||
--> $DIR/issue-103529.rs:8:6 | ||
| | ||
LL | m! { auto x } | ||
| ^^^^ | ||
| | ||
help: write `let` instead of `auto` to introduce a new variable | ||
| | ||
LL | m! { let x } | ||
| ~~~ | ||
|
||
error: invalid variable declaration | ||
--> $DIR/issue-103529.rs:10:6 | ||
| | ||
LL | m! { var x } | ||
| ^^^ | ||
| | ||
help: write `let` instead of `var` to introduce a new variable | ||
| | ||
LL | m! { let x } | ||
| ~~~ | ||
|
||
error: aborting due to 4 previous errors | ||
|