fix: don't panic when a lifetime is passed to an ident metavariable#22922
Open
shulaoda wants to merge 1 commit into
Open
Conversation
Veykril
reviewed
Jul 26, 2026
Comment on lines
+33
to
+36
| _ => { | ||
| res.push(ERROR, ctx_edition(punct.span.ctx)); | ||
| continue; | ||
| } |
Member
There was a problem hiding this comment.
This isn't the right spot to fix this. We are calling this function with an invalid state, so we need to fix this up in the caller somewhere. It seems like we are incorrectly recovering somewhere in the fragment parsing causing us to end up with a lone '
Contributor
Author
There was a problem hiding this comment.
Thanks for pointing this out!
shulaoda
marked this pull request as draft
July 26, 2026 14:40
shulaoda
force-pushed
the
07-26-fix_don_t_panic_when_a_macro_expansion_contains_a_lone_
branch
from
July 26, 2026 15:05
5eef988 to
9699be7
Compare
shulaoda
marked this pull request as ready for review
July 26, 2026 15:07
'ident metavariable
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.
Closes #22801
Passing a lifetime to a macro that expects an ident, likem!('a)for($t:ident), panics withNext token must be ident. rustc just reportsno rules expected 'a. The matcher consumes the'before theidentmatch fails, and the consumed token is still bound to the fragment, so the expansion ends up holding a'with nothing after it.to_parser_inputassumed a'is always followed by an ident. It is the point where every expansion, including proc macro output we don't control, becomes a syntax tree, so it now pushes anERRORtoken instead of panicking.The
expect_*helpers consume a token before checking what it is, so a failed match still advances past it.match_meta_varthen binds everything consumed since the savepoint, which form!('a)is the bare'that later trips the panic. ReturningFragment::Emptyon failure makes the caller take thepush_missingbranch it already has.The same bug made
@--1.0expand to a stray- -when matched against$lit:literal, hence the snapshot change inminus_belongs_to_literal.🤖 AI-assisted: understanding the issue, locating the cause, and writing the test.