File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -259,7 +259,9 @@ fn flat_let_chain(mut expr: ast::Expr) -> Vec<ast::Expr> {
259
259
&& bin_expr. op_kind ( ) == Some ( ast:: BinaryOp :: LogicOp ( ast:: LogicOp :: And ) )
260
260
&& let ( Some ( lhs) , Some ( rhs) ) = ( bin_expr. lhs ( ) , bin_expr. rhs ( ) )
261
261
{
262
- if let Some ( last) = chains. pop_if ( |last| !matches ! ( last, ast:: Expr :: LetExpr ( _) ) ) {
262
+ if !matches ! ( rhs, ast:: Expr :: LetExpr ( _) )
263
+ && let Some ( last) = chains. pop_if ( |last| !matches ! ( last, ast:: Expr :: LetExpr ( _) ) )
264
+ {
263
265
chains. push ( make:: expr_bin_op ( rhs, ast:: BinaryOp :: LogicOp ( ast:: LogicOp :: And ) , last) ) ;
264
266
} else {
265
267
chains. push ( rhs) ;
@@ -493,6 +495,30 @@ fn main() {
493
495
let Some(y) = Some(8) else { return };
494
496
foo(x, y);
495
497
}
498
+ "# ,
499
+ ) ;
500
+
501
+ check_assist (
502
+ convert_to_guarded_return,
503
+ r#"
504
+ fn main() {
505
+ if$0 let Ok(x) = Err(92)
506
+ && let Ok(y) = Ok(37)
507
+ && x < 30
508
+ && let Some(y) = Some(8)
509
+ {
510
+ foo(x, y);
511
+ }
512
+ }
513
+ "# ,
514
+ r#"
515
+ fn main() {
516
+ let Ok(x) = Err(92) else { return };
517
+ let Ok(y) = Ok(37) else { return };
518
+ if x >= 30 { return }
519
+ let Some(y) = Some(8) else { return };
520
+ foo(x, y);
521
+ }
496
522
"# ,
497
523
) ;
498
524
}
You can’t perform that action at this time.
0 commit comments