File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -290,6 +290,11 @@ impl<'a> SyntaxRewriter<'a> {
290290 N :: cast ( self . rewrite ( node. syntax ( ) ) ) . unwrap ( )
291291 }
292292
293+ /// Returns a node that encompasses all replacements to be done by this rewriter.
294+ ///
295+ /// Passing the returned node to `rewrite` will apply all replacements queued up in `self`.
296+ ///
297+ /// Returns `None` when there are no replacements.
293298 pub fn rewrite_root ( & self ) -> Option < SyntaxNode > {
294299 assert ! ( self . f. is_none( ) ) ;
295300 self . replacements
@@ -298,6 +303,9 @@ impl<'a> SyntaxRewriter<'a> {
298303 SyntaxElement :: Node ( it) => it. clone ( ) ,
299304 SyntaxElement :: Token ( it) => it. parent ( ) ,
300305 } )
306+ // If we only have one replacement, we must return its parent node, since `rewrite` does
307+ // not replace the node passed to it.
308+ . map ( |it| it. parent ( ) . unwrap_or ( it) )
301309 . fold1 ( |a, b| least_common_ancestor ( & a, & b) . unwrap ( ) )
302310 }
303311
You can’t perform that action at this time.
0 commit comments