Skip to content

Detect >= to => typo in comparisons #117245

Closed
@estebank

Description

@estebank

When encountering code like if 42 => 2 {}, we currently emit

error: expected `{`, found `=>`
 --> src/main.rs:2:10
  |
2 |    if 42 => 2 {}
  |          ^^ expected `{`
  |
note: the `if` expression is missing a block after this condition
 --> src/main.rs:2:7
  |
2 |    if 42 => 2 {}
  |       ^^

But it should be closer to

error: expected `{`, found `=>`
 --> src/main.rs:2:10
  |
2 |    if 42 => 2 {}
  |          ^^ expected `{`
  |
note: you likely meant to write a "greater than or equal to" comparison
 --> src/main.rs:2:7
  |
2 -    if 42 => 2 {}
2 +    if 42 >= 2 {}
  |

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTP-lowLow priorityT-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