From 701dd632ec6ca5304353d7ced0cec61d336c47d8 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 23 Apr 2025 19:52:36 +0800 Subject: [PATCH] gate `let_chains` in all places before the 2024 edition Since `let_chains` relies on the 2024 edition drop order to be consistent, it makes sense for us to gate it in all places, even when there are unstable features such as with `if_let_guard`s in matches. This removes the need for us to pass in an enum to `CondChecker` as we can just always pass in the edition instead. --- compiler/rustc_parse/src/parser/expr.rs | 43 +++----- .../rfc-2294-if-let-guard/feature-gate.rs | 5 + .../rfc-2294-if-let-guard/feature-gate.stderr | 100 +++++++++++++----- .../rfc-2497-if-let-chains/issue-93150.rs | 3 +- .../rfc-2497-if-let-chains/issue-93150.stderr | 12 ++- 5 files changed, 108 insertions(+), 55 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 370eb3f402d93..5e6e9404189c7 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2605,8 +2605,7 @@ impl<'a> Parser<'a> { let lo = self.prev_token.span; // Scoping code checks the top level edition of the `if`; let's match it here. // The `CondChecker` also checks the edition of the `let` itself, just to make sure. - let let_chains_policy = LetChainsPolicy::EditionDependent { current_edition: lo.edition() }; - let cond = self.parse_expr_cond(let_chains_policy)?; + let cond = self.parse_expr_cond(lo.edition())?; self.parse_if_after_cond(lo, cond) } @@ -2716,16 +2715,16 @@ impl<'a> Parser<'a> { /// Parses the condition of a `if` or `while` expression. /// - /// The specified `edition` in `let_chains_policy` should be that of the whole `if` construct, - /// i.e. the same span we use to later decide whether the drop behaviour should be that of - /// edition `..=2021` or that of `2024..`. + /// The specified `edition` should be that of the whole `if` construct, i.e. the same span + /// we use to later decide whether the drop behaviour should be that of edition `..=2021` + /// or that of `2024..`. // 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. - pub fn parse_expr_cond(&mut self, let_chains_policy: LetChainsPolicy) -> PResult<'a, P> { + pub fn parse_expr_cond(&mut self, edition: Edition) -> PResult<'a, P> { let attrs = self.parse_outer_attributes()?; let (mut cond, _) = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, attrs)?; - CondChecker::new(self, let_chains_policy).visit_expr(&mut cond); + CondChecker::new(self, edition).visit_expr(&mut cond); Ok(cond) } @@ -3020,8 +3019,7 @@ impl<'a> Parser<'a> { /// Parses a `while` or `while let` expression (`while` token already eaten). fn parse_expr_while(&mut self, opt_label: Option