internal: make::expr_if should return ast::IfExpr

This commit is contained in:
Giga Bowser 2024-12-14 14:31:57 -05:00
parent 913d197a04
commit c549be9ab6
7 changed files with 8 additions and 7 deletions

View file

@ -195,6 +195,7 @@ fn bool_expr_to_enum_expr(expr: ast::Expr) -> ast::Expr {
make::tail_only_block_expr(true_expr), make::tail_only_block_expr(true_expr),
Some(ast::ElseBranch::Block(make::tail_only_block_expr(false_expr))), Some(ast::ElseBranch::Block(make::tail_only_block_expr(false_expr))),
) )
.into()
} }
} }

View file

@ -60,7 +60,7 @@ pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>)
.indent(while_indent_level); .indent(while_indent_level);
let block_expr = if is_pattern_cond(while_cond.clone()) { let block_expr = if is_pattern_cond(while_cond.clone()) {
let if_expr = make::expr_if(while_cond, while_body, Some(break_block.into())); let if_expr = make::expr_if(while_cond, while_body, Some(break_block.into()));
let stmts = iter::once(make::expr_stmt(if_expr).into()); let stmts = iter::once(make::expr_stmt(if_expr.into()).into());
make::block_expr(stmts, None) make::block_expr(stmts, None)
} else { } else {
let if_cond = invert_boolean_expression(while_cond); let if_cond = invert_boolean_expression(while_cond);

View file

@ -1533,7 +1533,7 @@ impl FlowHandler {
.into(), .into(),
call_expr, call_expr,
); );
make::expr_if(condition.into(), block, None) make::expr_if(condition.into(), block, None).into()
} }
FlowHandler::IfOption { action } => { FlowHandler::IfOption { action } => {
let path = make::ext::ident_path("Some"); let path = make::ext::ident_path("Some");
@ -1544,7 +1544,7 @@ impl FlowHandler {
let action_expr = action.make_result_handler(Some(value)); let action_expr = action.make_result_handler(Some(value));
let action_stmt = make::expr_stmt(action_expr); let action_stmt = make::expr_stmt(action_expr);
let then = make::block_expr(iter::once(action_stmt.into()), None); let then = make::block_expr(iter::once(action_stmt.into()), None);
make::expr_if(cond.into(), then, None) make::expr_if(cond.into(), then, None).into()
} }
FlowHandler::MatchOption { none } => { FlowHandler::MatchOption { none } => {
let some_name = "value"; let some_name = "value";

View file

@ -61,7 +61,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext<'_>)
}; };
edit.delete(guard.syntax().text_range()); edit.delete(guard.syntax().text_range());
edit.replace_ast(arm_expr, if_expr); edit.replace_ast(arm_expr, if_expr.into());
}, },
) )
} }

View file

@ -285,7 +285,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<'
) )
.indent(IndentLevel::from_node(match_expr.syntax())); .indent(IndentLevel::from_node(match_expr.syntax()));
edit.replace_ast::<ast::Expr>(match_expr.into(), if_let_expr); edit.replace_ast::<ast::Expr>(match_expr.into(), if_let_expr.into());
}, },
) )
} }

View file

@ -63,7 +63,7 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext<'_>
let block = let block =
make::ext::empty_block_expr().indent(IndentLevel::from_node(let_stmt.syntax())); make::ext::empty_block_expr().indent(IndentLevel::from_node(let_stmt.syntax()));
let if_ = make::expr_if(make::expr_let(pat, init).into(), block, None); let if_ = make::expr_if(make::expr_let(pat, init).into(), block, None);
let stmt = make::expr_stmt(if_); let stmt = make::expr_stmt(if_.into());
edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt)); edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt));
}, },

View file

@ -607,7 +607,7 @@ pub fn expr_if(
condition: ast::Expr, condition: ast::Expr,
then_branch: ast::BlockExpr, then_branch: ast::BlockExpr,
else_branch: Option<ast::ElseBranch>, else_branch: Option<ast::ElseBranch>,
) -> ast::Expr { ) -> ast::IfExpr {
let else_branch = match else_branch { let else_branch = match else_branch {
Some(ast::ElseBranch::Block(block)) => format!("else {block}"), Some(ast::ElseBranch::Block(block)) => format!("else {block}"),
Some(ast::ElseBranch::IfExpr(if_expr)) => format!("else {if_expr}"), Some(ast::ElseBranch::IfExpr(if_expr)) => format!("else {if_expr}"),