mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
Fix indent for convert_to_guarded_return
This commit is contained in:
parent
9d58a93602
commit
f953e2fa9d
@ -218,7 +218,7 @@ fn let_stmt_to_guarded_return(
|
||||
let let_else_stmt = make::let_else_stmt(
|
||||
happy_pattern,
|
||||
let_stmt.ty(),
|
||||
expr,
|
||||
expr.reset_indent(),
|
||||
ast::make::tail_only_block_expr(early_expression),
|
||||
);
|
||||
let let_else_stmt = let_else_stmt.indent(let_indent_level);
|
||||
@ -275,11 +275,11 @@ fn flat_let_chain(mut expr: ast::Expr) -> Vec<ast::Expr> {
|
||||
&& bin_expr.op_kind() == Some(ast::BinaryOp::LogicOp(ast::LogicOp::And))
|
||||
&& let (Some(lhs), Some(rhs)) = (bin_expr.lhs(), bin_expr.rhs())
|
||||
{
|
||||
reduce_cond(rhs);
|
||||
reduce_cond(rhs.reset_indent());
|
||||
expr = lhs;
|
||||
}
|
||||
|
||||
reduce_cond(expr);
|
||||
reduce_cond(expr.reset_indent());
|
||||
chains.reverse();
|
||||
chains
|
||||
}
|
||||
@ -1019,6 +1019,63 @@ fn main() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indentations() {
|
||||
check_assist(
|
||||
convert_to_guarded_return,
|
||||
r#"
|
||||
mod indent {
|
||||
fn main() {
|
||||
$0if let None = Some(
|
||||
92
|
||||
) {
|
||||
foo(
|
||||
93
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
mod indent {
|
||||
fn main() {
|
||||
let None = Some(
|
||||
92
|
||||
) else { return };
|
||||
foo(
|
||||
93
|
||||
);
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
check_assist(
|
||||
convert_to_guarded_return,
|
||||
r#"
|
||||
//- minicore: option
|
||||
mod indent {
|
||||
fn foo(_: i32) -> Option<i32> { None }
|
||||
fn main() {
|
||||
$0let x = foo(
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
mod indent {
|
||||
fn foo(_: i32) -> Option<i32> { None }
|
||||
fn main() {
|
||||
let Some(x) = foo(
|
||||
2
|
||||
) else { return };
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignore_already_converted_if() {
|
||||
check_assist_not_applicable(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user