@@ -3420,15 +3420,15 @@ impl<'a> Parser<'a> {
3420
3420
fn parse_match_arm_guard ( & mut self ) -> PResult < ' a , Option < P < Expr > > > {
3421
3421
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
3422
3422
// `&&` tokens.
3423
- fn check_let_expr ( expr : & Expr ) -> ( bool , bool ) {
3423
+ fn has_let_expr ( expr : & Expr ) -> bool {
3424
3424
match & expr. kind {
3425
3425
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
3429
3429
}
3430
- ExprKind :: Let ( ..) => ( true , true ) ,
3431
- _ => ( false , true ) ,
3430
+ ExprKind :: Let ( ..) => true ,
3431
+ _ => false ,
3432
3432
}
3433
3433
}
3434
3434
if !self . eat_keyword ( exp ! ( If ) ) {
@@ -3441,12 +3441,21 @@ impl<'a> Parser<'a> {
3441
3441
3442
3442
CondChecker :: new ( self ) . visit_expr ( & mut cond) ;
3443
3443
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
+ }
3449
3457
}
3458
+ ungate_let_exprs ( self , & cond) ;
3450
3459
let span = if_span. to ( cond. span ) ;
3451
3460
self . psess . gated_spans . gate ( sym:: if_let_guard, span) ;
3452
3461
}
0 commit comments