Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ide-assists/src/handlers/convert_for_to_while_let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ pub(crate) fn convert_for_loop_to_while_let(
{
(expr, Some(make.name_ref(method.as_str())))
} else if let ast::Expr::RefExpr(_) = iterable {
(make::expr_paren(iterable), Some(make.name_ref("into_iter")))
(make::expr_paren(iterable).into(), Some(make.name_ref("into_iter")))
} else {
(iterable, Some(make.name_ref("into_iter")))
};

let iterable = if let Some(method) = method {
make::expr_method_call(iterable, method, make::arg_list([]))
make::expr_method_call(iterable, method, make::arg_list([])).into()
} else {
iterable
};
Expand Down
1 change: 1 addition & 0 deletions crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn wrap_ok(expr: ast::Expr) -> ast::Expr {
make::expr_path(make::ext::ident_path("Ok")),
make::arg_list(std::iter::once(expr)),
)
.into()
}

#[cfg(test)]
Expand Down
20 changes: 11 additions & 9 deletions crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,10 +1426,10 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> Sy
let name = fun.name.clone();
let mut call_expr = if fun.self_param.is_some() {
let self_arg = make::expr_path(make::ext::ident_path("self"));
make::expr_method_call(self_arg, name, args)
make::expr_method_call(self_arg, name, args).into()
} else {
let func = make::expr_path(make::path_unqualified(make::path_segment(name)));
make::expr_call(func, args)
make::expr_call(func, args).into()
};

let handler = FlowHandler::from_ret_ty(fun, &ret_ty);
Expand Down Expand Up @@ -1911,14 +1911,15 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
};
let func = make::expr_path(make::ext::ident_path(constructor));
let args = make::arg_list(iter::once(tail_expr));
make::expr_call(func, args)
make::expr_call(func, args).into()
})
}
FlowHandler::If { .. } => {
let controlflow_continue = make::expr_call(
make::expr_path(make::path_from_text("ControlFlow::Continue")),
make::arg_list([make::ext::expr_unit()]),
);
)
.into();
with_tail_expr(block, controlflow_continue)
}
FlowHandler::IfOption { .. } => {
Expand All @@ -1928,12 +1929,12 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
FlowHandler::MatchOption { .. } => map_tail_expr(block, |tail_expr| {
let some = make::expr_path(make::ext::ident_path("Some"));
let args = make::arg_list(iter::once(tail_expr));
make::expr_call(some, args)
make::expr_call(some, args).into()
}),
FlowHandler::MatchResult { .. } => map_tail_expr(block, |tail_expr| {
let ok = make::expr_path(make::ext::ident_path("Ok"));
let args = make::arg_list(iter::once(tail_expr));
make::expr_call(ok, args)
make::expr_call(ok, args).into()
}),
}
}
Expand Down Expand Up @@ -2121,17 +2122,18 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
FlowHandler::If { .. } => make::expr_call(
make::expr_path(make::path_from_text("ControlFlow::Break")),
make::arg_list([make::ext::expr_unit()]),
),
)
.into(),
FlowHandler::IfOption { .. } => {
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
let args = make::arg_list([expr]);
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args).into()
}
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
FlowHandler::MatchResult { .. } => {
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
let args = make::arg_list([expr]);
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args).into()
}
};
Some(make::expr_return(Some(value)).clone_for_update())
Expand Down
3 changes: 2 additions & 1 deletion crates/ide-assists/src/handlers/generate_delegate_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
.map(convert_param_list_to_arg_list)
.unwrap_or_else(|| make::arg_list([]));

let tail_expr = make::expr_method_call(field, make::name_ref(&name), arg_list);
let tail_expr =
make::expr_method_call(field, make::name_ref(&name), arg_list).into();
let tail_expr_finished =
if is_async { make::expr_await(tail_expr) } else { tail_expr };
let body = make::block_expr([], Some(tail_expr_finished));
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/generate_delegate_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ fn func_assoc_item(
}
.clone_for_update();

