Skip to content

Commit 82bf341

Browse files
committed
Auto merge of rust-lang#100538 - Nilstrieb:revert-let-chains-beta, r=compiler-errors
Revert let_chains stabilization This reverts commit 3266460. It was discovered in rust-lang#100513 that they are not implemented correctly, which does not make them ready for stabilization. The merge in the let parsing had a few conflicts, cc `@compiler-errors` and `@c410-f3r` to make sure I did it correctly (alternatively I could also revert `@compiler-errors'` let diagnostic improvement PR as well if a simpler revert is desired). r? `@Mark-Simulacrum`
2 parents fb2194a + 11a367a commit 82bf341

File tree

60 files changed

+789
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+789
-439
lines changed

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(const_trait_impl)]
1515
#![feature(if_let_guard)]
1616
#![feature(label_break_value)]
17-
#![cfg_attr(bootstrap, feature(let_chains))]
17+
#![feature(let_chains)]
1818
#![feature(min_specialization)]
1919
#![feature(negative_impls)]
2020
#![feature(slice_internals)]

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//! in the HIR, especially for multiple identifiers.
3232
3333
#![feature(box_patterns)]
34-
#![cfg_attr(bootstrap, feature(let_chains))]
34+
#![feature(let_chains)]
3535
#![feature(let_else)]
3636
#![feature(never_type)]
3737
#![recursion_limit = "256"]

compiler/rustc_ast_passes/src/ast_validation.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,33 @@ impl<'a> AstValidator<'a> {
119119

120120
/// Emits an error banning the `let` expression provided in the given location.
121121
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
122-
let err = "`let` expressions are not supported here";
123-
let mut diag = self.session.struct_span_err(expr.span, err);
124-
diag.note("only supported directly in conditions of `if` and `while` expressions");
125-
match forbidden_let_reason {
126-
ForbiddenLetReason::GenericForbidden => {}
127-
ForbiddenLetReason::NotSupportedOr(span) => {
128-
diag.span_note(span, "`||` operators are not supported in let chain expressions");
129-
}
130-
ForbiddenLetReason::NotSupportedParentheses(span) => {
131-
diag.span_note(
132-
span,
133-
"`let`s wrapped in parentheses are not supported in a context with let \
134-
chains",
135-
);
122+
let sess = &self.session;
123+
if sess.opts.unstable_features.is_nightly_build() {
124+
let err = "`let` expressions are not supported here";
125+
let mut diag = sess.struct_span_err(expr.span, err);
126+
diag.note("only supported directly in conditions of `if` and `while` expressions");
127+
match forbidden_let_reason {
128+
ForbiddenLetReason::GenericForbidden => {}
129+
ForbiddenLetReason::NotSupportedOr(span) => {
130+
diag.span_note(
131+
span,
132+
"`||` operators are not supported in let chain expressions",
133+
);
134+
}
135+
ForbiddenLetReason::NotSupportedParentheses(span) => {
136+
diag.span_note(
137+
span,
138+
"`let`s wrapped in parentheses are not supported in a context with let \
139+
chains",
140+
);
141+
}
136142
}
143+
diag.emit();
144+
} else {
145+
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
146+
.note("variable declaration using `let` is a statement")
147+
.emit();
137148
}
138-
diag.emit();
139149
}
140150

141151
fn check_gat_where(

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
766766
"`if let` guards are experimental",
767767
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
768768
);
769+
gate_all!(let_chains, "`let` expressions in this position are unstable");
769770
gate_all!(
770771
async_closure,
771772
"async closures are unstable",

compiler/rustc_ast_passes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(box_patterns)]
99
#![feature(if_let_guard)]
1010
#![feature(iter_is_partitioned)]
11-
#![cfg_attr(bootstrap, feature(let_chains))]
11+
#![feature(let_chains)]
1212
#![feature(let_else)]
1313
#![recursion_limit = "256"]
1414

compiler/rustc_attr/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
55
//! to this crate.
66
7-
#![cfg_attr(bootstrap, feature(let_chains))]
7+
#![feature(let_chains)]
88
#![feature(let_else)]
99

1010
#[macro_use]

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![allow(rustc::potential_query_instability)]
44
#![feature(box_patterns)]
5-
#![cfg_attr(bootstrap, feature(let_chains))]
5+
#![feature(let_chains)]
66
#![feature(let_else)]
77
#![feature(min_specialization)]
88
#![feature(never_type)]

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(decl_macro)]
99
#![feature(if_let_guard)]
1010
#![feature(is_sorted)]
11-
#![cfg_attr(bootstrap, feature(let_chains))]
11+
#![feature(let_chains)]
1212
#![feature(let_else)]
1313
#![feature(proc_macro_internals)]
1414
#![feature(proc_macro_quote)]

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
88
#![feature(hash_raw_entry)]
9-
#![cfg_attr(bootstrap, feature(let_chains))]
9+
#![feature(let_chains)]
1010
#![feature(let_else)]
1111
#![feature(extern_types)]
1212
#![feature(once_cell)]

compiler/rustc_const_eval/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Rust MIR: a lowered representation of Rust.
99
#![feature(control_flow_enum)]
1010
#![feature(decl_macro)]
1111
#![feature(exact_size_is_empty)]
12-
#![cfg_attr(bootstrap, feature(let_chains))]
12+
#![feature(let_chains)]
1313
#![feature(let_else)]
1414
#![feature(map_try_insert)]
1515
#![feature(min_specialization)]

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(bootstrap, feature(let_chains))]
1+
#![feature(let_chains)]
22
#![feature(once_cell)]
33
#![feature(rustc_attrs)]
44
#![feature(type_alias_impl_trait)]

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(drain_filter)]
77
#![feature(backtrace)]
88
#![feature(if_let_guard)]
9-
#![cfg_attr(bootstrap, feature(let_chains))]
9+
#![feature(let_chains)]
1010
#![feature(let_else)]
1111
#![feature(never_type)]
1212
#![feature(adt_const_params)]

