@@ -33,9 +33,9 @@ pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'
3333 let let_stmt = LetStmt :: cast ( let_stmt) ?;
3434 let else_block = let_stmt. let_else ( ) ?. block_expr ( ) ?;
3535 let else_expr = if else_block. statements ( ) . next ( ) . is_none ( ) {
36- else_block. tail_expr ( ) ?
36+ else_block. tail_expr ( ) ?. reset_indent ( )
3737 } else {
38- else_block. into ( )
38+ else_block. reset_indent ( ) . into ( )
3939 } ;
4040 let init = let_stmt. initializer ( ) ?;
4141 // Ignore let stmt with type annotation
@@ -91,8 +91,8 @@ pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'
9191 } ,
9292 ) ;
9393 let else_arm = make. match_arm ( make. wildcard_pat ( ) . into ( ) , None , else_expr) ;
94- let match_ = make . expr_match ( init , make . match_arm_list ( [ binding_arm, else_arm] ) ) ;
95- let match_ = match_ . reset_indent ( ) ;
94+ let arms = [ binding_arm, else_arm] . map ( |arm| arm . indent ( 1 . into ( ) ) ) ;
95+ let match_ = make . expr_match ( init , make . match_arm_list ( arms ) ) ;
9696 let match_ = match_. indent ( let_stmt. indent_level ( ) ) ;
9797
9898 if bindings. is_empty ( ) {
@@ -298,6 +298,63 @@ fn main() {
298298 ) ;
299299 }
300300
301+ #[ test]
302+ fn convert_let_else_to_match_with_some_indent ( ) {
303+ check_assist (
304+ convert_let_else_to_match,
305+ r#"
306+ mod indent {
307+ fn main() {
308+ let Ok(x) = f() else$0 {
309+ log();
310+ unreachable!(
311+ "..."
312+ );
313+ };
314+ }
315+ }"# ,
316+ r#"
317+ mod indent {
318+ fn main() {
319+ let x = match f() {
320+ Ok(x) => x,
321+ _ => {
322+ log();
323+ unreachable!(
324+ "..."
325+ );
326+ }
327+ };
328+ }
329+ }"# ,
330+ ) ;
331+
332+ check_assist (
333+ convert_let_else_to_match,
334+ r#"
335+ mod indent {
336+ fn main() {
337+ let Ok(x) = f() else$0 {
338+ unreachable!(
339+ "..."
340+ )
341+ };
342+ }
343+ }"# ,
344+ r#"
345+ mod indent {
346+ fn main() {
347+ let x = match f() {
348+ Ok(x) => x,
349+ _ => unreachable!(
350+ "..."
351+ ),
352+ };
353+ }
354+ }"# ,
355+ ) ;
356+ }
357+
301358 #[ test]
302359 fn convert_let_else_to_match_const_ref ( ) {
303360 check_assist (
0 commit comments