Revert let_chains stabilization

This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in .
This commit is contained in:
Nilstrieb 2022-08-20 20:40:08 +02:00
parent 76eb4f3bfd
commit d1ef8180f9
59 changed files with 825 additions and 430 deletions
compiler
rustc_ast/src
rustc_ast_lowering/src
rustc_ast_passes/src
rustc_attr/src
rustc_borrowck/src
rustc_builtin_macros/src
rustc_codegen_llvm/src
rustc_const_eval/src
rustc_error_messages/src
rustc_errors/src
rustc_expand/src
rustc_feature/src
rustc_infer/src
rustc_lint/src
rustc_metadata/src
rustc_middle/src
rustc_mir_build/src
rustc_mir_transform/src
rustc_parse/src
rustc_passes/src
rustc_resolve/src
rustc_session/src
rustc_trait_selection/src
rustc_typeck/src
library/std/src
src

View File

@ -14,6 +14,7 @@
#![feature(const_trait_impl)]
#![feature(if_let_guard)]
#![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(slice_internals)]

View File

@ -31,6 +31,7 @@
//! in the HIR, especially for multiple identifiers.
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(never_type)]
#![recursion_limit = "256"]

View File

@ -119,7 +119,33 @@ impl<'a> AstValidator<'a> {
/// Emits an error banning the `let` expression provided in the given location.
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
self.session.emit_err(ForbiddenLet { span: expr.span, reason: forbidden_let_reason });
let sess = &self.session;
if sess.opts.unstable_features.is_nightly_build() {
let err = "`let` expressions are not supported here";
let mut diag = sess.struct_span_err(expr.span, err);
diag.note("only supported directly in conditions of `if` and `while` expressions");
match forbidden_let_reason {
ForbiddenLetReason::GenericForbidden => {}
ForbiddenLetReason::NotSupportedOr(span) => {
diag.span_note(
span,
"`||` operators are not supported in let chain expressions",
);
}
ForbiddenLetReason::NotSupportedParentheses(span) => {
diag.span_note(
span,
"`let`s wrapped in parentheses are not supported in a context with let \
chains",
);
}
}
diag.emit();
} else {
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
.note("variable declaration using `let` is a statement")
.emit();
}
}
fn check_gat_where(

View File

@ -777,6 +777,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
"`if let` guards are experimental",
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
);
gate_all!(let_chains, "`let` expressions in this position are unstable");
gate_all!(
async_closure,
"async closures are unstable",

View File

@ -8,6 +8,7 @@
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(iter_is_partitioned)]
#![feature(let_chains)]
#![feature(let_else)]
#![recursion_limit = "256"]

View File

@ -4,6 +4,7 @@
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
//! to this crate.
#![feature(let_chains)]
#![feature(let_else)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

View File

@ -2,6 +2,7 @@
#![allow(rustc::potential_query_instability)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(never_type)]

View File

@ -8,6 +8,7 @@
#![feature(decl_macro)]
#![feature(if_let_guard)]
#![feature(is_sorted)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]

View File

@ -6,6 +6,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(hash_raw_entry)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(extern_types)]
#![feature(once_cell)]

View File

@ -9,6 +9,7 @@ Rust MIR: a lowered representation of Rust.
#![feature(control_flow_enum)]
#![feature(decl_macro)]
#![feature(exact_size_is_empty)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(map_try_insert)]
#![feature(min_specialization)]

View File

@ -1,3 +1,4 @@
#![feature(let_chains)]
#![feature(once_cell)]
#![feature(rustc_attrs)]
#![feature(type_alias_impl_trait)]

View File

@ -6,6 +6,7 @@
#![feature(drain_filter)]
#![feature(if_let_guard)]
#![feature(adt_const_params)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(never_type)]
#![feature(result_option_inspect)]

View File

@ -2,6 +2,7 @@
#![feature(associated_type_bounds)]
#![feature(associated_type_defaults)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(macro_metavar_expr)]
#![feature(proc_macro_diagnostic)]

