Skip to content

Recover from common if let syntax mistakes/typos #103587

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 26, 2022
  2. chenyukang commented on Oct 27, 2022

    @chenyukang
    Member

    @rustbot claim

  3. chenyukang commented on Oct 27, 2022

    @chenyukang
    Member

    Submit #103636 to resolve scenario 1 and 4, because I think we are sure about the intention of developer, and there is a clear way to fix it.

    For 2 and 3, there are several potential ways to fix the code, so give a specific suggestion may not correct.

  4. added a commit that references this issue on Nov 8, 2022
    667b15b
  5. added 4 commits that reference this issue on Nov 8, 2022
    0dfd52b
    1053217
    c4526d8
    47b7512
  6. added a commit that references this issue on Nov 10, 2022
    11fa085
  7. added a commit that references this issue on Jan 6, 2023
    1ff5e2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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