Skip to content

Commit 04f9957

Browse files
committed
Show => help only if operator expected.
1 parent cc6c774 commit 04f9957

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ impl<'a> Parser<'a> {
606606
&& expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Gt)))
607607
{
608608
err.span_label(self.prev_token.span, "maybe try to close unmatched angle bracket");
609-
} else if self.token == token::FatArrow {
609+
} else if self.token == token::FatArrow
610+
&& expected.iter().any(|tok| matches!(tok, TokenType::Operator))
611+
{
610612
err.help("closures are written `|a, b| a + b` and greater-than-or-equal is `>=`.");
611613
}
612614

src/test/ui/asm/x86_64/parse-error.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
5757
|
5858
LL | asm!("{}", in(reg) foo => bar);
5959
| ^^ expected one of 7 possible tokens
60+
|
61+
= help: closures are written `|a, b| a + b` and greater-than-or-equal is `>=`.
6062

6163
error: expected a path for argument to `sym`
6264
--> $DIR/parse-error.rs:31:24

src/test/ui/missing/missing-comma-in-match.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | &None => 1
55
| - help: missing a comma here to end this `match` arm
66
LL | &Some(2) => { 3 }
77
| ^^ expected one of `,`, `.`, `?`, `}`, or an operator
8+
|
9+
= help: closures are written `|a, b| a + b` and greater-than-or-equal is `>=`.
810

911
error: aborting due to previous error
1012

0 commit comments

Comments
 (0)