about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-10-03 14:14:35 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-10-03 14:14:35 +0200
commitcf19131cb356591d27dded5bdb1d00df1bd077c9 (patch)
treee9c3d623092ce26ff13e7e1b87c7383a569c47a5 /compiler/rustc_parse/src/parser
parentedebf77e0090195bf80c0d8cda821e1bf9d03053 (diff)
downloadrust-cf19131cb356591d27dded5bdb1d00df1bd077c9.tar.gz
rust-cf19131cb356591d27dded5bdb1d00df1bd077c9.zip
Try to recover from a `=>` -> `=` or `->` typo in a match arm
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index c5417ea23f2..e6a0c4c7952 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2322,7 +2322,21 @@ impl<'a> Parser<'a> {
                 None
             };
             let arrow_span = this.token.span;
-            this.expect(&token::FatArrow)?;
+            if let Err(mut err) = this.expect(&token::FatArrow) {
+                // We might have a `=>` -> `=` or `->` typo (issue #89396).
+                if let token::Eq | token::RArrow = this.token.kind {
+                    err.span_suggestion(
+                        this.token.span,
+                        "try using a fat arrow here",
+                        "=>".to_string(),
+                        Applicability::MaybeIncorrect,
+                    );
+                    err.emit();
+                    this.bump();
+                } else {
+                    return Err(err);
+                }
+            }
             let arm_start_span = this.token.span;
 
             let expr = this.parse_expr_res(Restrictions::STMT_EXPR, None).map_err(|mut err| {