From: Fabian Wolff Date: Mon, 4 Oct 2021 20:13:00 +0000 (+0200) Subject: Use `TokenKind::similar_tokens()` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=079c075f24d2aae84cd6715f350cf56420816f63;p=rust.git Use `TokenKind::similar_tokens()` --- diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 3a65ffe41ae..db066d7c6a5 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -295,6 +295,7 @@ pub fn similar_tokens(&self) -> Option> { match *self { Comma => Some(vec![Dot, Lt, Semi]), Semi => Some(vec![Colon, Comma]), + FatArrow => Some(vec![Eq, RArrow]), _ => None, } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e6a0c4c7952..79f46be73f6 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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",