@@ -3157,8 +3157,7 @@ impl<'a> Parser<'a> {
3157
3157
/// Parses an `if` expression (`if` token already eaten).
3158
3158
fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3159
3159
let lo = self . prev_span ;
3160
- let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3161
- self . ungate_prev_let_expr ( & cond) ;
3160
+ let cond = self . parse_cond_expr ( ) ?;
3162
3161
3163
3162
// Verify that the parsed `if` condition makes sense as a condition. If it is a block, then
3164
3163
// verify that the last statement is either an implicit return (no `;`) or an explicit
@@ -3188,12 +3187,17 @@ impl<'a> Parser<'a> {
3188
3187
Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: If ( cond, thn, els) , attrs) )
3189
3188
}
3190
3189
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 {
3190
+ /// Parse the condition of a `if`- or `while`-expression
3191
+ fn parse_cond_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
3192
+ let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3193
+
3194
+ if let ExprKind :: Let ( ..) = cond. node {
3195
+ // Remove the last feature gating of a `let` expression since it's stable.
3194
3196
let last = self . sess . let_chains_spans . borrow_mut ( ) . pop ( ) ;
3195
- debug_assert_eq ! ( expr . span, last. unwrap( ) ) ;
3197
+ debug_assert_eq ! ( cond . span, last. unwrap( ) ) ;
3196
3198
}
3199
+
3200
+ Ok ( cond)
3197
3201
}
3198
3202
3199
3203
/// Parses a `let $pats = $expr` pseudo-expression.
@@ -3295,12 +3299,11 @@ impl<'a> Parser<'a> {
3295
3299
fn parse_while_expr ( & mut self , opt_label : Option < Label > ,
3296
3300
span_lo : Span ,
3297
3301
mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3298
- let cond = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3299
- self . ungate_prev_let_expr ( & cond) ;
3302
+ let cond = self . parse_cond_expr ( ) ?;
3300
3303
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3301
3304
attrs. extend ( iattrs) ;
3302
3305
let span = span_lo. to ( body. span ) ;
3303
- return Ok ( self . mk_expr ( span, ExprKind :: While ( cond, body, opt_label) , attrs) ) ;
3306
+ Ok ( self . mk_expr ( span, ExprKind :: While ( cond, body, opt_label) , attrs) )
3304
3307
}
3305
3308
3306
3309
// parse `loop {...}`, `loop` token already eaten
0 commit comments