Skip to content

Fix missing syntax context in lifetime hygiene debug output - #151817

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aytey:fix_lifetime_unpretty_hygiene
Jan 30, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aytey:fix_lifetime_unpretty_hygiene

Conversation

@aytey

@aytey aytey commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

-Zunpretty=expanded,hygiene was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes 'a with different hygiene would both print as /* 2538 */ instead of /* 2538#0 */ and /* 2538#1 */, making it impossible to distinguish them.

This was fixed by changing print_lifetime to call ann_post() with the full Ident, matching how regular identifiers are handled in print_ident.

Closes: #151797

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 29, 2026
@rustbot

rustbot commented Jan 29, 2026

Copy link
Copy Markdown
Collaborator

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

`-Zunpretty=expanded,hygiene` was not printing the syntax context for
lifetimes. For example, two macro-generated lifetimes `'a` with different
hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and
`/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with
the full `Ident`, matching how regular identifiers are handled in
`print_ident`.
@aytey
aytey force-pushed the fix_lifetime_unpretty_hygiene branch from 6bc4b5f to a333f6f Compare January 29, 2026 12:07
@jdonszelmann

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a333f6f has been approved by jdonszelmann

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 29, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 29, 2026
…e, r=jdonszelmann

Fix missing syntax context in lifetime hygiene debug output

`-Zunpretty=expanded,hygiene` was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes `'a` with different hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and `/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with the full `Ident`, matching how regular identifiers are handled in `print_ident`.

Closes: rust-lang#151797
rust-bors Bot pushed a commit that referenced this pull request Jan 29, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - #151811 (Fix false positive in unused_parens caused by break)
 - #151817 (Fix missing syntax context in lifetime hygiene debug output)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 29, 2026
…e, r=jdonszelmann

Fix missing syntax context in lifetime hygiene debug output

`-Zunpretty=expanded,hygiene` was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes `'a` with different hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and `/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with the full `Ident`, matching how regular identifiers are handled in `print_ident`.

Closes: rust-lang#151797
rust-bors Bot pushed a commit that referenced this pull request Jan 29, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - #151811 (Fix false positive in unused_parens caused by break)
 - #151817 (Fix missing syntax context in lifetime hygiene debug output)
 - #151836 (Fix flakyness issue with `tests/rustdoc-gui/globals.goml` test)
rust-bors Bot pushed a commit that referenced this pull request Jan 30, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - #151811 (Fix false positive in unused_parens caused by break)
 - #151817 (Fix missing syntax context in lifetime hygiene debug output)
 - #151836 (Fix flakyness issue with `tests/rustdoc-gui/globals.goml` test)
Zalathar added a commit to Zalathar/rust that referenced this pull request Jan 30, 2026
…e, r=jdonszelmann

Fix missing syntax context in lifetime hygiene debug output

`-Zunpretty=expanded,hygiene` was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes `'a` with different hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and `/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with the full `Ident`, matching how regular identifiers are handled in `print_ident`.

Closes: rust-lang#151797
rust-bors Bot pushed a commit that referenced this pull request Jan 30, 2026
Rollup of 6 pull requests

Successful merges:

 - #151777 (    Reduce generics use in the query system.)
 - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - #151811 (Fix false positive in unused_parens caused by break)
 - #151817 (Fix missing syntax context in lifetime hygiene debug output)
 - #151836 (Fix flakyness issue with `tests/rustdoc-gui/globals.goml` test)
 - #151844 (rustc-dev-guide subtree update)
rust-bors Bot pushed a commit that referenced this pull request Jan 30, 2026
Rollup of 5 pull requests

Successful merges:

 - #151777 (    Reduce generics use in the query system.)
 - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - #151811 (Fix false positive in unused_parens caused by break)
 - #151817 (Fix missing syntax context in lifetime hygiene debug output)
 - #151844 (rustc-dev-guide subtree update)
@rust-bors
rust-bors Bot merged commit dcc74dd into rust-lang:main Jan 30, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 30, 2026
rust-timer added a commit that referenced this pull request Jan 30, 2026
Rollup merge of #151817 - aytey:fix_lifetime_unpretty_hygiene, r=jdonszelmann

Fix missing syntax context in lifetime hygiene debug output

`-Zunpretty=expanded,hygiene` was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes `'a` with different hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and `/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with the full `Ident`, matching how regular identifiers are handled in `print_ident`.

Closes: #151797
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 31, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#151777 (    Reduce generics use in the query system.)
 - rust-lang/rust#151808 (Document a safety condition for `TypedArena::alloc_raw_slice`)
 - rust-lang/rust#151811 (Fix false positive in unused_parens caused by break)
 - rust-lang/rust#151817 (Fix missing syntax context in lifetime hygiene debug output)
 - rust-lang/rust#151844 (rustc-dev-guide subtree update)
@RalfJung

RalfJung commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

The test you added here has very strange behavior. Just look at its git history:
https://github.com/rust-lang/rust/commits/676862daf62785e9aa0a614f91ce5683c66ccd25/tests/ui/hygiene/unpretty-debug-lifetimes.stdout
Every now and then we have to add or remove a newline.

I think it's because this normalization

// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"

doesn't normalize away newline differences.
So, the test still does sometimes break when symbol numbering changes... any way this could be avoided? It is causing confusion and CI failures.^^

@aytey

aytey commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

The test you added here has very strange behavior. Just look at its git history: https://github.com/rust-lang/rust/commits/676862daf62785e9aa0a614f91ce5683c66ccd25/tests/ui/hygiene/unpretty-debug-lifetimes.stdout Every now and then we have to add or remove a newline.

I think it's because this normalization

// Don't break whenever Symbol numbering changes
//@ normalize-stdout: "\d+#" -> "0#"

doesn't normalize away newline differences. So, the test still does sometimes break when symbol numbering changes... any way this could be avoided? It is causing confusion and CI failures.^^

@RalfJung: I attempted to fix this here: #162608

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
… r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
Rollup merge of #162608 - aytey:unpretty-hygiene-test-churn, r=fmease

Avoid oscillating line wrapping due to symbol indices

A comment against PR #151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 4, 2026
Avoid oscillating line wrapping due to symbol indices

A comment against PR rust-lang/rust#151817 mentioned that the test file added in this PR kept causing "arbitrary" test file changes.

This is because one line of the expanded output sits *just* at 78 columns, which is the pretty-printer's margin. Adding or removing a symbol shifts every index after it, and when one of those gains or loses a digit, the wrapping moves.

We cannot use `normalize-stdout` as the layout is decided before normalization runs.

We fix this by avoiding a strict golden comparison, and instead using a regex to directly test that the expected syntax contexts exist in the expanded output.

**LLM disclosure**: I used an LLM to help me understand the problem and how the regex would look, which the LLM then actioned. I reviewed the diff and the commit (along with the message) was performed by hand with me (with the LLM checking the content of the commit message, but the commit message was, indeed, written by a human).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lifetime hygiene comments missing #N suffix in -Zunpretty=expanded,hygiene output

4 participants