File tree Expand file tree Collapse file tree
crates/ide-assists/src/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ fn let_stmt_to_guarded_return(
218218 let let_else_stmt = make:: let_else_stmt (
219219 happy_pattern,
220220 let_stmt. ty ( ) ,
221- expr,
221+ expr. reset_indent ( ) ,
222222 ast:: make:: tail_only_block_expr ( early_expression) ,
223223 ) ;
224224 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> {
275275 && bin_expr. op_kind ( ) == Some ( ast:: BinaryOp :: LogicOp ( ast:: LogicOp :: And ) )
276276 && let ( Some ( lhs) , Some ( rhs) ) = ( bin_expr. lhs ( ) , bin_expr. rhs ( ) )
277277 {
278- reduce_cond ( rhs) ;
278+ reduce_cond ( rhs. reset_indent ( ) ) ;
279279 expr = lhs;
280280 }
281281
282- reduce_cond ( expr) ;
282+ reduce_cond ( expr. reset_indent ( ) ) ;
283283 chains. reverse ( ) ;
284284 chains
285285}
@@ -1019,6 +1019,63 @@ fn main() {
10191019 ) ;
10201020 }
10211021
1022+ #[ test]
1023+ fn indentations ( ) {
1024+ check_assist (
1025+ convert_to_guarded_return,
1026+ r#"
1027+ mod indent {
1028+ fn main() {
1029+ $0if let None = Some(
1030+ 92
1031+ ) {
1032+ foo(
1033+ 93
1034+ );
1035+ }
1036+ }
1037+ }
1038+ "# ,
1039+ r#"
1040+ mod indent {
1041+ fn main() {
1042+ let None = Some(
1043+ 92
1044+ ) else { return };
1045+ foo(
1046+ 93
1047+ );
1048+ }
1049+ }
1050+ "# ,
1051+ ) ;
1052+
1053+ check_assist (
1054+ convert_to_guarded_return,
1055+ r#"
1056+ //- minicore: option
1057+ mod indent {
1058+ fn foo(_: i32) -> Option<i32> { None }
1059+ fn main() {
1060+ $0let x = foo(
1061+ 2
1062+ );
1063+ }
1064+ }
1065+ "# ,
1066+ r#"
1067+ mod indent {
1068+ fn foo(_: i32) -> Option<i32> { None }
1069+ fn main() {
1070+ let Some(x) = foo(
1071+ 2
1072+ ) else { return };
1073+ }
1074+ }
1075+ "# ,
1076+ ) ;
1077+ }
1078+
10221079 #[ test]
10231080 fn ignore_already_converted_if ( ) {
10241081 check_assist_not_applicable (
You can’t perform that action at this time.
0 commit comments