@@ -29,7 +29,7 @@ use base_db::CrateId;
29
29
use mbe:: ExpandResult ;
30
30
use parser:: FragmentKind ;
31
31
use std:: sync:: Arc ;
32
- use syntax:: { algo :: SyntaxRewriter , SyntaxNode } ;
32
+ use syntax:: { ted , SyntaxNode } ;
33
33
34
34
pub struct ErrorEmitted {
35
35
_private : ( ) ,
@@ -191,10 +191,10 @@ fn eager_macro_recur(
191
191
macro_resolver : & dyn Fn ( ast:: Path ) -> Option < MacroDefId > ,
192
192
mut diagnostic_sink : & mut dyn FnMut ( mbe:: ExpandError ) ,
193
193
) -> Result < SyntaxNode , ErrorEmitted > {
194
- let original = curr. value . clone ( ) ;
194
+ let original = curr. value . clone ( ) . clone_for_update ( ) ;
195
195
196
- let children = curr . value . descendants ( ) . filter_map ( ast:: MacroCall :: cast) ;
197
- let mut rewriter = SyntaxRewriter :: default ( ) ;
196
+ let children = original . descendants ( ) . filter_map ( ast:: MacroCall :: cast) ;
197
+ let mut replacements = Vec :: new ( ) ;
198
198
199
199
// Collect replacement
200
200
for child in children {
@@ -213,6 +213,7 @@ fn eager_macro_recur(
213
213
. into ( ) ;
214
214
db. parse_or_expand ( id. as_file ( ) )
215
215
. expect ( "successful macro expansion should be parseable" )
216
+ . clone_for_update ( )
216
217
}
217
218
MacroDefKind :: Declarative ( _)
218
219
| MacroDefKind :: BuiltIn ( ..)
@@ -226,15 +227,14 @@ fn eager_macro_recur(
226
227
}
227
228
} ;
228
229
229
- // check if the whole original sytnax is replaced
230
- // Note that SyntaxRewriter cannot replace the root node itself
230
+ // check if the whole original syntax is replaced
231
231
if child. syntax ( ) == & original {
232
232
return Ok ( insert) ;
233
233
}
234
234
235
- rewriter . replace ( child . syntax ( ) , & insert) ;
235
+ replacements . push ( ( child , insert) ) ;
236
236
}
237
237
238
- let res = rewriter . rewrite ( & original ) ;
239
- Ok ( res )
238
+ replacements . into_iter ( ) . rev ( ) . for_each ( | ( old , new ) | ted :: replace ( old . syntax ( ) , new ) ) ;
239
+ Ok ( original )
240
240
}
0 commit comments