Skip to content

fix: prevent ICE on lifetime-only macro arguments - #7100

Open
saberoueslati wants to merge 1 commit into
rust-lang:mainfrom
saberoueslati:parser/fix-issue-7034
Open

fix: prevent ICE on lifetime-only macro arguments#7100
saberoueslati wants to merge 1 commit into
rust-lang:mainfrom
saberoueslati:parser/fix-issue-7034

Conversation

@saberoueslati

Copy link
Copy Markdown

Fixes #7034.

Problem

Malformed macro arguments ending in &'a trigger rustc’s pattern parser, which creates an empty suggestion span at EOF and trips a debug assertion. &&'a variants are also affected because && is parsed as nested & tokens.

Fix

Skip speculative pattern parsing when a run of &/&& tokens is followed by a lifetime. Valid types remain unaffected, and rustfmt uses its existing unparseable-macro fallback.

Testing

Added &'a, &&'a, and &&&'a cases to dont_emit_ICE. Full cargo test passes.

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

LLM was used to understand the issue and as an extra reviewer for my code

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Sep 3, 2026
@ytmimi ytmimi added S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Sep 4, 2026
@ytmimi

ytmimi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

I wonder if this is the right approach. The root of the issue is in the rustc parser when debug-assertions are enabled. I feel like a more appropriate fix would be to address the source of the issue in rust-lang/rust than try to side step the issue by conditionally avoiding parser.parse_pat_no_top_alt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE with debug-assertions]: Span must not be empty and have no suggestion

3 participants