Skip to content

Recover from common if let syntax mistakes/typos #103587

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

fn main() {
    let x = Some(123);

    // #1
    if let Some(_) == x {}

    // #2
    if let x = Some(_) {}

    // #3
    if let x == Some(_) {}

    // #4
    if Some(_) = x {}
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected one of `=` or `|`, found `==`
 --> src/main.rs:5:20
  |
5 |     if let Some(_) == x {}
  |                    ^^ expected one of `=` or `|`

error: could not compile `playground` due to previous error

Ideally the output should suggest how to fix the syntax mistakes/typos for each of the above examples.
1 -> Remove extra =
2 -> Swap x and Some(_)
3 -> 1 and 2
4 -> Add let

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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