compiler/rustc_expand/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(associated_type_bounds)]
33
#![feature(associated_type_defaults)]
44
#![feature(if_let_guard)]
5-
#![cfg_attr(bootstrap, feature(let_chains))]
5+
#![feature(let_chains)]
66
#![feature(let_else)]
77
#![feature(macro_metavar_expr)]
88
#![feature(proc_macro_diagnostic)]

compiler/rustc_feature/src/accepted.rs

-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ declare_features! (
186186
/// Allows some increased flexibility in the name resolution rules,
187187
/// especially around globs and shadowing (RFC 1560).
188188
(accepted, item_like_imports, "1.15.0", Some(35120), None),
189-
/// Allows `if/while p && let q = r && ...` chains.
190-
(accepted, let_chains, "1.64.0", Some(53667), None),
191189
/// Allows `break {expr}` with a value inside `loop`s.
192190
(accepted, loop_break_value, "1.19.0", Some(37339), None),
193191
/// Allows use of `?` as the Kleene "at most one" operator in macros.

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ declare_features! (
424424
(active, label_break_value, "1.28.0", Some(48594), None),
425425
// Allows setting the threshold for the `large_assignments` lint.
426426
(active, large_assignments, "1.52.0", Some(83518), None),
427+
/// Allows `if/while p && let q = r && ...` chains.
428+
(active, let_chains, "1.37.0", Some(53667), None),
427429
/// Allows `let...else` statements.
428430
(active, let_else, "1.56.0", Some(87335), None),
429431
/// Allows `#[link(..., cfg(..))]`.

compiler/rustc_infer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#![feature(control_flow_enum)]
1919
#![feature(extend_one)]
2020
#![feature(label_break_value)]
21-
#![cfg_attr(bootstrap, feature(let_chains))]
21+
#![feature(let_chains)]
2222
#![feature(let_else)]
2323
#![feature(min_specialization)]
2424
#![feature(never_type)]

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#![feature(if_let_guard)]
3434
#![feature(iter_intersperse)]
3535
#![feature(iter_order_by)]
36-
#![cfg_attr(bootstrap, feature(let_chains))]
36+
#![feature(let_chains)]
3737
#![feature(let_else)]
3838
#![feature(never_type)]
3939
#![recursion_limit = "256"]

compiler/rustc_metadata/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![feature(generators)]
55
#![feature(generic_associated_types)]
66
#![feature(iter_from_generator)]
7-
#![cfg_attr(bootstrap, feature(let_chains))]
7+
#![feature(let_chains)]
88
#![feature(let_else)]
99
#![feature(once_cell)]
1010
#![feature(proc_macro_internals)]

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#![feature(extern_types)]
4141
#![feature(new_uninit)]
4242
#![feature(once_cell)]
43-
#![cfg_attr(bootstrap, feature(let_chains))]
43+
#![feature(let_chains)]
4444
#![feature(let_else)]
4545
#![feature(min_specialization)]
4646
#![feature(trusted_len)]

compiler/rustc_mir_build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(box_patterns)]
66
#![feature(control_flow_enum)]
77
#![feature(if_let_guard)]
8-
#![cfg_attr(bootstrap, feature(let_chains))]
8+
#![feature(let_chains)]
99
#![feature(let_else)]
1010
#![feature(min_specialization)]
1111
#![feature(once_cell)]

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(rustc::potential_query_instability)]
22
#![feature(box_patterns)]
3-
#![cfg_attr(bootstrap, feature(let_chains))]
3+
#![feature(let_chains)]
44
#![feature(let_else)]
55
#![feature(map_try_insert)]
66
#![feature(min_specialization)]

compiler/rustc_parse/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(array_windows)]
44
#![feature(box_patterns)]
55
#![feature(if_let_guard)]
6-
#![cfg_attr(bootstrap, feature(let_chains))]
6+
#![feature(let_chains)]
77
#![feature(let_else)]
88
#![feature(never_type)]
99
#![feature(rustc_attrs)]

compiler/rustc_parse/src/parser/expr.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,14 @@ impl<'a> Parser<'a> {
23402340

23412341
/// Parses the condition of a `if` or `while` expression.
23422342
fn parse_cond_expr(&mut self) -> PResult<'a, P<Expr>> {
2343-
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)
2343+
let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)?;
2344+
2345+
if let ExprKind::Let(..) = cond.kind {
2346+
// Remove the last feature gating of a `let` expression since it's stable.
2347+
self.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
2348+
}
2349+
2350+
Ok(cond)
23442351
}
23452352

23462353
/// Parses a `let $pat = $expr` pseudo-expression.
@@ -2370,6 +2377,7 @@ impl<'a> Parser<'a> {
23702377
this.parse_assoc_expr_with(1 + prec_let_scrutinee_needs_par(), None.into())
23712378
})?;
23722379
let span = lo.to(expr.span);
2380+
self.sess.gated_spans.gate(sym::let_chains, span);
23732381
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span), attrs))
23742382
}
23752383

