mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
fix: make::expr_call() -> CallExpr
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
This commit is contained in:
parent
ab620e367d
commit
688464d5e6
9 changed files with 33 additions and 29 deletions
|
|
@ -128,6 +128,7 @@ fn wrap_ok(expr: ast::Expr) -> ast::Expr {
|
||||||
make::expr_path(make::ext::ident_path("Ok")),
|
make::expr_path(make::ext::ident_path("Ok")),
|
||||||
make::arg_list(std::iter::once(expr)),
|
make::arg_list(std::iter::once(expr)),
|
||||||
)
|
)
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -1429,7 +1429,7 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> Sy
|
||||||
make::expr_method_call(self_arg, name, args).into()
|
make::expr_method_call(self_arg, name, args).into()
|
||||||
} else {
|
} else {
|
||||||
let func = make::expr_path(make::path_unqualified(make::path_segment(name)));
|
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);
|
let handler = FlowHandler::from_ret_ty(fun, &ret_ty);
|
||||||
|
|
@ -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 func = make::expr_path(make::ext::ident_path(constructor));
|
||||||
let args = make::arg_list(iter::once(tail_expr));
|
let args = make::arg_list(iter::once(tail_expr));
|
||||||
make::expr_call(func, args)
|
make::expr_call(func, args).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
FlowHandler::If { .. } => {
|
FlowHandler::If { .. } => {
|
||||||
let controlflow_continue = make::expr_call(
|
let controlflow_continue = make::expr_call(
|
||||||
make::expr_path(make::path_from_text("ControlFlow::Continue")),
|
make::expr_path(make::path_from_text("ControlFlow::Continue")),
|
||||||
make::arg_list([make::ext::expr_unit()]),
|
make::arg_list([make::ext::expr_unit()]),
|
||||||
);
|
)
|
||||||
|
.into();
|
||||||
with_tail_expr(block, controlflow_continue)
|
with_tail_expr(block, controlflow_continue)
|
||||||
}
|
}
|
||||||
FlowHandler::IfOption { .. } => {
|
FlowHandler::IfOption { .. } => {
|
||||||
|
|
@ -1928,12 +1929,12 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
|
||||||
FlowHandler::MatchOption { .. } => map_tail_expr(block, |tail_expr| {
|
FlowHandler::MatchOption { .. } => map_tail_expr(block, |tail_expr| {
|
||||||
let some = make::expr_path(make::ext::ident_path("Some"));
|
let some = make::expr_path(make::ext::ident_path("Some"));
|
||||||
let args = make::arg_list(iter::once(tail_expr));
|
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| {
|
FlowHandler::MatchResult { .. } => map_tail_expr(block, |tail_expr| {
|
||||||
let ok = make::expr_path(make::ext::ident_path("Ok"));
|
let ok = make::expr_path(make::ext::ident_path("Ok"));
|
||||||
let args = make::arg_list(iter::once(tail_expr));
|
let args = make::arg_list(iter::once(tail_expr));
|
||||||
make::expr_call(ok, args)
|
make::expr_call(ok, args).into()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2121,17 +2122,18 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
|
||||||
FlowHandler::If { .. } => make::expr_call(
|
FlowHandler::If { .. } => make::expr_call(
|
||||||
make::expr_path(make::path_from_text("ControlFlow::Break")),
|
make::expr_path(make::path_from_text("ControlFlow::Break")),
|
||||||
make::arg_list([make::ext::expr_unit()]),
|
make::arg_list([make::ext::expr_unit()]),
|
||||||
),
|
)
|
||||||
|
.into(),
|
||||||
FlowHandler::IfOption { .. } => {
|
FlowHandler::IfOption { .. } => {
|
||||||
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
||||||
let args = make::arg_list([expr]);
|
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::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
|
||||||
FlowHandler::MatchResult { .. } => {
|
FlowHandler::MatchResult { .. } => {
|
||||||
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
||||||
let args = make::arg_list([expr]);
|
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())
|
Some(make::expr_return(Some(value)).clone_for_update())
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,7 @@ fn func_assoc_item(
|
||||||
}
|
}
|
||||||
.clone_for_update();
|
.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_(
|
let func = make::fn_(
|
||||||
item.visibility(),
|
item.visibility(),
|
||||||
item.name()?,
|
item.name()?,
|
||||||
|
|
|
||||||
|
|
@ -475,7 +475,7 @@ fn make_fn_body_as_new_function(
|
||||||
.map(|_| placeholder_expr.clone())
|
.map(|_| placeholder_expr.clone())
|
||||||
.collect::<Vec<_>>();
|
.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),
|
StructKind::Unit => make::expr_path(path_self),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ fn into_call(param: &Expr) -> Expr {
|
||||||
None
|
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)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,13 @@ pub(crate) fn replace_try_expr_with_match(
|
||||||
TryEnum::Option => {
|
TryEnum::Option => {
|
||||||
make::expr_return(Some(make::expr_path(make::ext::ident_path("None"))))
|
make::expr_return(Some(make::expr_path(make::ext::ident_path("None"))))
|
||||||
}
|
}
|
||||||
TryEnum::Result => make::expr_return(Some(make::expr_call(
|
TryEnum::Result => make::expr_return(Some(
|
||||||
make::expr_path(make::ext::ident_path("Err")),
|
make::expr_call(
|
||||||
make::arg_list(iter::once(make::expr_path(make::ext::ident_path("err")))),
|
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(
|
let happy_arm = make::match_arm(
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,8 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
||||||
}
|
}
|
||||||
let pat = make::tuple_struct_pat(variant_name.clone(), pats.into_iter());
|
let pat = make::tuple_struct_pat(variant_name.clone(), pats.into_iter());
|
||||||
let struct_name = make::expr_path(variant_name);
|
let struct_name = make::expr_path(variant_name);
|
||||||
let tuple_expr = make::expr_call(struct_name, make::arg_list(fields));
|
let tuple_expr =
|
||||||
|
make::expr_call(struct_name, make::arg_list(fields)).into();
|
||||||
arms.push(make::match_arm(pat.into(), None, tuple_expr));
|
arms.push(make::match_arm(pat.into(), None, tuple_expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +127,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
||||||
fields.push(gen_clone_call(target));
|
fields.push(gen_clone_call(target));
|
||||||
}
|
}
|
||||||
let struct_name = make::expr_path(make::ext::ident_path("Self"));
|
let struct_name = make::expr_path(make::ext::ident_path("Self"));
|
||||||
make::expr_call(struct_name, make::arg_list(fields))
|
make::expr_call(struct_name, make::arg_list(fields)).into()
|
||||||
}
|
}
|
||||||
// => Self { }
|
// => Self { }
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -303,7 +304,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
||||||
fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
||||||
fn gen_default_call() -> Option<ast::Expr> {
|
fn gen_default_call() -> Option<ast::Expr> {
|
||||||
let fn_name = make::ext::path_from_idents(["Default", "default"])?;
|
let fn_name = make::ext::path_from_idents(["Default", "default"])?;
|
||||||
Some(make::expr_call(make::expr_path(fn_name), make::arg_list(None)))
|
Some(make::expr_call(make::expr_path(fn_name), make::arg_list(None)).into())
|
||||||
}
|
}
|
||||||
match adt {
|
match adt {
|
||||||
// `Debug` cannot be derived for unions, so no default impl can be provided.
|
// `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<()> {
|
||||||
.fields()
|
.fields()
|
||||||
.map(|_| gen_default_call())
|
.map(|_| gen_default_call())
|
||||||
.collect::<Option<Vec<ast::Expr>>>()?;
|
.collect::<Option<Vec<ast::Expr>>>()?;
|
||||||
make::expr_call(struct_name, make::arg_list(fields))
|
make::expr_call(struct_name, make::arg_list(fields)).into()
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let struct_name = make::ext::ident_path("Self");
|
let struct_name = make::ext::ident_path("Self");
|
||||||
|
|
@ -364,7 +365,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
|
||||||
let fn_name = make_discriminant()?;
|
let fn_name = make_discriminant()?;
|
||||||
|
|
||||||
let arg = make::expr_path(make::ext::ident_path("self"));
|
let arg = make::expr_path(make::ext::ident_path("self"));
|
||||||
let fn_call = make::expr_call(fn_name, make::arg_list(Some(arg)));
|
let fn_call = make::expr_call(fn_name, make::arg_list(Some(arg))).into();
|
||||||
let stmt = gen_hash_call(fn_call);
|
let stmt = gen_hash_call(fn_call);
|
||||||
|
|
||||||
make::block_expr(Some(stmt), None).indent(ast::edit::IndentLevel(1))
|
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>) -
|
||||||
ast::Adt::Enum(enum_) => {
|
ast::Adt::Enum(enum_) => {
|
||||||
// => std::mem::discriminant(self) == std::mem::discriminant(other)
|
// => std::mem::discriminant(self) == std::mem::discriminant(other)
|
||||||
let lhs_name = make::expr_path(make::ext::ident_path("self"));
|
let lhs_name = make::expr_path(make::ext::ident_path("self"));
|
||||||
let lhs = make::expr_call(make_discriminant()?, make::arg_list(Some(lhs_name.clone())));
|
let lhs = make::expr_call(make_discriminant()?, make::arg_list(Some(lhs_name.clone())))
|
||||||
|
.into();
|
||||||
let rhs_name = make::expr_path(make::ext::ident_path("other"));
|
let rhs_name = make::expr_path(make::ext::ident_path("other"));
|
||||||
let rhs = make::expr_call(make_discriminant()?, make::arg_list(Some(rhs_name.clone())));
|
let rhs = make::expr_call(make_discriminant()?, make::arg_list(Some(rhs_name.clone())))
|
||||||
|
.into();
|
||||||
let eq_check =
|
let eq_check =
|
||||||
make::expr_bin_op(lhs, BinaryOp::CmpOp(CmpOp::Eq { negated: false }), rhs);
|
make::expr_bin_op(lhs, BinaryOp::CmpOp(CmpOp::Eq { negated: false }), rhs);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -633,7 +633,7 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::PrefixExpr {
|
||||||
let token = token(op);
|
let token = token(op);
|
||||||
expr_from_text(&format!("{token}{expr}"))
|
expr_from_text(&format!("{token}{expr}"))
|
||||||
}
|
}
|
||||||
pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
|
pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::CallExpr {
|
||||||
expr_from_text(&format!("{f}{arg_list}"))
|
expr_from_text(&format!("{f}{arg_list}"))
|
||||||
}
|
}
|
||||||
pub fn expr_method_call(
|
pub fn expr_method_call(
|
||||||
|
|
|
||||||
|
|
@ -400,12 +400,7 @@ impl SyntaxFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expr_call(&self, expr: ast::Expr, arg_list: ast::ArgList) -> ast::CallExpr {
|
pub fn expr_call(&self, expr: ast::Expr, arg_list: ast::ArgList) -> ast::CallExpr {
|
||||||
// FIXME: `make::expr_call`` should return a `CallExpr`, not just an `Expr`
|
let ast = make::expr_call(expr.clone(), arg_list.clone()).clone_for_update();
|
||||||
let ast::Expr::CallExpr(ast) =
|
|
||||||
make::expr_call(expr.clone(), arg_list.clone()).clone_for_update()
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(mut mapping) = self.mappings() {
|
if let Some(mut mapping) = self.mappings() {
|
||||||
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
|
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue