]> git.lizzy.rs Git - rust.git/commitdiff
Use `TokenKind::similar_tokens()`
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>
Mon, 4 Oct 2021 20:13:00 +0000 (22:13 +0200)
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>
Mon, 4 Oct 2021 20:13:00 +0000 (22:13 +0200)
compiler/rustc_ast/src/token.rs
compiler/rustc_parse/src/parser/expr.rs

index 3a65ffe41ae87cbf4c17622dc4b1556c2b231ccf..db066d7c6a5195dd184a711317bd08568bd67c81 100644 (file)
@@ -295,6 +295,7 @@ pub fn similar_tokens(&self) -> Option<Vec<TokenKind>> {
         match *self {
             Comma => Some(vec![Dot, Lt, Semi]),
             Semi => Some(vec![Colon, Comma]),
+            FatArrow => Some(vec![Eq, RArrow]),
             _ => None,
         }
     }
index e6a0c4c79524facf0c03f962ebff68d2f59d71b8..79f46be73f6c27442dca3eec5085ae8461c41ced 100644 (file)
@@ -2324,7 +2324,10 @@ pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm> {
             let arrow_span = this.token.span;
             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 {
+                if TokenKind::FatArrow
+                    .similar_tokens()
+                    .map_or(false, |similar_tokens| similar_tokens.contains(&this.token.kind))
+                {
                     err.span_suggestion(
                         this.token.span,
                         "try using a fat arrow here",