Skip to content

Commit 751cb0c

Browse files
committed
Revert let chains stabilization (feature(let_chains) again)
Undo the language stabilization of let chains from rust-lang#132833 / 1.88.0 by: - moving `let_chains` from accepted features back to unstable features - restoring the ast feature gate for `let_chains` - re-gating chained `let` expressions in conditions behind the feature Plain `if let` / `while let` remains stable; only chains such as `if a && let Some(x) = y` require `#![feature(let_chains)]`. This reintroduces the pre-stabilization language surface for let chains (tracking issue rust-lang#53667).
1 parent 0b5107f commit 751cb0c

4 files changed

Lines changed: 6 additions & 11 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
492492
gate_all!(global_registration, "global registration is experimental");
493493
gate_all!(guard_patterns, "guard patterns are experimental", "consider using match arm guards");
494494
gate_all!(impl_restriction, "`impl` restrictions are experimental");
495+
gate_all!(let_chains, "`let` expressions in this position are unstable");
495496
gate_all!(min_generic_const_args, "unbraced const blocks as const args are experimental");
496497
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
497498
gate_all!(move_expr, "`move(expr)` syntax is experimental");

compiler/rustc_feature/src/accepted.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ declare_features! (
275275
(accepted, keylocker_x86, "1.89.0", Some(134813)),
276276
/// Allows `'a: { break 'a; }`.
277277
(accepted, label_break_value, "1.65.0", Some(48594)),
278-
/// Allows `if/while p && let q = r && ...` chains.
279-
(accepted, let_chains, "1.88.0", Some(53667)),
280278
/// Allows `let...else` statements.
281279
(accepted, let_else, "1.65.0", Some(87335)),
282280
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ declare_features! (
607607
(unstable, large_assignments, "1.52.0", Some(83518)),
608608
/// Allow to have type alias types for inter-crate use.
609609
(incomplete, lazy_type_alias, "1.72.0", Some(112792)),
610+
/// Allows `if/while p && let q = r && ...` chains.
611+
(unstable, let_chains, "1.37.0", Some(53667)),
610612
/// Allows using `#[link(kind = "link-arg", name = "...")]`
611613
/// to pass custom arguments to the linker.
612614
(unstable, link_arg_attribute, "1.76.0", Some(99427)),

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4353,15 +4353,9 @@ impl MutVisitor for CondChecker<'_> {
43534353
};
43544354
*recovered = Recovered::Yes(error);
43554355
} else if self.depth > 1 {
4356-
// Top level `let` is always allowed; only gate chains
4357-
match self.let_chains_policy {
4358-
LetChainsPolicy::AlwaysAllowed => (),
4359-
LetChainsPolicy::EditionDependent { current_edition } => {
4360-
if !current_edition.at_least_rust_2024() || !span.at_least_rust_2024() {
4361-
self.parser.dcx().emit_err(errors::LetChainPre2024 { span });
4362-
}
4363-
}
4364-
}
4356+
// Top-level `if let` / `while let` is stable; only chained `let`s are gated.
4357+
// Re-introduces the `let_chains` feature gate (undoes #132833 stabilization).
4358+
self.parser.psess.gated_spans.gate(sym::let_chains, span);
43654359
}
43664360
}
43674361
ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => {

0 commit comments

Comments
 (0)