View File

@ -188,8 +188,6 @@ declare_features! (
(accepted, item_like_imports, "1.15.0", Some(35120), None),
/// Allows `'a: { break 'a; }`.
(accepted, label_break_value, "CURRENT_RUSTC_VERSION", Some(48594), None),
/// Allows `if/while p && let q = r && ...` chains.
(accepted, let_chains, "1.64.0", Some(53667), None),
/// Allows `break {expr}` with a value inside `loop`s.
(accepted, loop_break_value, "1.19.0", Some(37339), None),
/// Allows use of `?` as the Kleene "at most one" operator in macros.

View File

@ -422,6 +422,8 @@ declare_features! (
(active, isa_attribute, "1.48.0", Some(74727), None),
// Allows setting the threshold for the `large_assignments` lint.
(active, large_assignments, "1.52.0", Some(83518), None),
/// Allows `if/while p && let q = r && ...` chains.
(active, let_chains, "1.37.0", Some(53667), None),
/// Allows `let...else` statements.
(active, let_else, "1.56.0", Some(87335), None),
/// Allows `#[link(..., cfg(..))]`.

View File

@ -18,6 +18,7 @@
#![feature(control_flow_enum)]
#![feature(extend_one)]
#![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(never_type)]

View File

@ -33,6 +33,7 @@
#![feature(if_let_guard)]
#![feature(iter_intersperse)]
#![feature(iter_order_by)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(never_type)]
#![recursion_limit = "256"]

View File

@ -4,6 +4,7 @@
#![feature(generators)]
#![feature(generic_associated_types)]
#![feature(iter_from_generator)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(once_cell)]
#![feature(proc_macro_internals)]

View File

@ -39,6 +39,7 @@
#![feature(extern_types)]
#![feature(new_uninit)]
#![feature(once_cell)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(trusted_len)]

View File

@ -5,6 +5,7 @@
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(once_cell)]

View File

@ -1,5 +1,6 @@
#![allow(rustc::potential_query_instability)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(map_try_insert)]
#![feature(min_specialization)]

View File

@ -3,6 +3,7 @@
#![feature(array_windows)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(never_type)]
#![feature(rustc_attrs)]

View File

@ -2251,7 +2251,15 @@ impl<'a> Parser<'a> {
/// Parses the condition of a `if` or `while` expression.
fn parse_cond_expr(&mut self) -> PResult<'a, P<Expr>> {
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)
let cond =
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)?;
if let ExprKind::Let(..) = cond.kind {
// Remove the last feature gating of a `let` expression since it's stable.
self.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
}
Ok(cond)
}
/// Parses a `let $pat = $expr` pseudo-expression.
@ -2280,6 +2288,7 @@ impl<'a> Parser<'a> {
this.parse_assoc_expr_with(1 + prec_let_scrutinee_needs_par(), None.into())
})?;
let span = lo.to(expr.span);
self.sess.gated_spans.gate(sym::let_chains, span);
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
}
@ -2571,13 +2580,15 @@ impl<'a> Parser<'a> {
pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm> {
// Used to check the `let_chains` and `if_let_guard` features mostly by scaning
// `&&` tokens.
fn check_let_expr(expr: &Expr) -> bool {
fn check_let_expr(expr: &Expr) -> (bool, bool) {
match expr.kind {
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
check_let_expr(lhs) || check_let_expr(rhs)
let lhs_rslt = check_let_expr(lhs);
let rhs_rslt = check_let_expr(rhs);
(lhs_rslt.0 || rhs_rslt.0, false)
}
ExprKind::Let(..) => true,
_ => false,
ExprKind::Let(..) => (true, true),
_ => (false, true),
}
}
let attrs = self.parse_outer_attributes()?;
@ -2592,7 +2603,12 @@ impl<'a> Parser<'a> {
let guard = if this.eat_keyword(kw::If) {
let if_span = this.prev_token.span;
let cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?;
if check_let_expr(&cond) {
let (has_let_expr, does_not_have_bin_op) = check_let_expr(&cond);
if has_let_expr {
if does_not_have_bin_op {
// Remove the last feature gating of a `let` expression since it's stable.
this.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
}
let span = if_span.to(cond.span);
this.sess.gated_spans.gate(sym::if_let_guard, span);
}

View File

@ -7,6 +7,7 @@
#![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(map_try_insert)]
#![feature(min_specialization)]

View File

@ -11,6 +11,7 @@
#![feature(drain_filter)]
#![feature(if_let_guard)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(never_type)]
#![recursion_limit = "256"]

View File

@ -1,4 +1,5 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(never_type)]

View File

@ -17,6 +17,7 @@
#![feature(drain_filter)]
#![feature(hash_drain_filter)]
#![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(if_let_guard)]
#![feature(never_type)]

View File

@ -65,6 +65,7 @@ This API is completely unstable and subject to change.
#![feature(is_sorted)]
#![feature(iter_intersperse)]
#![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(never_type)]

View File

@ -254,6 +254,7 @@
#![feature(intra_doc_pointers)]
#![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(lang_items)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(linkage)]
#![feature(link_cfg)]

View File

@ -8,6 +8,7 @@
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(drain_filter)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(test)]
#![feature(never_type)]

View File

@ -1,5 +1,7 @@
// check-pass
#![feature(let_chains)]
#[cfg(FALSE)]
fn foo() {
#[attr]

View File

@ -4,6 +4,7 @@
fn a() {
if let x = 1 && i = 2 {}
//~^ ERROR cannot find value `i` in this scope
//~| ERROR `let` expressions in this position are unstable
//~| ERROR mismatched types
//~| ERROR `let` expressions are not supported here
}

View File

@ -13,7 +13,7 @@ LL | if let x = 1 && i = 2 {}
| ^ not found in this scope
error[E0425]: cannot find value `i` in this scope
--> $DIR/bad-if-let-suggestion.rs:12:9
--> $DIR/bad-if-let-suggestion.rs:13:9
|
LL | fn a() {
| ------ similarly named function `a` defined here
@ -22,7 +22,7 @@ LL | if (i + j) = i {}
| ^ help: a function with a similar name exists: `a`
error[E0425]: cannot find value `j` in this scope
--> $DIR/bad-if-let-suggestion.rs:12:13
--> $DIR/bad-if-let-suggestion.rs:13:13
|
LL | fn a() {
| ------ similarly named function `a` defined here
@ -31,7 +31,7 @@ LL | if (i + j) = i {}
| ^ help: a function with a similar name exists: `a`
error[E0425]: cannot find value `i` in this scope
--> $DIR/bad-if-let-suggestion.rs:12:18
--> $DIR/bad-if-let-suggestion.rs:13:18
|
LL | fn a() {
| ------ similarly named function `a` defined here
@ -40,7 +40,7 @@ LL | if (i + j) = i {}
| ^ help: a function with a similar name exists: `a`
error[E0425]: cannot find value `x` in this scope
--> $DIR/bad-if-let-suggestion.rs:19:8
--> $DIR/bad-if-let-suggestion.rs:20:8
|
LL | fn a() {
| ------ similarly named function `a` defined here
@ -48,13 +48,22 @@ LL | fn a() {
LL | if x[0] = 1 {}
| ^ help: a function with a similar name exists: `a`
error[E0658]: `let` expressions in this position are unstable
--> $DIR/bad-if-let-suggestion.rs:5:8
|
LL | if let x = 1 && i = 2 {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0308]: mismatched types
--> $DIR/bad-if-let-suggestion.rs:5:8
|
LL | if let x = 1 && i = 2 {}
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
error: aborting due to 7 previous errors
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0308, E0425.
Some errors have detailed explanations: E0308, E0425, E0658.
For more information about an error, try `rustc --explain E0308`.

View File

@ -1,5 +1,6 @@
struct Bug<A = [(); (let a = (), 1).1]> {
//~^ `let` expressions are not supported here
//~| `let` expressions in this position are unstable [E0658]
//~| expected expression, found `let` statement
a: A
}

View File

@ -12,5 +12,15 @@ LL | struct Bug<A = [(); (let a = (), 1).1]> {
|
= note: only supported directly in conditions of `if` and `while` expressions
error: aborting due to 2 previous errors
error[E0658]: `let` expressions in this position are unstable
--> $DIR/issue-92893.rs:1:22
|
LL | struct Bug<A = [(); (let a = (), 1).1]> {
| ^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -4,6 +4,7 @@
// See `mir_drop_order.rs` for more information
#![feature(let_chains)]
#![allow(irrefutable_let_patterns)]
use std::cell::RefCell;

View File

@ -8,35 +8,49 @@ fn _if_let_guard() {
//~^ ERROR `if let` guards are experimental
() if (let 0 = 1) => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
() if (((let 0 = 1))) => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
() if true && let 0 = 1 => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR `let` expressions in this position are unstable
() if let 0 = 1 && true => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR `let` expressions in this position are unstable
() if (let 0 = 1) && true => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
() if true && (let 0 = 1) => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
() if (let 0 = 1) && (let 0 = 1) => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
() if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR `let` expressions in this position are unstable
//~| ERROR `let` expressions in this position are unstable
//~| ERROR `let` expressions in this position are unstable
//~| ERROR `let` expressions in this position are unstable
//~| ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
() if let Range { start: _, end: _ } = (true..true) && false => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR `let` expressions in this position are unstable
_ => {}
}
@ -52,9 +66,11 @@ fn _macros() {
}
}
use_expr!((let 0 = 1 && 0 == 0));
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
use_expr!((let 0 = 1));
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `let` expressions in this position are unstable
//~| ERROR expected expression, found `let` statement
match () {
#[cfg(FALSE)]
() if let 0 = 1 => {}

View File

@ -5,67 +5,67 @@ LL | () if (let 0 = 1) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:13:18
--> $DIR/feature-gate.rs:14:18
|
LL | () if (((let 0 = 1))) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:22:16
--> $DIR/feature-gate.rs:26:16
|
LL | () if (let 0 = 1) && true => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:25:24
--> $DIR/feature-gate.rs:30:24
|
LL | () if true && (let 0 = 1) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:28:16
--> $DIR/feature-gate.rs:34:16
|
LL | () if (let 0 = 1) && (let 0 = 1) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:28:31
--> $DIR/feature-gate.rs:34:31
|
LL | () if (let 0 = 1) && (let 0 = 1) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:32:42
--> $DIR/feature-gate.rs:40:42
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:32:55
--> $DIR/feature-gate.rs:40:55
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:32:68
--> $DIR/feature-gate.rs:40:68
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:54:16
--> $DIR/feature-gate.rs:68:16
|
LL | use_expr!((let 0 = 1 && 0 == 0));
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:56:16
--> $DIR/feature-gate.rs:71:16
|
LL | use_expr!((let 0 = 1));
| ^^^
error: no rules expected the token `let`
--> $DIR/feature-gate.rs:64:15
--> $DIR/feature-gate.rs:80:15
|
LL | macro_rules! use_expr {
| --------------------- when calling this macro
@ -84,7 +84,7 @@ LL | () if let 0 = 1 => {}
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:16:12
--> $DIR/feature-gate.rs:18:12
|
LL | () if true && let 0 = 1 => {}
| ^^^^^^^^^^^^^^^^^^^^
@ -94,7 +94,7 @@ LL | () if true && let 0 = 1 => {}
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:19:12
--> $DIR/feature-gate.rs:22:12
|
LL | () if let 0 = 1 && true => {}
| ^^^^^^^^^^^^^^^^^^^^
@ -104,7 +104,7 @@ LL | () if let 0 = 1 && true => {}
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:32:12
--> $DIR/feature-gate.rs:40:12
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -114,7 +114,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:38:12
--> $DIR/feature-gate.rs:51:12
|
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -124,7 +124,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:60:12
--> $DIR/feature-gate.rs:76:12
|
LL | () if let 0 = 1 => {}
| ^^^^^^^^^^^^
@ -133,6 +133,150 @@ LL | () if let 0 = 1 => {}
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error: aborting due to 18 previous errors
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:10:16
|
LL | () if (let 0 = 1) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:14:18
|
LL | () if (((let 0 = 1))) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:18:23
|
LL | () if true && let 0 = 1 => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:22:15
|
LL | () if let 0 = 1 && true => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:26:16
|
LL | () if (let 0 = 1) && true => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:30:24
|
LL | () if true && (let 0 = 1) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:34:16
|
LL | () if (let 0 = 1) && (let 0 = 1) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:34:31
|
LL | () if (let 0 = 1) && (let 0 = 1) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:40:15
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:40:28
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:40:42
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:40:55
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:40:68
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:51:15
|
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:68:16
|
LL | use_expr!((let 0 = 1 && 0 == 0));
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:71:16
|
LL | use_expr!((let 0 = 1));
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error: aborting due to 34 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,30 +0,0 @@
// check-pass
#![allow(irrefutable_let_patterns)]
use std::ops::Range;
fn _if() {
if let 0 = 1 {}
if true && let 0 = 1 {}
if let 0 = 1 && true {}
if let Range { start: _, end: _ } = (true..true) && false {}
if let 1 = 1 && let true = { true } && false {
}
}
fn _while() {
while let 0 = 1 {}
while true && let 0 = 1 {}
while let 0 = 1 && true {}
while let Range { start: _, end: _ } = (true..true) && false {}
}
fn main() {}

View File

@ -1,5 +1,6 @@
// run-pass
#![feature(let_chains)]
#![allow(irrefutable_let_patterns)]
fn main() {

View File

@ -17,6 +17,8 @@
//
// To that end, we check some positions which is not part of the language above.
#![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test.
#![allow(irrefutable_let_patterns)]
use std::ops::Range;
@ -102,12 +104,6 @@ fn _macros() {
//~^ ERROR `let` expressions are not supported here
//~| ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
use_expr!(true && let 0 = 1);
//~^ ERROR expected expression, found `let` statement
macro_rules! noop_expr { ($e:expr) => {}; }
noop_expr!((let 0 = 1));
//~^ ERROR expected expression, found `let` statement
}
fn nested_within_if_expr() {
@ -481,7 +477,4 @@ fn with_parenthesis() {
([1, 2, 3][let _ = ()])
//~^ ERROR expected expression, found `let` statement
}
#[cfg(FALSE)] (let 0 = 1);
//~^ ERROR expected expression, found `let` statement
}

View File

@ -1,4 +1,4 @@
#![feature(let_else)]
#![feature(let_chains, let_else)]
fn main() {
let opt = Some(1i32);

View File

@ -0,0 +1,62 @@
// gate-test-let_chains
// Here we test feature gating for ´let_chains`.
// See `disallowed-positions.rs` for the grammar
// defining the language for gated allowed positions.
#![allow(irrefutable_let_patterns)]
use std::ops::Range;
fn _if() {
if let 0 = 1 {} // Stable!
if true && let 0 = 1 {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
if let 0 = 1 && true {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
if let Range { start: _, end: _ } = (true..true) && false {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
if let 1 = 1 && let true = { true } && false {
//~^ ERROR `let` expressions in this position are unstable [E0658]
//~| ERROR `let` expressions in this position are unstable [E0658]
}
}
fn _while() {
while let 0 = 1 {} // Stable!
while true && let 0 = 1 {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
while let 0 = 1 && true {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
while let Range { start: _, end: _ } = (true..true) && false {}
//~^ ERROR `let` expressions in this position are unstable [E0658]
}
fn _macros() {
macro_rules! noop_expr { ($e:expr) => {}; }
noop_expr!((let 0 = 1));
//~^ ERROR `let` expressions in this position are unstable [E0658]
//~| ERROR expected expression, found `let` statement
macro_rules! use_expr {
($e:expr) => {
if $e {}
while $e {}
}
}
#[cfg(FALSE)] (let 0 = 1);
//~^ ERROR `let` expressions in this position are unstable [E0658]
//~| ERROR expected expression, found `let` statement
use_expr!(let 0 = 1);
//~^ ERROR no rules expected the token `let`
}
fn main() {}

View File

@ -0,0 +1,114 @@
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:55:20
|
LL | #[cfg(FALSE)] (let 0 = 1);
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:45:17
|
LL | noop_expr!((let 0 = 1));
| ^^^
error: no rules expected the token `let`
--> $DIR/feature-gate.rs:58:15
|
LL | macro_rules! use_expr {
| --------------------- when calling this macro
...
LL | use_expr!(let 0 = 1);
| ^^^ no rules expected this token in macro call
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:14:16
|
LL | if true && let 0 = 1 {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:17:8
|
LL | if let 0 = 1 && true {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:20:8
|
LL | if let Range { start: _, end: _ } = (true..true) && false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:23:8
|
LL | if let 1 = 1 && let true = { true } && false {
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:23:21
|
LL | if let 1 = 1 && let true = { true } && false {
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:32:19
|
LL | while true && let 0 = 1 {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:35:11
|
LL | while let 0 = 1 && true {}
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:38:11
|
LL | while let Range { start: _, end: _ } = (true..true) && false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:55:20
|
LL | #[cfg(FALSE)] (let 0 = 1);
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error[E0658]: `let` expressions in this position are unstable
--> $DIR/feature-gate.rs:45:17
|
LL | noop_expr!((let 0 = 1));
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,3 +1,5 @@
#![feature(let_chains)]
fn main() {
let _opt = Some(1i32);

View File

@ -1,35 +1,35 @@
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:6:19
--> $DIR/invalid-let-in-a-valid-let-context.rs:8:19
|
LL | let _ = &&let Some(x) = Some(42);
| ^^^
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:11:47
--> $DIR/invalid-let-in-a-valid-let-context.rs:13:47
|
LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 {
| ^^^
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:11:57
--> $DIR/invalid-let-in-a-valid-let-context.rs:13:57
|
LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 {
| ^^^
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:21:23
--> $DIR/invalid-let-in-a-valid-let-context.rs:23:23
|
LL | [1, 2, 3][let _ = ()];
| ^^^
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:30:47
--> $DIR/invalid-let-in-a-valid-let-context.rs:32:47
|
LL | if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 {
| ^^^
error: expected expression, found `let` statement
--> $DIR/invalid-let-in-a-valid-let-context.rs:38:21
--> $DIR/invalid-let-in-a-valid-let-context.rs:40:21
|
LL | let x = let y = 1;
| ^^^

View File

@ -1,7 +1,7 @@
// revisions: allowed disallowed
//[allowed] check-pass
#![feature(if_let_guard)]
#![feature(if_let_guard, let_chains)]
#![cfg_attr(allowed, allow(irrefutable_let_patterns))]
#![cfg_attr(disallowed, deny(irrefutable_let_patterns))]

View File

@ -1,5 +1,7 @@
// check-pass
#![feature(let_chains)]
fn main() {
let x = Some(vec!["test"]);

View File

@ -1,5 +1,7 @@
// check-pass
#![feature(let_chains)]
fn main() {
let opt = Some("foo bar");

View File

@ -2,6 +2,7 @@ fn main() {
match true {
_ if let true = true && true => {}
//~^ ERROR `if let` guards are
//~| ERROR `let` expressions in this
_ => {}
}
}

View File

@ -8,6 +8,15 @@ LL | _ if let true = true && true => {}
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error: aborting due to previous error
error[E0658]: `let` expressions in this position are unstable
--> $DIR/issue-93150.rs:3:14
|
LL | _ if let true = true && true => {}
| ^^^^^^^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: add `#![feature(let_chains)]` to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,6 +1,6 @@
// run-pass
#![feature(if_let_guard)]
#![feature(if_let_guard, let_chains)]
fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
if let Some(first) = opt

View File

@ -1,3 +1,4 @@
#![feature(let_chains)]
#![feature(let_else)]
#![feature(once_cell)]
#![feature(rustc_private)]

View File

@ -4,6 +4,7 @@
#![feature(control_flow_enum)]
#![feature(drain_filter)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(lint_reasons)]
#![feature(never_type)]

View File

@ -2,6 +2,7 @@
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(let_else)]
#![feature(let_chains)]
#![feature(lint_reasons)]
#![feature(once_cell)]
#![feature(rustc_private)]

View File

@ -1,4 +1,5 @@
// run-rustfix
#![feature(let_chains)]
#![allow(
unused,
clippy::assign_op_pattern,

View File

@ -1,4 +1,5 @@
// run-rustfix
#![feature(let_chains)]
#![allow(
unused,
clippy::assign_op_pattern,

View File

@ -1,5 +1,5 @@
error: unneeded late initialization
--> $DIR/needless_late_init.rs:22:5
--> $DIR/needless_late_init.rs:23:5
|
LL | let a;
| ^^^^^^ created here
@ -13,7 +13,7 @@ LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:25:5
--> $DIR/needless_late_init.rs:26:5
|
LL | let b;
| ^^^^^^ created here
@ -27,7 +27,7 @@ LL | let b = 1;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:26:5
--> $DIR/needless_late_init.rs:27:5
|
LL | let c;
| ^^^^^^ created here
@ -41,7 +41,7 @@ LL | let c = 2;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:30:5
--> $DIR/needless_late_init.rs:31:5
|
LL | let d: usize;
| ^^^^^^^^^^^^^ created here
@ -54,7 +54,7 @@ LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:33:5
--> $DIR/needless_late_init.rs:34:5
|
LL | let e;
| ^^^^^^ created here
@ -67,7 +67,7 @@ LL | let e = format!("{}", d);
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:38:5
--> $DIR/needless_late_init.rs:39:5
|
LL | let a;
| ^^^^^^
@ -88,7 +88,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:47:5
--> $DIR/needless_late_init.rs:48:5
|
LL | let b;
| ^^^^^^
@ -109,7 +109,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:54:5
--> $DIR/needless_late_init.rs:55:5
|
LL | let d;
| ^^^^^^
@ -130,7 +130,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:62:5
--> $DIR/needless_late_init.rs:63:5
|
LL | let e;
| ^^^^^^
@ -151,7 +151,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:69:5
--> $DIR/needless_late_init.rs:70:5
|
LL | let f;
| ^^^^^^
@ -167,7 +167,7 @@ LL + 1 => "three",
|
error: unneeded late initialization
--> $DIR/needless_late_init.rs:75:5
--> $DIR/needless_late_init.rs:76:5
|
LL | let g: usize;
| ^^^^^^^^^^^^^
@ -187,7 +187,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:83:5
--> $DIR/needless_late_init.rs:84:5
|
LL | let x;
| ^^^^^^ created here
@ -201,7 +201,7 @@ LL | let x = 1;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:87:5
--> $DIR/needless_late_init.rs:88:5
|
LL | let x;
| ^^^^^^ created here
@ -215,7 +215,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:91:5
--> $DIR/needless_late_init.rs:92:5
|
LL | let x;
| ^^^^^^ created here
@ -229,7 +229,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:110:5
--> $DIR/needless_late_init.rs:111:5
|
LL | let a;
| ^^^^^^
@ -250,7 +250,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:127:5
--> $DIR/needless_late_init.rs:128:5
|
LL | let a;
| ^^^^^^