Files
rust/tests/ui/hygiene/unpretty-debug.stdout
Andrew V. Teylu f5a2bb6263 Add hygiene annotations for tokens in macro_rules! bodies
`-Zunpretty=expanded,hygiene` was not printing syntax context annotations
for identifiers and lifetimes inside `macro_rules!` bodies. These tokens
are printed via `print_tt()` → `token_to_string_ext()`, which converts
tokens to strings without calling `ann_post()`. This meant that
macro-generated `macro_rules!` definitions with hygienic metavar
parameters (e.g. multiple `$marg` distinguished only by hygiene) were
printed with no way to tell them apart.

This was fixed by adding a match on `token.kind` in `print_tt()` to call
`ann_post()` for `Ident`, `NtIdent`, `Lifetime`, and `NtLifetime`
tokens, matching how `print_ident()` and `print_lifetime()` already
handle AST-level identifiers and lifetimes.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
2026-03-02 20:28:16 +00:00

35 lines
805 B
Plaintext

//@ check-pass
//@ compile-flags: -Zunpretty=expanded,hygiene
// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"
// minimal junk
#![feature /* 0#0 */(no_core /* 0#0 */)]
#![no_core /* 0#0 */]
macro_rules! foo
/*
0#0
*/ {
($x /* 0#0 */: ident /* 0#0 */) =>
{ y /* 0#0 */ + $x /* 0#0 */ }
}
fn bar /* 0#0 */() {
let x /* 0#0 */ = 1;
y /* 0#1 */ + x /* 0#0 */
}
fn y /* 0#0 */() {}
/*
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, "foo")
SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiOpaque)
*/