diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-12-17 21:29:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-17 21:29:59 +0100 |
| commit | 93d3a4231ea3aae4ca38ae6dc0d8650b8293edb0 (patch) | |
| tree | aa54c73812abfd6980cd4075134489caeab49302 /tests | |
| parent | 6269bf1a3a17527347d0f7b890840e2cd1ccfd9f (diff) | |
| parent | 770013d315e9a905e92794876b604568d2fb568e (diff) | |
| download | rust-93d3a4231ea3aae4ca38ae6dc0d8650b8293edb0.tar.gz rust-93d3a4231ea3aae4ca38ae6dc0d8650b8293edb0.zip | |
Rollup merge of #118928 - EliseZeroTwo:EliseZeroTwo/fix-issue-118786, r=cjgillot
fix: Overlapping spans in delimited meta-vars Closes #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. 🖤
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/macros/issue-118786.rs | 16 | ||||
| -rw-r--r-- | tests/ui/macros/issue-118786.stderr | 47 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/ui/macros/issue-118786.rs b/tests/ui/macros/issue-118786.rs new file mode 100644 index 00000000000..84af3a65113 --- /dev/null +++ b/tests/ui/macros/issue-118786.rs @@ -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)); diff --git a/tests/ui/macros/issue-118786.stderr b/tests/ui/macros/issue-118786.stderr new file mode 100644 index 00000000000..ca3a40f31c1 --- /dev/null +++ b/tests/ui/macros/issue-118786.stderr @@ -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 + |
