Skip to content

Commit ab620e3

Browse files
committed
fix: make::expr_method_call() -> MethodCallExpr
Signed-off-by: Prajwal S N <[email protected]>
1 parent 728d72f commit ab620e3

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(crate) fn convert_for_loop_to_while_let(
6666
};
6767

6868
let iterable = if let Some(method) = method {
69-
make::expr_method_call(iterable, method, make::arg_list([]))
69+
make::expr_method_call(iterable, method, make::arg_list([])).into()
7070
} else {
7171
iterable
7272
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> Sy
14261426
let name = fun.name.clone();
14271427
let mut call_expr = if fun.self_param.is_some() {
14281428
let self_arg = make::expr_path(make::ext::ident_path("self"));
1429-
make::expr_method_call(self_arg, name, args)
1429+
make::expr_method_call(self_arg, name, args).into()
14301430
} else {
14311431
let func = make::expr_path(make::path_unqualified(make::path_segment(name)));
14321432
make::expr_call(func, args)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
140140
.map(convert_param_list_to_arg_list)
141141
.unwrap_or_else(|| make::arg_list([]));
142142

143-
let tail_expr = make::expr_method_call(field, make::name_ref(&name), arg_list);
143+
let tail_expr =
144+
make::expr_method_call(field, make::name_ref(&name), arg_list).into();
144145
let tail_expr_finished =
145146
if is_async { make::expr_await(tail_expr) } else { tail_expr };
146147
let body = make::block_expr([], Some(tail_expr_finished));

crates/ide-assists/src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
351351
"is_err" => "is_ok",
352352
_ => return None,
353353
};
354-
Some(make::expr_method_call(receiver, make::name_ref(method), arg_list))
354+
Some(make::expr_method_call(receiver, make::name_ref(method), arg_list).into())
355355
}
356356
ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => match pe.expr()? {
357357
ast::Expr::ParenExpr(parexpr) => parexpr.expr(),
@@ -856,6 +856,7 @@ impl ReferenceConversion {
856856
make::expr_ref(expr, false)
857857
} else {
858858
make::expr_method_call(expr, make::name_ref("as_ref"), make::arg_list([]))
859+
.into()
859860
}
860861
}
861862
}

