aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-19 19:03:56 +0100
committerGitHub <[email protected]>2021-04-19 19:03:56 +0100
commitb6a7276c5435da2431eb7dd783aa09c0cd718371 (patch)
tree45a01bb69aad5cd74a330f560d22ee11f1a31d18 /crates/hir_expand
parent9cfbb56afac972b317f3a2b314302a7b4cc92edc (diff)
parent952fc236948ce8a63e7f7ee49878aa2ffd011298 (diff)
Merge #8586
8586: Replace SyntaxRewriter usage with ted in eager::eager_macro_recur r=Veykril a=Veykril Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_expand')
-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 a5ac32d3c..f12132f84 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
34#[derive(Debug)] 34#[derive(Debug)]
35pub struct ErrorEmitted { 35pub struct ErrorEmitted {
@@ -192,10 +192,10 @@ fn eager_macro_recur(
192 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, 192 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
193 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError), 193 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
194) -> Result<SyntaxNode, ErrorEmitted> { 194) -> Result<SyntaxNode, ErrorEmitted> {
195 let original = curr.value.clone(); 195 let original = curr.value.clone().clone_for_update();
196 196
197 let children = curr.value.descendants().filter_map(ast::MacroCall::cast); 197 let children = original.descendants().filter_map(ast::MacroCall::cast);
198 let mut rewriter = SyntaxRewriter::default(); 198 let mut replacements = Vec::new();
199 199
200 // Collect replacement 200 // Collect replacement
201 for child in children { 201 for child in children {
@@ -214,6 +214,7 @@ fn eager_macro_recur(
214 .into(); 214 .into();
215 db.parse_or_expand(id.as_file()) 215 db.parse_or_expand(id.as_file())
216 .expect("successful macro expansion should be parseable") 216 .expect("successful macro expansion should be parseable")
217 .clone_for_update()
217 } 218 }
218 MacroDefKind::Declarative(_) 219 MacroDefKind::Declarative(_)
219 | MacroDefKind::BuiltIn(..) 220 | MacroDefKind::BuiltIn(..)
@@ -227,15 +228,14 @@ fn eager_macro_recur(
227 } 228 }
228 }; 229 };
229 230
230 // check if the whole original sytnax is replaced 231 // check if the whole original syntax is replaced
231 // Note that SyntaxRewriter cannot replace the root node itself
232 if child.syntax() == &original { 232 if child.syntax() == &original {
233 return Ok(insert); 233 return Ok(insert);
234 } 234 }
235 235
236 rewriter.replace(child.syntax(), &insert); 236 replacements.push((child, insert));
237 } 237 }
238 238
239 let res = rewriter.rewrite(&original); 239 replacements.into_iter().rev().for_each(|(old, new)| ted::replace(old.syntax(), new));
240 Ok(res) 240 Ok(original)
241} 241}