Skip to content

Commit

Permalink
simplify similar_tokens from Vec<_> to &[_]
Browse files Browse the repository at this point in the history
  • Loading branch information
hkBst committed Jan 23, 2025
1 parent ccb9674 commit 5f01e12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ impl TokenKind {

/// Returns tokens that are likely to be typed accidentally instead of the current token.
/// Enables better error recovery when the wrong token is found.
pub fn similar_tokens(&self) -> Vec<TokenKind> {
pub fn similar_tokens(&self) -> &[TokenKind] {
match self {
Comma => vec![Dot, Lt, Semi],
Semi => vec![Colon, Comma],
Colon => vec![Semi],
FatArrow => vec![Eq, RArrow, Ge, Gt],
_ => vec![],
Comma => &[Dot, Lt, Semi],
Semi => &[Colon, Comma],
Colon => &[Semi],
FatArrow => &[Eq, RArrow, Ge, Gt],
_ => &[],
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3114,8 +3114,8 @@ impl<'a> Parser<'a> {
let span_before_body = this.prev_token.span;
let arm_body;
let is_fat_arrow = this.check(exp!(FatArrow));
let is_almost_fat_arrow = TokenKind::FatArrow
.similar_tokens().contains(&this.token.kind);
let is_almost_fat_arrow =
TokenKind::FatArrow.similar_tokens().contains(&this.token.kind);

// this avoids the compiler saying that a `,` or `}` was expected even though
// the pattern isn't a never pattern (and thus an arm body is required)
Expand Down

0 comments on commit 5f01e12

Please sign in to comment.