diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index acf892cec532..20447fa07cad 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -606,6 +606,10 @@ impl<'a> Parser<'a> { && expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Gt))) { err.span_label(self.prev_token.span, "maybe try to close unmatched angle bracket"); + } else if self.token == token::FatArrow + && expected.iter().any(|tok| matches!(tok, TokenType::Operator)) + { + err.help("closures are written `|a, b| a + b` and greater-than-or-equal is `>=`."); } let sp = if self.token == token::Eof { diff --git a/src/test/ui/asm/x86_64/parse-error.stderr b/src/test/ui/asm/x86_64/parse-error.stderr index 1fd317a96a8a..5c176f93a434 100644 --- a/src/test/ui/asm/x86_64/parse-error.stderr +++ b/src/test/ui/asm/x86_64/parse-error.stderr @@ -57,6 +57,8 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>` | LL | asm!("{}", in(reg) foo => bar); | ^^ expected one of 7 possible tokens + | + = help: closures are written `|a, b| a + b` and greater-than-or-equal is `>=`. error: expected a path for argument to `sym` --> $DIR/parse-error.rs:31:24 diff --git a/src/test/ui/missing/missing-comma-in-match.stderr b/src/test/ui/missing/missing-comma-in-match.stderr index fe210f697c44..58897a499e8c 100644 --- a/src/test/ui/missing/missing-comma-in-match.stderr +++ b/src/test/ui/missing/missing-comma-in-match.stderr @@ -5,6 +5,8 @@ LL | &None => 1 | - help: missing a comma here to end this `match` arm LL | &Some(2) => { 3 } | ^^ expected one of `,`, `.`, `?`, `}`, or an operator + | + = help: closures are written `|a, b| a + b` and greater-than-or-equal is `>=`. error: aborting due to previous error diff --git a/src/test/ui/unexpected-fat-arrow.rs b/src/test/ui/unexpected-fat-arrow.rs new file mode 100644 index 000000000000..88e19395da7b --- /dev/null +++ b/src/test/ui/unexpected-fat-arrow.rs @@ -0,0 +1,5 @@ +fn main() { + // JavaScript-style arrow function. + let _lambda = (a, b) => { println!(); a + b }; +//~^ ERROR expected one of `.`, `;`, `?`, `else`, or an operator, found `=>` +} diff --git a/src/test/ui/unexpected-fat-arrow.stderr b/src/test/ui/unexpected-fat-arrow.stderr new file mode 100644 index 000000000000..2922c373a2af --- /dev/null +++ b/src/test/ui/unexpected-fat-arrow.stderr @@ -0,0 +1,10 @@ +error: expected one of `.`, `;`, `?`, `else`, or an operator, found `=>` + --> $DIR/unexpected-fat-arrow.rs:3:26 + | +LL | let _lambda = (a, b) => { println!(); a + b }; + | ^^ expected one of `.`, `;`, `?`, `else`, or an operator + | + = help: closures are written `|a, b| a + b` and greater-than-or-equal is `>=`. + +error: aborting due to previous error +