Add hygiene annotations for tokens in macro_rules! bodies#153308
Open
aytey wants to merge 1 commit intorust-lang:mainfrom
Open
Add hygiene annotations for tokens in macro_rules! bodies#153308aytey wants to merge 1 commit intorust-lang:mainfrom
macro_rules! bodies#153308aytey wants to merge 1 commit intorust-lang:mainfrom
Conversation
`-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>
Collaborator
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
macro_rules! bodies
Contributor
Author
|
(I hope this appropriate; I only selected @jdonszelmann as she helped me with my previous commit in the same area) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-Zunpretty=expanded,hygienewas not printing syntax context annotations for identifiers and lifetimes insidemacro_rules!bodies. These tokens are printed viaprint_tt()→token_to_string_ext(), which converts tokens to strings without callingann_post(). This meant that macro-generatedmacro_rules!definitions with hygienic metavar parameters (e.g. multiple$margdistinguished only by hygiene) were printed with no way to tell them apart.This was fixed by adding a match on
token.kindinprint_tt()to callann_post()forIdent,NtIdent,Lifetime, andNtLifetimetokens, matching howprint_ident()andprint_lifetime()already handle AST-level identifiers and lifetimes.