Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/path_transform.rs')
-rw-r--r--crates/ide-db/src/path_transform.rs67
1 files changed, 29 insertions, 38 deletions
diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs
index 508f841340..407276a2de 100644
--- a/crates/ide-db/src/path_transform.rs
+++ b/crates/ide-db/src/path_transform.rs
@@ -197,7 +197,7 @@ impl<'a> PathTransform<'a> {
&& let Some(default) =
&default.display_source_code(db, source_module.into(), false).ok()
{
- type_substs.insert(k, make::ty(default).clone_for_update());
+ type_substs.insert(k, make::ty(default));
defaulted_params.push(Either::Left(k));
}
}
@@ -222,7 +222,7 @@ impl<'a> PathTransform<'a> {
k.default(db, target_module.krate(db).to_display_target(db))
&& let Some(default) = default.expr()
{
- const_substs.insert(k, default.syntax().clone_for_update());
+ const_substs.insert(k, default.syntax().clone());
defaulted_params.push(Either::Right(k));
}
}
@@ -278,12 +278,10 @@ impl Ctx<'_> {
// `transform_path` may update a node's parent and that would break the
// tree traversal. Thus all paths in the tree are collected into a vec
// so that such operation is safe.
- let item = self.transform_path(item).clone_subtree();
- let mut editor = SyntaxEditor::new(item.clone());
+ let (mut editor, item) = SyntaxEditor::new(self.transform_path(item));
preorder_rev(&item).filter_map(ast::Lifetime::cast).for_each(|lifetime| {
if let Some(subst) = self.lifetime_substs.get(&lifetime.syntax().text().to_string()) {
- editor
- .replace(lifetime.syntax(), subst.clone_subtree().clone_for_update().syntax());
+ editor.replace(lifetime.syntax(), subst.clone().syntax());
}
});
@@ -331,18 +329,14 @@ impl Ctx<'_> {
result
}
- let root_path = path.clone_subtree();
-
+ let (mut editor, root_path) = SyntaxEditor::new(path.clone());
let result = find_child_paths_and_ident_pats(&root_path);
- let mut editor = SyntaxEditor::new(root_path.clone());
for sub_path in result {
let new = self.transform_path(sub_path.syntax());
editor.replace(sub_path.syntax(), new);
}
-
- let update_sub_item = editor.finish().new_root().clone().clone_subtree();
+ let (mut editor, update_sub_item) = SyntaxEditor::new(editor.finish().new_root().clone());
let item = find_child_paths_and_ident_pats(&update_sub_item);
- let mut editor = SyntaxEditor::new(update_sub_item);
for sub_path in item {
self.transform_path_or_ident_pat(&mut editor, &sub_path);
}
@@ -411,33 +405,27 @@ impl Ctx<'_> {
let segment = make::path_segment_ty(subst.clone(), trait_ref);
let qualified = make::path_from_segments(std::iter::once(segment), false);
- editor.replace(path.syntax(), qualified.clone_for_update().syntax());
+ editor.replace(path.syntax(), qualified.clone().syntax());
} else if let Some(path_ty) = ast::PathType::cast(parent) {
let old = path_ty.syntax();
if old.parent().is_some() {
- editor.replace(old, subst.clone_subtree().clone_for_update().syntax());
+ editor.replace(old, subst.clone().syntax());
} else {
- // Some `path_ty` has no parent, especially ones made for default value
- // of type parameters.
- // In this case, `ted` cannot replace `path_ty` with `subst` directly.
- // So, just replace its children as long as the `subst` is the same type.
- let new = subst.clone_subtree().clone_for_update();
- if !matches!(new, ast::Type::PathType(..)) {
- return None;
- }
let start = path_ty.syntax().first_child().map(NodeOrToken::Node)?;
let end = path_ty.syntax().last_child().map(NodeOrToken::Node)?;
editor.replace_all(
start..=end,
- new.syntax().children().map(NodeOrToken::Node).collect::<Vec<_>>(),
+ subst
+ .clone()
+ .syntax()
+ .children()
+ .map(NodeOrToken::Node)
+ .collect::<Vec<_>>(),
);
}
} else {
- editor.replace(
- path.syntax(),
- subst.clone_subtree().clone_for_update().syntax(),
- );
+ editor.replace(path.syntax(), subst.clone().syntax());
}
}
}
@@ -459,18 +447,17 @@ impl Ctx<'_> {
allow_unstable: true,
};
let found_path = self.target_module.find_path(self.source_scope.db, def, cfg)?;
- let res = mod_path_to_ast(&found_path, self.target_edition).clone_for_update();
- let mut res_editor = SyntaxEditor::new(res.syntax().clone_subtree());
+ let res = mod_path_to_ast(&found_path, self.target_edition);
+ let (mut res_editor, res) = SyntaxEditor::with_ast_node(&res);
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list())
&& let Some(segment) = res.segment()
{
if let Some(old) = segment.generic_arg_list() {
- res_editor
- .replace(old.syntax(), args.clone_subtree().syntax().clone_for_update())
+ res_editor.replace(old.syntax(), args.syntax().clone())
} else {
res_editor.insert(
syntax_editor::Position::last_child_of(segment.syntax()),
- args.clone_subtree().syntax().clone_for_update(),
+ args.syntax().clone(),
);
}
}
@@ -479,7 +466,7 @@ impl Ctx<'_> {
}
hir::PathResolution::ConstParam(cp) => {
if let Some(subst) = self.const_substs.get(&cp) {
- editor.replace(path.syntax(), subst.clone_subtree().clone_for_update());
+ editor.replace(path.syntax(), subst.clone());
}
}
hir::PathResolution::SelfType(imp) => {
@@ -496,7 +483,7 @@ impl Ctx<'_> {
true,
)
.ok()?;
- let ast_ty = make::ty(ty_str).clone_for_update();
+ let ast_ty = make::ty(ty_str);
if let Some(adt) = ty.as_adt()
&& let ast::Type::PathType(path_ty) = &ast_ty
@@ -516,8 +503,10 @@ impl Ctx<'_> {
if let Some(qual) =
mod_path_to_ast(&found_path, self.target_edition).qualifier()
{
- let res = make::path_concat(qual, path_ty.path()?).clone_for_update();
- editor.replace(path.syntax(), res.syntax());
+ editor.replace(
+ path.syntax(),
+ make::path_concat(qual, path_ty.path()?).syntax(),
+ );
return Some(());
}
}
@@ -593,8 +582,10 @@ impl Ctx<'_> {
allow_unstable: true,
};
let found_path = self.target_module.find_path(self.source_scope.db, def, cfg)?;
- let res = mod_path_to_ast(&found_path, self.target_edition).clone_for_update();
- editor.replace(ident_pat.syntax(), res.syntax());
+ editor.replace(
+ ident_pat.syntax(),
+ mod_path_to_ast(&found_path, self.target_edition).syntax(),
+ );
Some(())
}
_ => None,