crates/ide-assists/src/utils/gen_trait_fn_body.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
3535
stdx::always!(func.name().is_some_and(|name| name.text() == "clone"));
3636
fn gen_clone_call(target: ast::Expr) -> ast::Expr {
3737
let method = make::name_ref("clone");
38-
make::expr_method_call(target, method, make::arg_list(None))
38+
make::expr_method_call(target, method, make::arg_list(None)).into()
3939
}
4040
let expr = match adt {
4141
// `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<()> {
165165
let method = make::name_ref("debug_struct");
166166
let struct_name = format!("\"{name}\"");
167167
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
168-
let mut expr = make::expr_method_call(target, method, args);
168+
let mut expr = make::expr_method_call(target, method, args).into();
169169

170170
let mut pats = vec![];
171171
for field in list.fields() {
@@ -181,12 +181,13 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
181181
let path = &format!("{field_name}");
182182
let path = make::expr_path(make::ext::ident_path(path));
183183
let args = make::arg_list(vec![name, path]);
184-
expr = make::expr_method_call(expr, method_name, args);
184+
expr = make::expr_method_call(expr, method_name, args).into();
185185
}
186186

187187
// => <expr>.finish()
188188
let method = make::name_ref("finish");
189-
let expr = make::expr_method_call(expr, method, make::arg_list(None));
189+
let expr =
190+
make::expr_method_call(expr, method, make::arg_list(None)).into();
190191

191192
// => MyStruct { fields.. } => f.debug_struct("MyStruct")...finish(),
192193
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<()> {
198199
let method = make::name_ref("debug_tuple");
199200
let struct_name = format!("\"{name}\"");
200201
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
201-
let mut expr = make::expr_method_call(target, method, args);
202+
let mut expr = make::expr_method_call(target, method, args).into();
202203

203204
let mut pats = vec![];
204205
for (i, _) in list.fields().enumerate() {
@@ -214,12 +215,13 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
214215
let field_path = &name.to_string();
215216
let field_path = make::expr_path(make::ext::ident_path(field_path));
216217
let args = make::arg_list(vec![field_path]);
217-
expr = make::expr_method_call(expr, method_name, args);
218+
expr = make::expr_method_call(expr, method_name, args).into();
218219
}
219220

220221
// => <expr>.finish()
221222
let method = make::name_ref("finish");
222-
let expr = make::expr_method_call(expr, method, make::arg_list(None));
223+
let expr =
224+
make::expr_method_call(expr, method, make::arg_list(None)).into();
223225

224226
// => MyStruct (fields..) => f.debug_tuple("MyStruct")...finish(),
225227
let pat = make::tuple_struct_pat(variant_name.clone(), pats.into_iter());
@@ -254,41 +256,42 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
254256

255257
let expr = match strukt.field_list() {
256258
// => f.debug_struct("Name").finish()
257-
None => make::expr_method_call(target, make::name_ref("debug_struct"), args),
259+
None => make::expr_method_call(target, make::name_ref("debug_struct"), args).into(),
258260

259261
// => f.debug_struct("Name").field("foo", &self.foo).finish()
260262
Some(ast::FieldList::RecordFieldList(field_list)) => {
261263
let method = make::name_ref("debug_struct");
262-
let mut expr = make::expr_method_call(target, method, args);
264+
let mut expr = make::expr_method_call(target, method, args).into();
263265
for field in field_list.fields() {
264266
let name = field.name()?;
265267
let f_name = make::expr_literal(&(format!("\"{name}\""))).into();
266268
let f_path = make::expr_path(make::ext::ident_path("self"));
267269
let f_path = make::expr_ref(f_path, false);
268270
let f_path = make::expr_field(f_path, &format!("{name}"));
269271
let args = make::arg_list([f_name, f_path]);
270-
expr = make::expr_method_call(expr, make::name_ref("field"), args);
272+
expr = make::expr_method_call(expr, make::name_ref("field"), args).into();
271273
}
272274
expr
273275
}
274276

275277
// => f.debug_tuple("Name").field(self.0).finish()
276278
Some(ast::FieldList::TupleFieldList(field_list)) => {
277279
let method = make::name_ref("debug_tuple");
278-
let mut expr = make::expr_method_call(target, method, args);
280+
let mut expr = make::expr_method_call(target, method, args).into();
279281
for (i, _) in field_list.fields().enumerate() {
280282
let f_path = make::expr_path(make::ext::ident_path("self"));
281283
let f_path = make::expr_ref(f_path, false);
282284
let f_path = make::expr_field(f_path, &format!("{i}"));
283285
let method = make::name_ref("field");
284-
expr = make::expr_method_call(expr, method, make::arg_list(Some(f_path)));
286+
expr = make::expr_method_call(expr, method, make::arg_list(Some(f_path)))
287+
.into();
285288
}
286289
expr
287290
}
288291
};
289292

290293
let method = make::name_ref("finish");
291-
let expr = make::expr_method_call(expr, method, make::arg_list(None));
294+
let expr = make::expr_method_call(expr, method, make::arg_list(None)).into();
292295
let body = make::block_expr(None, Some(expr)).indent(ast::edit::IndentLevel(1));
293296
ted::replace(func.body()?.syntax(), body.clone_for_update().syntax());
294297
Some(())
@@ -348,7 +351,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
348351
fn gen_hash_call(target: ast::Expr) -> ast::Stmt {
349352
let method = make::name_ref("hash");
350353
let arg = make::expr_path(make::ext::ident_path("state"));
351-
let expr = make::expr_method_call(target, method, make::arg_list(Some(arg)));
354+
let expr = make::expr_method_call(target, method, make::arg_list(Some(arg))).into();
352355
make::expr_stmt(expr).into()
353356
}
354357

@@ -613,7 +616,7 @@ fn gen_partial_ord(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>)
613616
fn gen_partial_cmp_call(lhs: ast::Expr, rhs: ast::Expr) -> ast::Expr {
614617
let rhs = make::expr_ref(rhs, false);
615618
let method = make::name_ref("partial_cmp");
616-
make::expr_method_call(lhs, method, make::arg_list(Some(rhs)))
619+
make::expr_method_call(lhs, method, make::arg_list(Some(rhs))).into()
617620
}
618621

619622
// Check that self type and rhs type match. We don't know how to implement the method

crates/syntax/src/ast/make.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ pub fn expr_method_call(
640640
receiver: ast::Expr,
641641
method: ast::NameRef,
642642
arg_list: ast::ArgList,
643-
) -> ast::Expr {
643+
) -> ast::MethodCallExpr {
644644
expr_from_text(&format!("{receiver}.{method}{arg_list}"))
645645
}
646646
pub fn expr_macro_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {

crates/syntax/src/ast/syntax_factory/constructors.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,8 @@ impl SyntaxFactory {
423423
method: ast::NameRef,
424424
arg_list: ast::ArgList,
425425
) -> ast::MethodCallExpr {
426-
// FIXME: `make::expr_method_call` should return a `MethodCallExpr`, not just an `Expr`
427-
let ast::Expr::MethodCallExpr(ast) =
428-
make::expr_method_call(receiver.clone(), method.clone(), arg_list.clone())
429-
.clone_for_update()
430-
else {
431-
unreachable!()
432-
};
426+
let ast = make::expr_method_call(receiver.clone(), method.clone(), arg_list.clone())
427+
.clone_for_update();
433428

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

0 commit comments

Comments
 (0)