@@ -2251,7 +2251,15 @@ impl<'a> Parser<'a> {
2251
2251
2252
2252
/// Parses the condition of a `if` or `while` expression.
2253
2253
fn parse_cond_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
2254
- self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL | Restrictions :: ALLOW_LET , None )
2254
+ let cond =
2255
+ self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL | Restrictions :: ALLOW_LET , None ) ?;
2256
+
2257
+ if let ExprKind :: Let ( ..) = cond. kind {
2258
+ // Remove the last feature gating of a `let` expression since it's stable.
2259
+ self . sess . gated_spans . ungate_last ( sym:: let_chains, cond. span ) ;
2260
+ }
2261
+
2262
+ Ok ( cond)
2255
2263
}
2256
2264
2257
2265
/// Parses a `let $pat = $expr` pseudo-expression.
@@ -2280,6 +2288,7 @@ impl<'a> Parser<'a> {
2280
2288
this. parse_assoc_expr_with ( 1 + prec_let_scrutinee_needs_par ( ) , None . into ( ) )
2281
2289
} ) ?;
2282
2290
let span = lo. to ( expr. span ) ;
2291
+ self . sess . gated_spans . gate ( sym:: let_chains, span) ;
2283
2292
Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span) ) )
2284
2293
}
2285
2294
@@ -2571,13 +2580,15 @@ impl<'a> Parser<'a> {
2571
2580
pub ( super ) fn parse_arm ( & mut self ) -> PResult < ' a , Arm > {
2572
2581
// Used to check the `let_chains` and `if_let_guard` features mostly by scaning
2573
2582
// `&&` tokens.
2574
- fn check_let_expr ( expr : & Expr ) -> bool {
2583
+ fn check_let_expr ( expr : & Expr ) -> ( bool , bool ) {
2575
2584
match expr. kind {
2576
2585
ExprKind :: Binary ( BinOp { node : BinOpKind :: And , .. } , ref lhs, ref rhs) => {
2577
- check_let_expr ( lhs) || check_let_expr ( rhs)
2586
+ let lhs_rslt = check_let_expr ( lhs) ;
2587
+ let rhs_rslt = check_let_expr ( rhs) ;
2588
+ ( lhs_rslt. 0 || rhs_rslt. 0 , false )
2578
2589
}
2579
- ExprKind :: Let ( ..) => true ,
2580
- _ => false ,
2590
+ ExprKind :: Let ( ..) => ( true , true ) ,
2591
+ _ => ( false , true ) ,
2581
2592
}
2582
2593
}
2583
2594
let attrs = self . parse_outer_attributes ( ) ?;
@@ -2592,7 +2603,12 @@ impl<'a> Parser<'a> {
2592
2603
let guard = if this. eat_keyword ( kw:: If ) {
2593
2604
let if_span = this. prev_token . span ;
2594
2605
let cond = this. parse_expr_res ( Restrictions :: ALLOW_LET , None ) ?;
2595
- if check_let_expr ( & cond) {
2606
+ let ( has_let_expr, does_not_have_bin_op) = check_let_expr ( & cond) ;
2607
+ if has_let_expr {
2608
+ if does_not_have_bin_op {
2609
+ // Remove the last feature gating of a `let` expression since it's stable.
2610
+ this. sess . gated_spans . ungate_last ( sym:: let_chains, cond. span ) ;
2611
+ }
2596
2612
let span = if_span. to ( cond. span ) ;
2597
2613
this. sess . gated_spans . gate ( sym:: if_let_guard, span) ;
2598
2614
}
0 commit comments