You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compiler/rustc_parse/src/parser/expr.rs
+54-29
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,7 @@ use rustc_macros::Subdiagnostic;
26
26
use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error};
27
27
use rustc_session::lint::BuiltinLintDiag;
28
28
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
29
+
use rustc_span::edition::Edition;
29
30
use rustc_span::source_map::{self,Spanned};
30
31
use rustc_span::{BytePos,ErrorGuaranteed,Ident,Pos,Span,Symbol, kw, sym};
31
32
use thin_vec::{ThinVec, thin_vec};
@@ -2602,7 +2603,10 @@ impl<'a> Parser<'a> {
2602
2603
/// Parses an `if` expression (`if` token already eaten).
2603
2604
fnparse_expr_if(&mutself) -> PResult<'a,P<Expr>>{
2604
2605
let lo = self.prev_token.span;
2605
-
let cond = self.parse_expr_cond()?;
2606
+
// Scoping code checks the top level edition of the `if`; let's match it here.
2607
+
// The `CondChecker` also checks the edition of the `let` itself, just to make sure.
2608
+
let let_chains_policy = LetChainsPolicy::EditionDependent{current_edition: lo.edition()};
2609
+
let cond = self.parse_expr_cond(let_chains_policy)?;
2606
2610
self.parse_if_after_cond(lo, cond)
2607
2611
}
2608
2612
@@ -2711,18 +2715,17 @@ impl<'a> Parser<'a> {
2711
2715
}
2712
2716
2713
2717
/// Parses the condition of a `if` or `while` expression.
2718
+
///
2719
+
/// The specified `edition` in `let_chains_policy` should be that of the whole `if` construct,
2720
+
/// i.e. the same span we use to later decide whether the drop behaviour should be that of
2721
+
/// edition `..=2021` or that of `2024..`.
2714
2722
// Public because it is used in rustfmt forks such as https://github.com/tucant/rustfmt/blob/30c83df9e1db10007bdd16dafce8a86b404329b2/src/parse/macros/html.rs#L57 for custom if expressions.
0 commit comments