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

Recover from common if let syntax mistakes/typos #103587

Closed
Rageking8 opened this issue Oct 26, 2022 · 2 comments · Fixed by #103636
Closed

Recover from common if let syntax mistakes/typos #103587

Rageking8 opened this issue Oct 26, 2022 · 2 comments · Fixed by #103636
Assignees
Labels
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.

Comments

@Rageking8
Copy link
Contributor

Rageking8 commented Oct 26, 2022

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

@Rageking8 Rageking8 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 Oct 26, 2022
@chenyukang
Copy link
Member

@rustbot claim

@chenyukang
Copy link
Member

chenyukang commented Oct 27, 2022

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.

Manishearth added a commit to Manishearth/rust that referenced this issue Nov 8, 2022
…if-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 8, 2022
…if-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 8, 2022
…if-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 10, 2022
…if-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 10, 2022
…-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
@bors bors closed this as completed in 667b15b Nov 10, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes rust-lang#103587
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 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.

2 participants