@@ -3420,15 +3420,15 @@ impl<'a> Parser<'a> {
34203420    fn  parse_match_arm_guard ( & mut  self )  -> PResult < ' a ,  Option < P < Expr > > >  { 
34213421        // Used to check the `let_chains` and `if_let_guard` features mostly by scanning 
34223422        // `&&` tokens. 
3423-         fn  check_let_expr ( expr :  & Expr )  -> ( bool ,   bool )  { 
3423+         fn  has_let_expr ( expr :  & Expr )  -> bool  { 
34243424            match  & expr. kind  { 
34253425                ExprKind :: Binary ( BinOp  {  node :  BinOpKind :: And ,  .. } ,  lhs,  rhs)  => { 
3426-                     let  lhs_rslt = check_let_expr ( lhs) ; 
3427-                     let  rhs_rslt = check_let_expr ( rhs) ; 
3428-                     ( lhs_rslt. 0  || rhs_rslt. 0 ,   false ) 
3426+                     let  lhs_rslt = has_let_expr ( lhs) ; 
3427+                     let  rhs_rslt = has_let_expr ( rhs) ; 
3428+                     lhs_rslt || rhs_rslt
34293429                } 
3430-                 ExprKind :: Let ( ..)  => ( true ,   true ) , 
3431-                 _ => ( false ,   true ) , 
3430+                 ExprKind :: Let ( ..)  => true , 
3431+                 _ => false , 
34323432            } 
34333433        } 
34343434        if  !self . eat_keyword ( exp ! ( If ) )  { 
@@ -3441,12 +3441,21 @@ impl<'a> Parser<'a> {
34413441
34423442        CondChecker :: new ( self ) . visit_expr ( & mut  cond) ; 
34433443
3444-         let  ( has_let_expr,  does_not_have_bin_op)  = check_let_expr ( & cond) ; 
3445-         if  has_let_expr { 
3446-             if  does_not_have_bin_op { 
3447-                 // Remove the last feature gating of a `let` expression since it's stable. 
3448-                 self . psess . gated_spans . ungate_last ( sym:: let_chains,  cond. span ) ; 
3444+         if  has_let_expr ( & cond)  { 
3445+             // Let chains are allowed in match guards, but only there 
3446+             fn  ungate_let_exprs ( this :  & mut  Parser < ' _ > ,  expr :  & Expr )  { 
3447+                 match  & expr. kind  { 
3448+                     ExprKind :: Binary ( BinOp  {  node :  BinOpKind :: And ,  .. } ,  lhs,  rhs)  => { 
3449+                         ungate_let_exprs ( this,  rhs) ; 
3450+                         ungate_let_exprs ( this,  lhs) ; 
3451+                     } 
3452+                     ExprKind :: Let ( ..)  => { 
3453+                         this. psess . gated_spans . ungate_last ( sym:: let_chains,  expr. span ) 
3454+                     } 
3455+                     _ => ( ) , 
3456+                 } 
34493457            } 
3458+             ungate_let_exprs ( self ,  & cond) ; 
34503459            let  span = if_span. to ( cond. span ) ; 
34513460            self . psess . gated_spans . gate ( sym:: if_let_guard,  span) ; 
34523461        } 
0 commit comments