@@ -3431,15 +3431,15 @@ impl<'a> Parser<'a> {
3431
3431
fn parse_match_arm_guard ( & mut self ) -> PResult < ' a , Option < P < Expr > > > {
3432
3432
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
3433
3433
// `&&` tokens.
3434
- fn check_let_expr ( expr : & Expr ) -> ( bool , bool ) {
3434
+ fn has_let_expr ( expr : & Expr ) -> bool {
3435
3435
match & expr. kind {
3436
3436
ExprKind :: Binary ( BinOp { node : BinOpKind :: And , .. } , lhs, rhs) => {
3437
- let lhs_rslt = check_let_expr ( lhs) ;
3438
- let rhs_rslt = check_let_expr ( rhs) ;
3439
- ( lhs_rslt. 0 || rhs_rslt. 0 , false )
3437
+ let lhs_rslt = has_let_expr ( lhs) ;
3438
+ let rhs_rslt = has_let_expr ( rhs) ;
3439
+ lhs_rslt || rhs_rslt
3440
3440
}
3441
- ExprKind :: Let ( ..) => ( true , true ) ,
3442
- _ => ( false , true ) ,
3441
+ ExprKind :: Let ( ..) => true ,
3442
+ _ => false ,
3443
3443
}
3444
3444
}
3445
3445
if !self . eat_keyword ( exp ! ( If ) ) {
@@ -3452,12 +3452,21 @@ impl<'a> Parser<'a> {
3452
3452
3453
3453
CondChecker :: new ( self ) . visit_expr ( & mut cond) ;
3454
3454
3455
- let ( has_let_expr, does_not_have_bin_op) = check_let_expr ( & cond) ;
3456
- if has_let_expr {
3457
- if does_not_have_bin_op {
3458
- // Remove the last feature gating of a `let` expression since it's stable.
3459
- self . psess . gated_spans . ungate_last ( sym:: let_chains, cond. span ) ;
3455
+ if has_let_expr ( & cond) {
3456
+ // Let chains are allowed in match guards, but only there
3457
+ fn ungate_let_exprs ( this : & mut Parser < ' _ > , expr : & Expr ) {
3458
+ match & expr. kind {
3459
+ ExprKind :: Binary ( BinOp { node : BinOpKind :: And , .. } , lhs, rhs) => {
3460
+ ungate_let_exprs ( this, rhs) ;
3461
+ ungate_let_exprs ( this, lhs) ;
3462
+ }
3463
+ ExprKind :: Let ( ..) => {
3464
+ this. psess . gated_spans . ungate_last ( sym:: let_chains, expr. span )
3465
+ }
3466
+ _ => ( ) ,
3467
+ }
3460
3468
}
3469
+ ungate_let_exprs ( self , & cond) ;
3461
3470
let span = if_span. to ( cond. span ) ;
3462
3471
self . psess . gated_spans . gate ( sym:: if_let_guard, span) ;
3463
3472
}
0 commit comments