Skip to content

Allow while let chains on all editions #140204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -3020,7 +3020,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<Label>, lo: Span) -> PResult<'a, P<Expr>> {
let policy = LetChainsPolicy::EditionDependent { current_edition: lo.edition() };
let policy = LetChainsPolicy::AlwaysAllowed;
let cond = self.parse_expr_cond(policy).map_err(|mut err| {
err.span_label(lo, "while parsing the condition of this `while` expression");
err
236 changes: 118 additions & 118 deletions tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.feature.stderr

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs
Original file line number Diff line number Diff line change
@@ -76,8 +76,6 @@ fn _while() {
//~^ ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//[no_feature]~| ERROR `let` expressions in this position are unstable
//[no_feature]~| ERROR `let` expressions in this position are unstable
}

#[cfg(not(nothing))]
3 changes: 0 additions & 3 deletions tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.rs
Original file line number Diff line number Diff line change
@@ -30,13 +30,10 @@ 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() {
40 changes: 5 additions & 35 deletions tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:54:20
--> $DIR/feature-gate.rs:51:20
|
LL | #[cfg(false)] (let 0 = 1);
| ^^^
|
= note: only supported directly in conditions of `if` and `while` expressions

error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:45:17
--> $DIR/feature-gate.rs:42:17
|
LL | noop_expr!((let 0 = 1));
| ^^^
|
= note: only supported directly in conditions of `if` and `while` expressions

error: no rules expected keyword `let`
--> $DIR/feature-gate.rs:56:15
--> $DIR/feature-gate.rs:53:15
|
LL | macro_rules! use_expr {
| --------------------- when calling this macro
@@ -24,7 +24,7 @@ LL | use_expr!(let 0 = 1);
| ^^^ no rules expected this token in macro call
|
note: while trying to match meta-variable `$e:expr`
--> $DIR/feature-gate.rs:49:10
--> $DIR/feature-gate.rs:46:10
|
LL | ($e:expr) => {
| ^^^^^^^
@@ -79,36 +79,6 @@ LL | if let 1 = 1 && let true = { true } && false {
= help: add `#![feature(let_chains)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 11 previous errors
error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0658`.