@@ -3158,6 +3158,7 @@ impl<'a> Parser<'a> {
3158
3158
fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3159
3159
let lo = self . prev_span ;
3160
3160
let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3161
+ self . ungate_prev_let_expr ( & cond) ;
3161
3162
3162
3163
// Verify that the parsed `if` condition makes sense as a condition. If it is a block, then
3163
3164
// verify that the last statement is either an implicit return (no `;`) or an explicit
@@ -3187,18 +3188,27 @@ impl<'a> Parser<'a> {
3187
3188
Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: If ( cond, thn, els) , attrs) )
3188
3189
}
3189
3190
3191
+ /// Remove the last feature gating of a `let` expression that must the one provided.
3192
+ fn ungate_prev_let_expr ( & mut self , expr : & Expr ) {
3193
+ if let ExprKind :: Let ( ..) = expr. node {
3194
+ let last = self . sess . let_chains_spans . borrow_mut ( ) . pop ( ) ;
3195
+ debug_assert_eq ! ( expr. span, last. unwrap( ) ) ;
3196
+ }
3197
+ }
3198
+
3190
3199
/// Parses a `let $pats = $expr` pseudo-expression.
3191
3200
/// The `let` token has already been eaten.
3192
3201
fn parse_let_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3193
3202
let lo = self . prev_span ;
3194
3203
let pats = self . parse_pats ( ) ?;
3195
3204
self . expect ( & token:: Eq ) ?;
3196
-
3197
3205
let expr = self . with_res (
3198
3206
Restrictions :: NO_STRUCT_LITERAL ,
3199
3207
|this| this. parse_assoc_expr_with ( 1 + AssocOp :: LAnd . precedence ( ) , None . into ( ) )
3200
3208
) ?;
3201
- Ok ( self . mk_expr ( lo. to ( expr. span ) , ExprKind :: Let ( pats, expr) , attrs) )
3209
+ let span = lo. to ( expr. span ) ;
3210
+ self . sess . let_chains_spans . borrow_mut ( ) . push ( span) ;
3211
+ Ok ( self . mk_expr ( span, ExprKind :: Let ( pats, expr) , attrs) )
3202
3212
}
3203
3213
3204
3214
/// Parses `move |args| expr`.
@@ -3286,6 +3296,7 @@ impl<'a> Parser<'a> {
3286
3296
span_lo : Span ,
3287
3297
mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3288
3298
let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3299
+ self . ungate_prev_let_expr ( & cond) ;
3289
3300
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3290
3301
attrs. extend ( iattrs) ;
3291
3302
let span = span_lo. to ( body. span ) ;
0 commit comments