diff options
author | Lukas Wirth <[email protected]> | 2021-04-19 18:28:41 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-04-19 18:28:41 +0100 |
commit | 617cd7231c1aee5d7ca04892c6983c009b5ee60c (patch) | |
tree | 19db08c5ce035ef41df066d17191b1c40cc96233 /crates | |
parent | 3f1a220f32220cd4a664ca1adac5eb36e9eb33b2 (diff) |
Remove SyntaxRewriter usage in eager::eager_macro_recur
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_expand/src/eager.rs | 18 |
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; | |||
29 | use mbe::ExpandResult; | 29 | use mbe::ExpandResult; |
30 | use parser::FragmentKind; | 30 | use parser::FragmentKind; |
31 | use std::sync::Arc; | 31 | use std::sync::Arc; |
32 | use syntax::{algo::SyntaxRewriter, SyntaxNode}; | 32 | use syntax::{ted, SyntaxNode}; |
33 | 33 | ||
34 | pub struct ErrorEmitted { | 34 | pub 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 | } |