aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index f74c9f9c6..bdaecdc43 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -251,7 +251,7 @@ impl ast::UseItem {
251 #[must_use] 251 #[must_use]
252 pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { 252 pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem {
253 if let Some(old) = self.use_tree() { 253 if let Some(old) = self.use_tree() {
254 return self.replace_descendants(iter::once((old, use_tree))); 254 return self.replace_descendant(old, use_tree);
255 } 255 }
256 self.clone() 256 self.clone()
257 } 257 }
@@ -283,7 +283,7 @@ impl ast::UseTree {
283 #[must_use] 283 #[must_use]
284 pub fn with_path(&self, path: ast::Path) -> ast::UseTree { 284 pub fn with_path(&self, path: ast::Path) -> ast::UseTree {
285 if let Some(old) = self.path() { 285 if let Some(old) = self.path() {
286 return self.replace_descendants(iter::once((old, path))); 286 return self.replace_descendant(old, path);
287 } 287 }
288 self.clone() 288 self.clone()
289 } 289 }
@@ -291,7 +291,7 @@ impl ast::UseTree {
291 #[must_use] 291 #[must_use]
292 pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree { 292 pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree {
293 if let Some(old) = self.use_tree_list() { 293 if let Some(old) = self.use_tree_list() {
294 return self.replace_descendants(iter::once((old, use_tree_list))); 294 return self.replace_descendant(old, use_tree_list);
295 } 295 }
296 self.clone() 296 self.clone()
297 } 297 }
@@ -466,6 +466,11 @@ pub trait AstNodeEdit: AstNode + Sized {
466 } 466 }
467 467
468 #[must_use] 468 #[must_use]
469 fn replace_descendant<D: AstNode>(&self, old: D, new: D) -> Self {
470 self.replace_descendants(iter::once((old, new)))
471 }
472
473 #[must_use]
469 fn replace_descendants<D: AstNode>( 474 fn replace_descendants<D: AstNode>(
470 &self, 475 &self,
471 replacement_map: impl IntoIterator<Item = (D, D)>, 476 replacement_map: impl IntoIterator<Item = (D, D)>,