@@ -3158,6 +3158,7 @@ impl<'a> Parser<'a> {
31583158 fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
31593159 let lo = self . prev_span ;
31603160 let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3161+ self . ungate_prev_let_expr ( & cond) ;
31613162
31623163 // Verify that the parsed `if` condition makes sense as a condition. If it is a block, then
31633164 // verify that the last statement is either an implicit return (no `;`) or an explicit
@@ -3187,18 +3188,27 @@ impl<'a> Parser<'a> {
31873188 Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: If ( cond, thn, els) , attrs) )
31883189 }
31893190
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+
31903199 /// Parses a `let $pats = $expr` pseudo-expression.
31913200 /// The `let` token has already been eaten.
31923201 fn parse_let_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
31933202 let lo = self . prev_span ;
31943203 let pats = self . parse_pats ( ) ?;
31953204 self . expect ( & token:: Eq ) ?;
3196-
31973205 let expr = self . with_res (
31983206 Restrictions :: NO_STRUCT_LITERAL ,
31993207 |this| this. parse_assoc_expr_with ( 1 + AssocOp :: LAnd . precedence ( ) , None . into ( ) )
32003208 ) ?;
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) )
32023212 }
32033213
32043214 /// Parses `move |args| expr`.
@@ -3286,6 +3296,7 @@ impl<'a> Parser<'a> {
32863296 span_lo : Span ,
32873297 mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
32883298 let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3299+ self . ungate_prev_let_expr ( & cond) ;
32893300 let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
32903301 attrs. extend ( iattrs) ;
32913302 let span = span_lo. to ( body. span ) ;
0 commit comments