Skip to content

fix: avoid panic in convert_tuple_struct_to_named_struct on nested pattern usage#22613

Open
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:convert-tuple-struct-nested-pat-panic
Open

fix: avoid panic in convert_tuple_struct_to_named_struct on nested pattern usage#22613
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:convert-tuple-struct-nested-pat-panic

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

the TupleStructPat arm replaced the whole pattern range with a freshly built RecordPat. when one usage is nested inside another usage of the same variant (e.g. matching T::Value(T::Value(t)) on a recursive enum), the outer and inner edits target overlapping ranges and SyntaxEditors edit_algo panics trying to resolve two ReplaceAll operations where ones range is nested inside the other.

switch to surgical token level edits instead: insert the field name before each subpattern in place, swap the (/) delimiter tokens for {/}, and relocate .. to the end. this mirrors the approach already used for the PathExpr/CallExpr arm.

fixes #22094

…ttern usage

The TupleStructPat arm replaced the whole pattern range with a freshly built RecordPat. When one usage is nested inside another usage of the same variant (e.g. matching `T::Value(T::Value(t))` on a recursive enum), the outer and inner edits target overlapping ranges, and SyntaxEditor's edit_algo panics trying to resolve two ReplaceAll operations where one's range is nested inside the other.

Switch to surgical token-level edits instead: insert the field name before each subpattern in place, swap the `(`/`)` delimiter tokens for `{`/`}`, and relocate `..` to the end (record patterns require it to be trailing, unlike tuple patterns).This mirrors the approach already used for the PathExpr/CallExpr arm, where edits only ever touch a usage's own tokens andnever overlapwith a nested usage's edits.

fixes rust-lang#22094
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert_tuple_struct_to_named_struct panics on recursive enum destructured with nested tuple pattern

2 participants