forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#118928 - EliseZeroTwo:EliseZeroTwo/fix-issue-118786, r=cjgillot fix: Overlapping spans in delimited meta-vars Closes rust-lang#118786 Delimited meta-vars inside of MBE's spans were set to have the same opening and closing position resulting in an ICE when debug assertions were enabled and an error was present in the templated code. This ensures that the spans do not overlap, whilst still having the spans point at the usage of the meta-var inside the macro definition. It includes a regression test. 🖤
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 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,16 @@ | ||
// compile-flags: --crate-type lib -O -C debug-assertions=yes | ||
|
||
// Regression test for issue 118786 | ||
|
||
macro_rules! make_macro { | ||
($macro_name:tt) => { | ||
macro_rules! $macro_name { | ||
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon | ||
//~| ERROR macro expansion ignores token `{` and any following | ||
//~| ERROR cannot find macro `macro_rules` in this scope | ||
() => {} | ||
} | ||
} | ||
} | ||
|
||
make_macro!((meow)); |
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,47 @@ | ||
error: macros that expand to items must be delimited with braces or followed by a semicolon | ||
--> $DIR/issue-118786.rs:7:22 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
| | ||
help: change the delimiters to curly braces | ||
| | ||
LL | macro_rules! {} { | ||
| ~ + | ||
help: add a semicolon | ||
| | ||
LL | macro_rules! $macro_name; { | ||
| + | ||
|
||
error: macro expansion ignores token `{` and any following | ||
--> $DIR/issue-118786.rs:7:34 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- caused by the macro expansion here | ||
| | ||
= note: the usage of `make_macro!` is likely invalid in item context | ||
|
||
error: cannot find macro `macro_rules` in this scope | ||
--> $DIR/issue-118786.rs:7:9 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- in this macro invocation | ||
| | ||
note: maybe you have forgotten to define a name for this `macro_rules!` | ||
--> $DIR/issue-118786.rs:7:9 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- in this macro invocation | ||
= note: this error originates in the macro `make_macro` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 3 previous errors | ||
|