Move syntax editor initialization invariants to its constructor#21960
Merged
ChayimFriedman2 merged 9 commits intorust-lang:masterfrom Apr 6, 2026
Conversation
…hink of root invariant
ChayimFriedman2
requested changes
Apr 5, 2026
Member
Author
Ah!!! thats a nice idea. Updated. |
ChayimFriedman2
approved these changes
Apr 6, 2026
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.
Currently, initializing
SyntaxEditorrequires the caller to maintain certain invariants. Specifically, the node used for initialization must be the root (i.e., it must have no parent) and must not be mutable. To ensure this, call sites either detach the subtree usingclone_subtreeor pass the root of the tree directly. This PR moves these invariants into theSyntaxEditorconstructor. If the node passed to the constructor is not a root node or is mutable, the constructor will internally callclone_subtreeto detach it and ensure a fresh, immutable tree. This removes the burden from the caller to handle detachment or mutability concerns. Additionally, the constructor’s return type has been updated. Along withSyntaxEditor, it now also returns a detached, immutable snapshot of the node, which can be used to issue mutation queries to the editor.part of #15710 and #18285