@@ -2675,13 +2683,15 @@ impl<'a> Parser<'a> {
26752683
pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm> {
26762684
// Used to check the `let_chains` and `if_let_guard` features mostly by scaning
26772685
// `&&` tokens.
2678-
fn check_let_expr(expr: &Expr) -> bool {
2686+
fn check_let_expr(expr: &Expr) -> (bool, bool) {
26792687
match expr.kind {
26802688
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
2681-
check_let_expr(lhs) || check_let_expr(rhs)
2689+
let lhs_rslt = check_let_expr(lhs);
2690+
let rhs_rslt = check_let_expr(rhs);
2691+
(lhs_rslt.0 || rhs_rslt.0, false)
26822692
}
2683-
ExprKind::Let(..) => true,
2684-
_ => false,
2693+
ExprKind::Let(..) => (true, true),
2694+
_ => (false, true),
26852695
}
26862696
}
26872697
let attrs = self.parse_outer_attributes()?;
@@ -2696,7 +2706,12 @@ impl<'a> Parser<'a> {
26962706
let guard = if this.eat_keyword(kw::If) {
26972707
let if_span = this.prev_token.span;
26982708
let cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?;
2699-
if check_let_expr(&cond) {
2709+
let (has_let_expr, does_not_have_bin_op) = check_let_expr(&cond);
2710+
if has_let_expr {
2711+
if does_not_have_bin_op {
2712+
// Remove the last feature gating of a `let` expression since it's stable.
2713+
this.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
2714+
}
27002715
let span = if_span.to(cond.span);
27012716
this.sess.gated_spans.gate(sym::if_let_guard, span);
27022717
}

compiler/rustc_passes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![allow(rustc::potential_query_instability)]
88
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
99
#![feature(iter_intersperse)]
10-
#![cfg_attr(bootstrap, feature(let_chains))]
10+
#![feature(let_chains)]
1111
#![feature(let_else)]
1212
#![feature(map_try_insert)]
1313
#![feature(min_specialization)]

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#![feature(box_patterns)]
1111
#![feature(drain_filter)]
1212
#![feature(if_let_guard)]
13-
#![cfg_attr(bootstrap, feature(let_chains))]
1413
#![feature(iter_intersperse)]
14+
#![feature(let_chains)]
1515
#![feature(let_else)]
1616
#![feature(never_type)]
1717
#![recursion_limit = "256"]

compiler/rustc_session/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(if_let_guard)]
2-
#![cfg_attr(bootstrap, feature(let_chains))]
2+
#![feature(let_chains)]
33
#![feature(let_else)]
44
#![feature(min_specialization)]
55
#![feature(never_type)]

compiler/rustc_trait_selection/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![feature(drain_filter)]
1818
#![feature(hash_drain_filter)]
1919
#![feature(label_break_value)]
20-
#![cfg_attr(bootstrap, feature(let_chains))]
20+
#![feature(let_chains)]
2121
#![feature(let_else)]
2222
#![feature(if_let_guard)]
2323
#![feature(never_type)]

compiler/rustc_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This API is completely unstable and subject to change.
6565
#![feature(is_sorted)]
6666
#![feature(iter_intersperse)]
6767
#![feature(label_break_value)]
68-
#![cfg_attr(bootstrap, feature(let_chains))]
68+
#![feature(let_chains)]
6969
#![feature(let_else)]
7070
#![feature(min_specialization)]
7171
#![feature(never_type)]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
#![feature(intra_doc_pointers)]
244244
#![feature(label_break_value)]
245245
#![feature(lang_items)]
246-
#![cfg_attr(bootstrap, feature(let_chains))]
246+
#![feature(let_chains)]
247247
#![feature(let_else)]
248248
#![feature(linkage)]
249249
#![feature(min_specialization)]

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(box_patterns)]
99
#![feature(control_flow_enum)]
1010
#![feature(drain_filter)]
11-
#![cfg_attr(bootstrap, feature(let_chains))]
11+
#![feature(let_chains)]
1212
#![feature(let_else)]
1313
#![feature(test)]
1414
#![feature(never_type)]

src/test/ui/expr/if/attrs/let-chains-attr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// check-pass
22

3+
#![feature(let_chains)]
4+
35
#[cfg(FALSE)]
46
fn foo() {
57
#[attr]

src/test/ui/expr/if/bad-if-let-suggestion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
fn a() {
55
if let x = 1 && i = 2 {}
66
//~^ ERROR cannot find value `i` in this scope
7+
//~| ERROR `let` expressions in this position are unstable
78
//~| ERROR mismatched types
89
//~| ERROR `let` expressions are not supported here
910
}

0 commit comments

Comments
 (0)