@@ -3291,15 +3291,15 @@ impl<'a> Parser<'a> {
3291
3291
fn parse_match_arm_guard ( & mut self ) -> PResult < ' a , Option < P < Expr > > > {
3292
3292
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
3293
3293
// `&&` tokens.
3294
- fn check_let_expr ( expr : & Expr ) -> ( bool , bool ) {
3294
+ fn has_let_expr ( expr : & Expr ) -> bool {
3295
3295
match & expr. kind {
3296
3296
ExprKind :: Binary ( BinOp { node : BinOpKind :: And , .. } , lhs, rhs) => {
3297
- let lhs_rslt = check_let_expr ( lhs) ;
3298
- let rhs_rslt = check_let_expr ( rhs) ;
3299
- ( lhs_rslt. 0 || rhs_rslt. 0 , false )
3297
+ let lhs_rslt = has_let_expr ( lhs) ;
3298
+ let rhs_rslt = has_let_expr ( rhs) ;
3299
+ lhs_rslt || rhs_rslt
3300
3300
}
3301
- ExprKind :: Let ( ..) => ( true , true ) ,
3302
- _ => ( false , true ) ,
3301
+ ExprKind :: Let ( ..) => true ,
3302
+ _ => false ,
3303
3303
}
3304
3304
}
3305
3305
if !self . eat_keyword ( exp ! ( If ) ) {
@@ -3312,12 +3312,21 @@ impl<'a> Parser<'a> {
3312
3312
3313
3313
CondChecker :: new ( self ) . visit_expr ( & mut cond) ;
3314
3314
3315
- let ( has_let_expr, does_not_have_bin_op) = check_let_expr ( & cond) ;
3316
- if has_let_expr {
3317
- if does_not_have_bin_op {
3318
- // Remove the last feature gating of a `let` expression since it's stable.
3319
- self . psess . gated_spans . ungate_last ( sym:: let_chains, cond. span ) ;
3315
+ if has_let_expr ( & cond) {
3316
+ // Let chains are allowed in match guards, but only there
3317
+ fn ungate_let_exprs ( this : & mut Parser < ' _ > , expr : & Expr ) {
3318
+ match & expr. kind {
3319
+ ExprKind :: Binary ( BinOp { node : BinOpKind :: And , .. } , lhs, rhs) => {
3320
+ ungate_let_exprs ( this, rhs) ;
3321
+ ungate_let_exprs ( this, lhs) ;
3322
+ }
3323
+ ExprKind :: Let ( ..) => {
3324
+ this. psess . gated_spans . ungate_last ( sym:: let_chains, expr. span )
3325
+ }
3326
+ _ => ( ) ,
3327
+ }
3320
3328
}
3329
+ ungate_let_exprs ( self , & cond) ;
3321
3330
let span = if_span. to ( cond. span ) ;
3322
3331
self . psess . gated_spans . gate ( sym:: if_let_guard, span) ;
3323
3332
}
0 commit comments