File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +29
-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> {
259259 && bin_expr. op_kind ( ) == Some ( ast:: BinaryOp :: LogicOp ( ast:: LogicOp :: And ) )
260260 && let ( Some ( lhs) , Some ( rhs) ) = ( bin_expr. lhs ( ) , bin_expr. rhs ( ) )
261261 {
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+ {
263265 chains. push ( make:: expr_bin_op ( rhs, ast:: BinaryOp :: LogicOp ( ast:: LogicOp :: And ) , last) ) ;
264266 } else {
265267 chains. push ( rhs) ;
@@ -493,6 +495,32 @@ fn main() {
493495 let Some(y) = Some(8) else { return };
494496 foo(x, y);
495497}
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 {
519+ return;
520+ }
521+ let Some(y) = Some(8) else { return };
522+ foo(x, y);
523+ }
496524"# ,
497525 ) ;
498526 }
You can’t perform that action at this time.
0 commit comments