Add regression tests for token hygiene annotations in macro bodies

Add `unpretty-debug-shadow` test covering macro body tokens that
reference a shadowed variable, and simplify the `unpretty-debug-metavars`
test macro.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
This commit is contained in:
Andrew V. Teylu
2026-03-03 13:06:55 +00:00
parent f5a2bb6263
commit bf6db4f345
4 changed files with 58 additions and 6 deletions
+4 -3
View File
@@ -1,9 +1,10 @@
//@ check-pass
//@ compile-flags: -Zunpretty=expanded,hygiene
// Regression test: metavar parameters in macro-generated macro_rules!
// definitions should have hygiene annotations so that textually identical
// `$marg` bindings are distinguishable by their syntax contexts.
// Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene
// Previously, metavar parameters in macro-generated macro_rules! definitions
// were missing hygiene annotations, making identical `$marg` bindings
// indistinguishable.
// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"
@@ -1,9 +1,10 @@
//@ check-pass
//@ compile-flags: -Zunpretty=expanded,hygiene
// Regression test: metavar parameters in macro-generated macro_rules!
// definitions should have hygiene annotations so that textually identical
// `$marg` bindings are distinguishable by their syntax contexts.
// Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene
// Previously, metavar parameters in macro-generated macro_rules! definitions
// were missing hygiene annotations, making identical `$marg` bindings
// indistinguishable.
// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"
+20
View File
@@ -0,0 +1,20 @@
//@ check-pass
//@ compile-flags: -Zunpretty=expanded,hygiene
// Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene
// Previously, tokens in macro_rules! bodies were missing hygiene annotations,
// making it impossible to see how a macro's reference to a shadowed variable
// is distinguished from the shadowing binding.
// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"
#![feature(no_core)]
#![no_core]
fn f() {
let x = 0;
macro_rules! use_x { () => { x }; }
let x = 1;
use_x!();
}
@@ -0,0 +1,30 @@
//@ check-pass
//@ compile-flags: -Zunpretty=expanded,hygiene
// Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene
// Previously, tokens in macro_rules! bodies were missing hygiene annotations,
// making it impossible to see how a macro's reference to a shadowed variable
// is distinguished from the shadowing binding.
// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"
#![feature /* 0#0 */(no_core /* 0#0 */)]
#![no_core /* 0#0 */]
fn f /* 0#0 */() {
let x /* 0#0 */ = 0;
macro_rules! use_x /* 0#0 */ { () => { x /* 0#0 */ }; }
let x /* 0#0 */ = 1;
x /* 0#1 */;
}
/*
Expansions:
crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "use_x")
SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiOpaque)
*/