Unnamed repository; edit this file 'description' to name the repository.
fix: `make::expr_method_call() -> MethodCallExpr`
Signed-off-by: Prajwal S N <[email protected]>
Prajwal S N 2025-04-11
parent 728d72f · commit ab620e3
-rw-r--r--crates/ide-assists/src/handlers/convert_for_to_while_let.rs2
-rw-r--r--crates/ide-assists/src/handlers/extract_function.rs2
-rw-r--r--crates/ide-assists/src/handlers/generate_delegate_methods.rs3
-rw-r--r--crates/ide-assists/src/utils.rs3
-rw-r--r--crates/ide-assists/src/utils/gen_trait_fn_body.rs33
-rw-r--r--crates/syntax/src/ast/make.rs2
-rw-r--r--crates/syntax/src/ast/syntax_factory/constructors.rs9
7 files changed, 27 insertions, 27 deletions
diff --git a/crates/ide-assists/src/handlers/convert_for_to_while_let.rs b/crates/ide-assists/src/handlers/convert_for_to_while_let.rs
index 815e712caa..0ba292f5fc 100644
--- a/crates/ide-assists/src/handlers/convert_for_to_while_let.rs
+++ b/crates/ide-assists/src/handlers/convert_for_to_while_let.rs
@@ -66,7 +66,7 @@ pub(crate) fn convert_for_loop_to_while_let(
};
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
};
diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs
index ae53d7eeed..64f187edf9 100644
--- a/crates/ide-assists/src/handlers/extract_function.rs
+++ b/crates/ide-assists/src/handlers/extract_function.rs
@@ -1426,7 +1426,7 @@ 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)
diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
index 4794bf541f..ca66cb69dc 100644
--- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs
+++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
@@ -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));
diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs
index c05310b342..fdc5dd13eb 100644
--- a/crates/ide-assists/src/utils.rs
+++ b/crates/ide-assists/src/utils.rs
@@ -351,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(),
@@ -856,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()
}
}
}
diff --git a/crates/ide-assists/src/utils/gen_trait_fn_body.rs b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
index 5c2e27b343..553889d123 100644
--- a/crates/ide-assists/src/utils/gen_trait_fn_body.rs
+++ b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
@@ -35,7 +35,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
stdx::always!(func.name().is_some_and(|name| name.text() == "clone"));
fn gen_clone_call(target: ast::Expr) -> ast::Expr {
let method = make::name_ref("clone");
- make::expr_method_call(target, method, make::arg_list(None))
+ make::expr_method_call(target, method, make::arg_list(None)).into()
}
let expr = match adt {
// `Clone` cannot be derived for unions, so no default impl can be provided.
@@ -165,7 +165,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let method = make::name_ref("debug_struct");
let struct_name = format!("\"{name}\"");
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
- let mut expr = make::expr_method_call(target, method, args);
+ let mut expr = make::expr_method_call(target, method, args).into();
let mut pats = vec![];
for field in list.fields() {
@@ -181,12 +181,13 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let path = &format!("{field_name}");
let path = make::expr_path(make::ext::ident_path(path));
let args = make::arg_list(vec![name, path]);
- expr = make::expr_method_call(expr, method_name, args);
+ expr = make::expr_method_call(expr, method_name, args).into();
}
// => <expr>.finish()
let method = make::name_ref("finish");
- let expr = make::expr_method_call(expr, method, make::arg_list(None));
+ let expr =
+ make::expr_method_call(expr, method, make::arg_list(None)).into();
// => MyStruct { fields.. } => f.debug_struct("MyStruct")...finish(),
let pat = make::record_pat(variant_name.clone(), pats.into_iter());
@@ -198,7 +199,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let method = make::name_ref("debug_tuple");
let struct_name = format!("\"{name}\"");
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
- let mut expr = make::expr_method_call(target, method, args);
+ let mut expr = make::expr_method_call(target, method, args).into();
let mut pats = vec![];
for (i, _) in list.fields().enumerate() {
@@ -214,12 +215,13 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let field_path = &name.to_string();
let field_path = make::expr_path(make::ext::ident_path(field_path));
let args = make::arg_list(vec![field_path]);
- expr = make::expr_method_call(expr, method_name, args);
+ expr = make::expr_method_call(expr, method_name, args).into();
}
// => <expr>.finish()
let method = make::name_ref("finish");
- let expr = make::expr_method_call(expr, method, make::arg_list(None));
+ let expr =
+ make::expr_method_call(expr, method, make::arg_list(None)).into();
// => MyStruct (fields..) => f.debug_tuple("MyStruct")...finish(),
let pat = make::tuple_struct_pat(variant_name.clone(), pats.into_iter());
@@ -254,12 +256,12 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let expr = match strukt.field_list() {
// => f.debug_struct("Name").finish()
- None => make::expr_method_call(target, make::name_ref("debug_struct"), args),
+ None => make::expr_method_call(target, make::name_ref("debug_struct"), args).into(),
// => f.debug_struct("Name").field("foo", &self.foo).finish()
Some(ast::FieldList::RecordFieldList(field_list)) => {
let method = make::name_ref("debug_struct");
- let mut expr = make::expr_method_call(target, method, args);
+ let mut expr = make::expr_method_call(target, method, args).into();
for field in field_list.fields() {
let name = field.name()?;
let f_name = make::expr_literal(&(format!("\"{name}\""))).into();
@@ -267,7 +269,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
let f_path = make::expr_ref(f_path, false);
let f_path = make::expr_field(f_path, &format!("{name}"));
let args = make::arg_list([f_name, f_path]);
- expr = make::expr_method_call(expr, make::name_ref("field"), args);
+ expr = make::expr_method_call(expr, make::name_ref("field"), args).into();
}
expr
}
@@ -275,20 +277,21 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
// => f.debug_tuple("Name").field(self.0).finish()
Some(ast::FieldList::TupleFieldList(field_list)) => {
let method = make::name_ref("debug_tuple");
- let mut expr = make::expr_method_call(target, method, args);
+ let mut expr = make::expr_method_call(target, method, args).into();
for (i, _) in field_list.fields().enumerate() {
let f_path = make::expr_path(make::ext::ident_path("self"));
let f_path = make::expr_ref(f_path, false);
let f_path = make::expr_field(f_path, &format!("{i}"));
let method = make::name_ref("field");
- expr = make::expr_method_call(expr, method, make::arg_list(Some(f_path)));
+ expr = make::expr_method_call(expr, method, make::arg_list(Some(f_path)))
+ .into();
}
expr
}
};
let method = make::name_ref("finish");
- let expr = make::expr_method_call(expr, method, make::arg_list(None));
+ let expr = make::expr_method_call(expr, method, make::arg_list(None)).into();
let body = make::block_expr(None, Some(expr)).indent(ast::edit::IndentLevel(1));
ted::replace(func.body()?.syntax(), body.clone_for_update().syntax());
Some(())
@@ -348,7 +351,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
fn gen_hash_call(target: ast::Expr) -> ast::Stmt {
let method = make::name_ref("hash");
let arg = make::expr_path(make::ext::ident_path("state"));
- let expr = make::expr_method_call(target, method, make::arg_list(Some(arg)));
+ let expr = make::expr_method_call(target, method, make::arg_list(Some(arg))).into();
make::expr_stmt(expr).into()
}
@@ -613,7 +616,7 @@ fn gen_partial_ord(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>)
fn gen_partial_cmp_call(lhs: ast::Expr, rhs: ast::Expr) -> ast::Expr {
let rhs = make::expr_ref(rhs, false);
let method = make::name_ref("partial_cmp");
- make::expr_method_call(lhs, method, make::arg_list(Some(rhs)))
+ make::expr_method_call(lhs, method, make::arg_list(Some(rhs))).into()
}
// Check that self type and rhs type match. We don't know how to implement the method
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 8f37ebce6a..1a5bfe17ea 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -640,7 +640,7 @@ pub fn expr_method_call(
receiver: ast::Expr,
method: ast::NameRef,
arg_list: ast::ArgList,
-) -> ast::Expr {
+) -> ast::MethodCallExpr {
expr_from_text(&format!("{receiver}.{method}{arg_list}"))
}
pub fn expr_macro_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
diff --git a/crates/syntax/src/ast/syntax_factory/constructors.rs b/crates/syntax/src/ast/syntax_factory/constructors.rs
index 4c4c3f0d49..894d7f1181 100644
--- a/crates/syntax/src/ast/syntax_factory/constructors.rs
+++ b/crates/syntax/src/ast/syntax_factory/constructors.rs
@@ -423,13 +423,8 @@ impl SyntaxFactory {
method: ast::NameRef,
arg_list: ast::ArgList,
) -> ast::MethodCallExpr {
- // FIXME: `make::expr_method_call` should return a `MethodCallExpr`, not just an `Expr`
- let ast::Expr::MethodCallExpr(ast) =
- make::expr_method_call(receiver.clone(), method.clone(), arg_list.clone())
- .clone_for_update()
- else {
- unreachable!()
- };
+ let ast = make::expr_method_call(receiver.clone(), method.clone(), arg_list.clone())
+ .clone_for_update();
if let Some(mut mapping) = self.mappings() {
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());