Skip to content

Commit dc70a78

Browse files
authored
Merge pull request #19569 from snprajwal/fixmes
fix(ast): return correct types for `make::expr_*` methods
2 parents 909d210 + 688464d commit dc70a78

15 files changed

+79
-75
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ pub(crate) fn convert_for_loop_to_while_let(
6060
{
6161
(expr, Some(make.name_ref(method.as_str())))
6262
} else if let ast::Expr::RefExpr(_) = iterable {
63-
(make::expr_paren(iterable), Some(make.name_ref("into_iter")))
63+
(make::expr_paren(iterable).into(), Some(make.name_ref("into_iter")))
6464
} else {
6565
(iterable, Some(make.name_ref("into_iter")))
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/convert_from_to_tryfrom.rs

+1
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)]

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,10 @@ 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)));
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())

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/handlers/generate_delegate_trait.rs

+1-1
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()?,

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

+1-1
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
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ fn inline(
512512
&& usage.syntax().parent().and_then(ast::Expr::cast).is_some() =>
513513
{
514514
cov_mark::hit!(inline_call_inline_closure);
515-
let expr = make::expr_paren(expr.clone());
515+
let expr = make::expr_paren(expr.clone()).into();
516516
inline_direct(usage, &expr);
517517
}
518518
// inline single use literals
@@ -567,7 +567,7 @@ fn inline(
567567
let no_stmts = body.statements().next().is_none();
568568
match body.tail_expr() {
569569
Some(expr) if matches!(expr, ast::Expr::ClosureExpr(_)) && no_stmts => {
570-
make::expr_paren(expr).clone_for_update()
570+
make::expr_paren(expr).clone_for_update().into()
571571
}
572572
Some(expr) if !is_async_fn && no_stmts => expr,
573573
_ => match node
@@ -577,7 +577,7 @@ fn inline(
577577
.and_then(|bin_expr| bin_expr.lhs())
578578
{
579579
Some(lhs) if lhs.syntax() == node.syntax() => {
580-
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update()
580+
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update().into()
581581
}
582582
_ => ast::Expr::BlockExpr(body),
583583
},

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
146146
None => false,
147147
};
148148
let expr = replace_nested_dbgs(expr.clone());
149-
let expr = if wrap { make::expr_paren(expr) } else { expr.clone_subtree() };
149+
let expr = if wrap { make::expr_paren(expr).into() } else { expr.clone_subtree() };
150150
(macro_call.syntax().text_range(), Some(expr))
151151
}
152152
// dbg!(expr0, expr1, ...)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn into_closure(param: &Expr) -> Expr {
7979
None
8080
}
8181
})()
82-
.unwrap_or_else(|| make::expr_closure(None, param.clone()))
82+
.unwrap_or_else(|| make::expr_closure(None, param.clone()).into())
8383
}
8484

8585
// Assist: replace_with_eager_method
@@ -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)]

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

+7-4
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(

crates/ide-assists/src/utils.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
330330
T![>] => T![<=],
331331
T![>=] => T![<],
332332
// Parenthesize other expressions before prefixing `!`
333-
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone())).into()),
333+
_ => {
334+
return Some(
335+
make::expr_prefix(T![!], make::expr_paren(expr.clone()).into()).into(),
336+
);
337+
}
334338
};
335339
ted::replace(op_token, make::token(rev_token));
336340
Some(bin.into())
@@ -347,7 +351,7 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
347351
"is_err" => "is_ok",
348352
_ => return None,
349353
};
350-
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())
351355
}
352356
ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => match pe.expr()? {
353357
ast::Expr::ParenExpr(parexpr) => parexpr.expr(),
@@ -852,6 +856,7 @@ impl ReferenceConversion {
852856
make::expr_ref(expr, false)
853857
} else {
854858
make::expr_method_call(expr, make::name_ref("as_ref"), make::arg_list([]))
859+
.into()
855860
}
856861
}
857862
}

0 commit comments

Comments
 (0)