Skip to content

Commit

Permalink
Try to reduce false positives
Browse files Browse the repository at this point in the history
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
  • Loading branch information
sjwang05 and estebank authored Nov 11, 2023
1 parent 1b53936 commit ad088ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,12 @@ impl<'a> Parser<'a> {
let mut err = self.struct_span_err(self.token.span, msg_exp);

// Look for usages of '=>' where '>=' was probably intended
if self.token == token::FatArrow {
if self.token == token::FatArrow
&& expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Le)))
{
err.span_suggestion(
self.token.span,
"you probably meant to write a \"greater than or equal to\" comparison",
"you might have meant to write a \"greater than or equal to\" comparison",
">=",
Applicability::Unspecified,
);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/parser/eq-gt-to-gt-eq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// run-rustfix
// Check that we try to correct `=>` to `>=` in conditions.
#![allow(unused)]

fn main() {
let a = 0;
Expand Down

0 comments on commit ad088ef

Please sign in to comment.