Skip to content

Commit 50a17e7

Browse files
committed
fix: make::expr_call() -> CallExpr
Signed-off-by: Prajwal S N <[email protected]>
1 parent 1470ddb commit 50a17e7

File tree

9 files changed

+33
-29
lines changed

9 files changed

+33
-29
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fn wrap_ok(expr: ast::Expr) -> ast::Expr {
128128
make::expr_path(make::ext::ident_path("Ok")),
129129
make::arg_list(std::iter::once(expr)),
130130
)
131+
.into()
131132
}
132133

133134
#[cfg(test)]

src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> Sy
14291429
make::expr_method_call(self_arg, name, args).into()
14301430
} else {
14311431
let func = make::expr_path(make::path_unqualified(make::path_segment(name)));
1432-
make::expr_call(func, args)
1432+
make::expr_call(func, args).into()
14331433
};
14341434

14351435
let handler = FlowHandler::from_ret_ty(fun, &ret_ty);
@@ -1911,14 +1911,15 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
19111911
};
19121912
let func = make::expr_path(make::ext::ident_path(constructor));
19131913
let args = make::arg_list(iter::once(tail_expr));
1914-
make::expr_call(func, args)
1914+
make::expr_call(func, args).into()
19151915
})
19161916
}
19171917
FlowHandler::If { .. } => {
19181918
let controlflow_continue = make::expr_call(
19191919
make::expr_path(make::path_from_text("ControlFlow::Continue")),
19201920
make::arg_list([make::ext::expr_unit()]),
1921-
);
1921+
)
1922+
.into();
19221923
with_tail_expr(block, controlflow_continue)
19231924
}
19241925
FlowHandler::IfOption { .. } => {
@@ -1928,12 +1929,12 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
19281929
FlowHandler::MatchOption { .. } => map_tail_expr(block, |tail_expr| {
19291930
let some = make::expr_path(make::ext::ident_path("Some"));
19301931
let args = make::arg_list(iter::once(tail_expr));
1931-
make::expr_call(some, args)
1932+
make::expr_call(some, args).into()
19321933
}),
19331934
FlowHandler::MatchResult { .. } => map_tail_expr(block, |tail_expr| {
19341935
let ok = make::expr_path(make::ext::ident_path("Ok"));
19351936
let args = make::arg_list(iter::once(tail_expr));
1936-
make::expr_call(ok, args)
1937+
make::expr_call(ok, args).into()
19371938
}),
19381939
}
19391940
}
@@ -2121,17 +2122,18 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
21212122
FlowHandler::If { .. } => make::expr_call(
21222123
make::expr_path(make::path_from_text("ControlFlow::Break")),
21232124
make::arg_list([make::ext::expr_unit()]),
2124-
),
2125+
)
2126+
.into(),
21252127
FlowHandler::IfOption { .. } => {
21262128
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
21272129
let args = make::arg_list([expr]);
2128-
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
2130+
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args).into()
21292131
}
21302132
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
21312133
FlowHandler::MatchResult { .. } => {
21322134
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
21332135
let args = make::arg_list([expr]);
2134-
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
2136+
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args).into()
21352137
}
21362138
};
21372139
Some(make::expr_return(Some(value)).clone_for_update())

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ fn func_assoc_item(
751751
}
752752
.clone_for_update();
753753

754-
let body = make::block_expr(vec![], Some(call)).clone_for_update();
754+
let body = make::block_expr(vec![], Some(call.into())).clone_for_update();
755755
let func = make::fn_(
756756
item.visibility(),
757757
item.name()?,

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn make_fn_body_as_new_function(
475475
.map(|_| placeholder_expr.clone())
476476
.collect::<Vec<_>>();
477477

478-
make::expr_call(make::expr_path(path_self), make::arg_list(args))
478+
make::expr_call(make::expr_path(path_self), make::arg_list(args)).into()
479479
}
480480
StructKind::Unit => make::expr_path(path_self),
481481
}

src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn into_call(param: &Expr) -> Expr {
155155
None
156156
}
157157
})()
158-
.unwrap_or_else(|| make::expr_call(param.clone(), make::arg_list(Vec::new())))
158+
.unwrap_or_else(|| make::expr_call(param.clone(), make::arg_list(Vec::new())).into())
159159
}
160160

161161
#[cfg(test)]

src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ pub(crate) fn replace_try_expr_with_match(
6161
TryEnum::Option => {
6262
make::expr_return(Some(make::expr_path(make::ext::ident_path("None"))))
6363
}
64-
TryEnum::Result => make::expr_return(Some(make::expr_call(
65-
make::expr_path(make::ext::ident_path("Err")),
66-
make::arg_list(iter::once(make::expr_path(make::ext::ident_path("err")))),
67-
))),
64+
TryEnum::Result => make::expr_return(Some(
65+
make::expr_call(
66+
make::expr_path(make::ext::ident_path("Err")),
67+
make::arg_list(iter::once(make::expr_path(make::ext::ident_path("err")))),
68+
)
69+
.into(),
70+
)),
6871
};
6972

