Skip to content

Silencing "let expressions in this position are experimental" errors in case of misplaced parantheses in if let expression #83274

@atsuzaki

Description

@atsuzaki

Follow-up to #82827, cc: @estebank

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7810898a8a0c0b5d421b4efbd58a4ff8

pub fn main() {
  let x = Some(3);
  if (let Some(y) = x) {
    println!("{}", y)
  } else {
    println!("None")
  }
}

The current output is:

error[E0658]: `let` expressions in this position are experimental
 --> src/main.rs:3:7
  |
3 |   if (let Some(y) = x) {
  |       ^^^^^^^^^^^^^^^
  |
  = 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
  = help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`

error: invalid parentheses around `let` expression in `if let`
 --> src/main.rs:3:6
  |
3 |   if (let Some(y) = x) {
  |      ^               ^
  |
help: `if let` needs to be written without parentheses
  |
3 |   if let Some(y) = x {
  |     --             --

error: aborting due to 2 previous errors

Ideally the output should look like:
(Just the invalid parantheses error, and the let expressions in this position is experimental error is silenced)

error: invalid parentheses around `let` expression in `if let`
 --> src/main.rs:3:6
  |
3 |   if (let Some(y) = x) {
  |      ^               ^
  |
help: `if let` needs to be written without parentheses
  |
3 |   if let Some(y) = x {
  |     --             --

error: aborting due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions