Skip to content

Commit e00e5b8

Browse files
committed
remove redundant clone_subtree
1 parent 09ae159 commit e00e5b8

7 files changed

Lines changed: 15 additions & 23 deletions

File tree

crates/ide-assists/src/handlers/convert_range_for_to_while.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn process_loop_body(
133133
) -> Option<()> {
134134
let last = previous_non_trivia_token(body.r_curly_token()?)?.syntax_element();
135135

136-
let new_body = body.indent(1.into()).clone_subtree();
136+
let new_body = body.indent(1.into());
137137
let mut continues = vec![];
138138
collect_continue_to(
139139
&mut continues,

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ fn generate_impl(
363363
ast_strukt,
364364
&old_impl,
365365
&transform_args,
366-
trait_args.clone_subtree(),
366+
trait_args.clone(),
367367
) {
368-
*trait_args = new_args.clone_subtree();
368+
*trait_args = new_args.clone();
369369
Some(new_args)
370370
} else {
371371
None

crates/ide-assists/src/handlers/remove_dbg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn compute_dbg_replacement(
163163
None => false,
164164
};
165165
let expr = replace_nested_dbgs(expr.clone());
166-
let expr = if wrap { make::expr_paren(expr).into() } else { expr.clone_subtree() };
166+
let expr = if wrap { make::expr_paren(expr).into() } else { expr };
167167
(vec![macro_call.syntax().clone().into()], Some(expr))
168168
}
169169
// dbg!(expr0, expr1, ...)

crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,8 @@ fn impl_def_from_trait(
220220
&impl_def,
221221
&target_scope,
222222
);
223-
let assoc_item_list = if let Some((first, other)) =
224-
assoc_items.split_first().map(|(first, other)| (first.clone_subtree(), other))
225-
{
226-
let first_item = if let ast::AssocItem::Fn(ref func) = first
223+
let assoc_item_list = if let Some((first, other)) = assoc_items.split_first() {
224+
let first_item = if let ast::AssocItem::Fn(func) = first
227225
&& let Some(body) = gen_trait_fn_body(&make, func, trait_path, adt, None)
228226
&& let Some(func_body) = func.body()
229227
{

crates/ide-assists/src/handlers/unwrap_block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn delete_else_before(container: SyntaxNode, edit: &mut SyntaxEditor) {
103103
fn wrap_let(assign: &ast::LetStmt, replacement: ast::BlockExpr) -> ast::BlockExpr {
104104
let try_wrap_assign = || {
105105
let initializer = assign.initializer()?.syntax().syntax_element();
106-
let replacement = replacement.clone_subtree();
106+
let (mut edit, replacement) = SyntaxEditor::with_ast_node(&replacement);
107107
let assign = assign.clone_for_update();
108108
let tail_expr = replacement.tail_expr()?;
109109
let before =
@@ -115,7 +115,6 @@ fn wrap_let(assign: &ast::LetStmt, replacement: ast::BlockExpr) -> ast::BlockExp
115115
.skip(1)
116116
.collect();
117117

118-
let (mut edit, _) = SyntaxEditor::new(replacement.syntax().clone());
119118
edit.insert_all(Position::before(tail_expr.syntax()), before);
120119
edit.insert_all(Position::after(tail_expr.syntax()), after);
121120
ast::BlockExpr::cast(edit.finish().new_root().clone())

crates/ide-assists/src/utils.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,8 @@ fn invert_special_case(make: &SyntaxFactory, expr: &ast::Expr) -> Option<ast::Ex
330330
Some(make.expr_method_call(receiver, make.name_ref(method), arg_list).into())
331331
}
332332
ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => match pe.expr()? {
333-
ast::Expr::ParenExpr(parexpr) => {
334-
parexpr.expr().map(|e| e.clone_subtree().clone_for_update())
335-
}
336-
_ => pe.expr().map(|e| e.clone_subtree().clone_for_update()),
333+
ast::Expr::ParenExpr(parexpr) => parexpr.expr(),
334+
_ => pe.expr(),
337335
},
338336
ast::Expr::Literal(lit) => match lit.kind() {
339337
ast::LiteralKind::Bool(b) => match b {

crates/ide-db/src/path_transform.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,16 @@ impl Ctx<'_> {
412412
if old.parent().is_some() {
413413
editor.replace(old, subst.clone().syntax());
414414
} else {
415-
// Some `path_ty` has no parent, especially ones made for default value
416-
// of type parameters.
417-
// In this case, `ted` cannot replace `path_ty` with `subst` directly.
418-
// So, just replace its children as long as the `subst` is the same type.
419-
let new = subst.clone_subtree().clone_for_update();
420-
if !matches!(new, ast::Type::PathType(..)) {
421-
return None;
422-
}
423415
let start = path_ty.syntax().first_child().map(NodeOrToken::Node)?;
424416
let end = path_ty.syntax().last_child().map(NodeOrToken::Node)?;
425417
editor.replace_all(
426418
start..=end,
427-
new.syntax().children().map(NodeOrToken::Node).collect::<Vec<_>>(),
419+
subst
420+
.clone()
421+
.syntax()
422+
.children()
423+
.map(NodeOrToken::Node)
424+
.collect::<Vec<_>>(),
428425
);
429426
}
430427
} else {

0 commit comments

Comments
 (0)