7073
let happy_arm = make::match_arm(

src/tools/rust-analyzer/crates/ide-assists/src/utils/gen_trait_fn_body.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
8383
}
8484
let pat = make::tuple_struct_pat(variant_name.clone(), pats.into_iter());
8585
let struct_name = make::expr_path(variant_name);
86-
let tuple_expr = make::expr_call(struct_name, make::arg_list(fields));
86+
let tuple_expr =
87+
make::expr_call(struct_name, make::arg_list(fields)).into();
8788
arms.push(make::match_arm(pat.into(), None, tuple_expr));
8889
}
8990

@@ -126,7 +127,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
126127
fields.push(gen_clone_call(target));
127128
}
128129
let struct_name = make::expr_path(make::ext::ident_path("Self"));
129-
make::expr_call(struct_name, make::arg_list(fields))
130+
make::expr_call(struct_name, make::arg_list(fields)).into()
130131
}
131132
// => Self { }
132133
None => {
@@ -303,7 +304,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
303304
fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
304305
fn gen_default_call() -> Option<ast::Expr> {
305306
let fn_name = make::ext::path_from_idents(["Default", "default"])?;
306-
Some(make::expr_call(make::expr_path(fn_name), make::arg_list(None)))
307+
Some(make::expr_call(make::expr_path(fn_name), make::arg_list(None)).into())
307308
}
308309
match adt {
309310
// `Debug` cannot be derived for unions, so no default impl can be provided.
@@ -330,7 +331,7 @@ fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
330331
.fields()
331332
.map(|_| gen_default_call())
332333
.collect::<Option<Vec<ast::Expr>>>()?;
333-
make::expr_call(struct_name, make::arg_list(fields))
334+
make::expr_call(struct_name, make::arg_list(fields)).into()
334335
}
335336
None => {
336337
let struct_name = make::ext::ident_path("Self");
@@ -364,7 +365,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
364365
let fn_name = make_discriminant()?;
365366

366367
let arg = make::expr_path(make::ext::ident_path("self"));
367-
let fn_call = make::expr_call(fn_name, make::arg_list(Some(arg)));
368+
let fn_call = make::expr_call(fn_name, make::arg_list(Some(arg))).into();
368369
let stmt = gen_hash_call(fn_call);
369370

370371
make::block_expr(Some(stmt), None).indent(ast::edit::IndentLevel(1))
@@ -447,9 +448,11 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>) -
447448
ast::Adt::Enum(enum_) => {
448449
// => std::mem::discriminant(self) == std::mem::discriminant(other)
449450
let lhs_name = make::expr_path(make::ext::ident_path("self"));
450-
let lhs = make::expr_call(make_discriminant()?, make::arg_list(Some(lhs_name.clone())));
451+
let lhs = make::expr_call(make_discriminant()?, make::arg_list(Some(lhs_name.clone())))
452+
.into();
451453
let rhs_name = make::expr_path(make::ext::ident_path("other"));
452-
let rhs = make::expr_call(make_discriminant()?, make::arg_list(Some(rhs_name.clone())));
454+
let rhs = make::expr_call(make_discriminant()?, make::arg_list(Some(rhs_name.clone())))
455+
.into();
453456
let eq_check =
454457
make::expr_bin_op(lhs, BinaryOp::CmpOp(CmpOp::Eq { negated: false }), rhs);
455458

src/tools/rust-analyzer/crates/syntax/src/ast/make.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::PrefixExpr {
633633
let token = token(op);
634634
expr_from_text(&format!("{token}{expr}"))
635635
}
636-
pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
636+
pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::CallExpr {
637637
expr_from_text(&format!("{f}{arg_list}"))
638638
}
639639
pub fn expr_method_call(

src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,7 @@ impl SyntaxFactory {
400400
}
401401

402402
pub fn expr_call(&self, expr: ast::Expr, arg_list: ast::ArgList) -> ast::CallExpr {
403-
// FIXME: `make::expr_call`` should return a `CallExpr`, not just an `Expr`
404-
let ast::Expr::CallExpr(ast) =
405-
make::expr_call(expr.clone(), arg_list.clone()).clone_for_update()
406-
else {
407-
unreachable!()
408-
};
403+
let ast = make::expr_call(expr.clone(), arg_list.clone()).clone_for_update();
409404

410405
if let Some(mut mapping) = self.mappings() {
411406
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());

0 commit comments

Comments
 (0)