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

Poor diagnostic when using an if expression with missing half of binary operator #91421

Closed
lcnr opened this issue Dec 1, 2021 · 1 comment · Fixed by #91435
Closed

Poor diagnostic when using an if expression with missing half of binary operator #91421

lcnr opened this issue Dec 1, 2021 · 1 comment · Fixed by #91435
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

@lcnr
Copy link
Contributor

lcnr commented Dec 1, 2021

Given the following code:

fn main() {
    let value = if true && {
        3
    } else { 4 };
}

The current output is:

error: missing condition for `if` expression
 --> src/main.rs:2:19
  |
2 |     let value = if true && {
  |                   ^ expected if condition here

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
 --> src/main.rs:4:12
  |
4 |     } else { 4 };
  |            ^ expected one of `.`, `;`, `?`, `else`, or an operator

error: could not compile `wtf2` due to 2 previous errors

Ideally the output would refer to either the && or at least that there is an unexpected else or something 🤔

@lcnr lcnr 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 Dec 1, 2021
@FabianWolff
Copy link
Contributor

@rustbot claim

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