aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_expand/src')
-rw-r--r--crates/hir_expand/src/eager.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index ef126e4ad..f413a63f7 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -29,7 +29,7 @@ use base_db::CrateId;
29use mbe::ExpandResult; 29use mbe::ExpandResult;
30use parser::FragmentKind; 30use parser::FragmentKind;
31use std::sync::Arc; 31use std::sync::Arc;
32use syntax::{algo::SyntaxRewriter, SyntaxNode}; 32use syntax::{ted, SyntaxNode};
33 33
34pub struct ErrorEmitted { 34pub struct ErrorEmitted {
35 _private: (), 35 _private: (),
@@ -191,10 +191,10 @@ fn eager_macro_recur(
191 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, 191 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
192 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError), 192 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
193) -> Result<SyntaxNode, ErrorEmitted> { 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); 196 let children = original.descendants().filter_map(ast::MacroCall::cast);
197 let mut rewriter = SyntaxRewriter::default(); 197 let mut replacements = Vec::new();
198 198
199 // Collect replacement 199 // Collect replacement
200 for child in children { 200 for child in children {
@@ -213,6 +213,7 @@ fn eager_macro_recur(
213 .into(); 213 .into();
214 db.parse_or_expand(id.as_file()) 214 db.parse_or_expand(id.as_file())
215 .expect("successful macro expansion should be parseable") 215 .expect("successful macro expansion should be parseable")
216 .clone_for_update()
216 } 217 }
217 MacroDefKind::Declarative(_) 218 MacroDefKind::Declarative(_)
218 | MacroDefKind::BuiltIn(..) 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 // check if the whole original syntax is replaced
230 // Note that SyntaxRewriter cannot replace the root node itself
231 if child.syntax() == &original { 231 if child.syntax() == &original {
232 return Ok(insert); 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); 238 replacements.into_iter().rev().for_each(|(old, new)| ted::replace(old.syntax(), new));
239 Ok(res) 239 Ok(original)
240} 240}