let body = make::block_expr(vec![], Some(call)).clone_for_update();
let body = make::block_expr(vec![], Some(call.into())).clone_for_update();
let func = make::fn_(
item.visibility(),
item.name()?,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn make_fn_body_as_new_function(
.map(|_| placeholder_expr.clone())
.collect::<Vec<_>>();

make::expr_call(make::expr_path(path_self), make::arg_list(args))
make::expr_call(make::expr_path(path_self), make::arg_list(args)).into()
}
StructKind::Unit => make::expr_path(path_self),
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ide-assists/src/handlers/inline_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn inline(
&& usage.syntax().parent().and_then(ast::Expr::cast).is_some() =>
{
cov_mark::hit!(inline_call_inline_closure);
let expr = make::expr_paren(expr.clone());
let expr = make::expr_paren(expr.clone()).into();
inline_direct(usage, &expr);
}
// inline single use literals
Expand Down Expand Up @@ -567,7 +567,7 @@ fn inline(
let no_stmts = body.statements().next().is_none();
match body.tail_expr() {
Some(expr) if matches!(expr, ast::Expr::ClosureExpr(_)) && no_stmts => {
make::expr_paren(expr).clone_for_update()
make::expr_paren(expr).clone_for_update().into()
}
Some(expr) if !is_async_fn && no_stmts => expr,
_ => match node
Expand All @@ -577,7 +577,7 @@ fn inline(
.and_then(|bin_expr| bin_expr.lhs())
{
Some(lhs) if lhs.syntax() == node.syntax() => {
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update()
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update().into()
}
_ => ast::Expr::BlockExpr(body),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/remove_dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
None => false,
};
let expr = replace_nested_dbgs(expr.clone());
let expr = if wrap { make::expr_paren(expr) } else { expr.clone_subtree() };
let expr = if wrap { make::expr_paren(expr).into() } else { expr.clone_subtree() };
(macro_call.syntax().text_range(), Some(expr))
}
// dbg!(expr0, expr1, ...)
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-assists/src/handlers/replace_method_eager_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn into_closure(param: &Expr) -> Expr {
None
}
})()
.unwrap_or_else(|| make::expr_closure(None, param.clone()))
.unwrap_or_else(|| make::expr_closure(None, param.clone()).into())
}

// Assist: replace_with_eager_method
Expand Down Expand Up @@ -155,7 +155,7 @@ fn into_call(param: &Expr) -> Expr {
None
}
})()
.unwrap_or_else(|| make::expr_call(param.clone(), make::arg_list(Vec::new())))
.unwrap_or_else(|| make::expr_call(param.clone(), make::arg_list(Vec::new())).into())
}

#[cfg(test)]
Expand Down
11 changes: 7 additions & 4 deletions crates/ide-assists/src/handlers/replace_try_expr_with_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ pub(crate) fn replace_try_expr_with_match(
TryEnum::Option => {
make::expr_return(Some(make::expr_path(make::ext::ident_path("None"))))
}
TryEnum::Result => make::expr_return(Some(make::expr_call(
make::expr_path(make::ext::ident_path("Err")),
make::arg_list(iter::once(make::expr_path(make::ext::ident_path("err")))),
))),
TryEnum::Result => make::expr_return(Some(
make::expr_call(
make::expr_path(make::ext::ident_path("Err")),
make::arg_list(iter::once(make::expr_path(make::ext::ident_path("err")))),
)
.into(),
)),
};

let happy_arm = make::match_arm(
Expand Down
9 changes: 7 additions & 2 deletions crates/ide-assists/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
T![>] => T![<=],
T![>=] => T![<],
// Parenthesize other expressions before prefixing `!`
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone())).into()),
_ => {
return Some(
make::expr_prefix(T![!], make::expr_paren(expr.clone()).into()).into(),
);
}
};
ted::replace(op_token, make::token(rev_token));
Some(bin.into())
Expand All @@ -347,7 +351,7 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
"is_err" => "is_ok",
_ => return None,
};
Some(make::expr_method_call(receiver, make::name_ref(method), arg_list))
Some(make::expr_method_call(receiver, make::name_ref(method), arg_list).into())
}
ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => match pe.expr()? {
ast::Expr::ParenExpr(parexpr) => parexpr.expr(),
Expand Down Expand Up @@ -852,6 +856,7 @@ impl ReferenceConversion {
make::expr_ref(expr, false)
} else {
make::expr_method_call(expr, make::name_ref("as_ref"), make::arg_list([]))
.into()
}
}
}
Expand Down
Loading