Skip to content

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

Closed
@lcnr

Description

@lcnr

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 🤔

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