fix: avoid panic in convert_tuple_struct_to_named_struct on nested pattern usage#22613
Open
Albab-Hasan wants to merge 1 commit into
Open
fix: avoid panic in convert_tuple_struct_to_named_struct on nested pattern usage#22613Albab-Hasan wants to merge 1 commit into
convert_tuple_struct_to_named_struct on nested pattern usage#22613Albab-Hasan wants to merge 1 commit into
Conversation
…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
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.
the
TupleStructPatarm replaced the whole pattern range with a freshly builtRecordPat. when one usage is nested inside another usage of the same variant (e.g. matchingT::Value(T::Value(t))on a recursive enum), the outer and inner edits target overlapping ranges and SyntaxEditorsedit_algopanics trying to resolve twoReplaceAlloperations 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 thePathExpr/CallExprarm.fixes #22094