Skip to content

Commit dc9879c

Browse files
committed
Remove let_chains feature
1 parent ed2d759 commit dc9879c

39 files changed

+1053
-1194
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
469469
"`if let` guards are experimental",
470470
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
471471
);
472-
gate_all!(let_chains, "`let` expressions in this position are unstable");
473472
gate_all!(
474473
async_trait_bounds,
475474
"`async` trait bounds are unstable",

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ declare_features! (
265265
(accepted, keylocker_x86, "CURRENT_RUSTC_VERSION", Some(134813)),
266266
/// Allows `'a: { break 'a; }`.
267267
(accepted, label_break_value, "1.65.0", Some(48594)),
268+
/// Allows `if/while p && let q = r && ...` chains.
269+
(accepted, let_chains, "1.88.0", Some(53667)),
268270
/// Allows `let...else` statements.
269271
(accepted, let_else, "1.65.0", Some(87335)),
270272
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.

compiler/rustc_feature/src/unstable.rs

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

compiler/rustc_parse/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ parse_leading_underscore_unicode_escape_label = invalid start of unicode escape
512512
parse_left_arrow_operator = unexpected token: `<-`
513513
.suggestion = if you meant to write a comparison against a negative value, add a space in between `<` and `-`
514514
515+
parse_let_chain_pre_2024 = let chains are only allowed in Rust 2024 or later
516+
515517
parse_lifetime_after_mut = lifetime must precede `mut`
516518
.suggestion = place the lifetime before `mut`
517519

compiler/rustc_parse/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,13 @@ pub(crate) struct AsyncBoundModifierIn2015 {
17781778
pub help: HelpUseLatestEdition,
17791779
}
17801780

1781+
#[derive(Diagnostic)]
1782+
#[diag(parse_let_chain_pre_2024)]
1783+
pub(crate) struct LetChainPre2024 {
1784+
#[primary_span]
1785+
pub span: Span,
1786+
}
1787+
17811788
#[derive(Diagnostic)]
17821789
#[diag(parse_self_argument_pointer)]
17831790
pub(crate) struct SelfArgumentPointer {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ impl MutVisitor for CondChecker<'_> {
41174117
LetChainsPolicy::AlwaysAllowed => (),
41184118
LetChainsPolicy::EditionDependent { current_edition } => {
41194119
if !current_edition.at_least_rust_2024() || !span.at_least_rust_2024() {
4120-
self.parser.psess.gated_spans.gate(sym::let_chains, span);
4120+
self.parser.dcx().emit_err(errors::LetChainPre2024 { span });
41214121
}
41224122
}
41234123
}

src/tools/rustfmt/tests/source/let_chains.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-edition: 2024
2+
13
fn main() {
24
if let x = x && x {}
35

src/tools/rustfmt/tests/target/let_chains.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-edition: 2024
2+
13
fn main() {
24
if let x = x
35
&& x

tests/coverage/branch/if-let.coverage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
LL| |#![feature(coverage_attribute, let_chains)]
2-
LL| |//@ edition: 2021
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
33
LL| |//@ compile-flags: -Zcoverage-options=branch
44
LL| |//@ llvm-cov-flags: --show-branches=count
55
LL| |

tests/coverage/branch/if-let.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![feature(coverage_attribute, let_chains)]
2-
//@ edition: 2021
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
33
//@ compile-flags: -Zcoverage-options=branch
44
//@ llvm-cov-flags: --show-branches=count
55

0 commit comments

Comments
 (0)