Skip to content
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

Prompted to add #![feature(let_chains)] to code that is unsupported anyway #104868

Closed
jruderman opened this issue Nov 25, 2022 · 1 comment · Fixed by #115677
Closed

Prompted to add #![feature(let_chains)] to code that is unsupported anyway #104868

jruderman opened this issue Nov 25, 2022 · 1 comment · Fixed by #115677
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Given the following code (playground):

fn main() {
    let _ = let _ = 3;
}

The current output is:

error: expected expression, found `let` statement
 --> qlet.rs:2:13
  |
2 |     let _ = let _ = 3;
  |             ^^^

error: `let` expressions are not supported here
 --> qlet.rs:2:13
  |
2 |     let _ = let _ = 3;
  |             ^^^^^^^^^
  |
  = note: only supported directly in conditions of `if` and `while` expressions

error[E0658]: `let` expressions in this position are unstable
 --> qlet.rs:2:13
  |
2 |     let _ = let _ = 3;
  |             ^^^^^^^^^
  |
  = 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

Adding #![feature(let_chains)] only makes the last error go away: let is not supported in this position even with #![feature(let_chains)].

So it would be better not to show the last error message in this case.

Version

rustc 1.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4
@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2022
@TaKO8Ki TaKO8Ki self-assigned this Nov 28, 2022
@est31
Copy link
Member

est31 commented Jan 7, 2023

@rustbot label F-let_chains

@rustbot rustbot added the F-let_chains `#![feature(let_chains)]` label Jan 7, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 14, 2023
…-naber

Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for rust-lang#104172.

Fixes rust-lang#104172
Fixes rust-lang#104868
@bors bors closed this as completed in dac91a8 Sep 14, 2023
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 25, 2023
…-naber

Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for rust-lang#104172.

Fixes rust-lang#104172
Fixes rust-lang#104868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants