Skip to content

Commit 5f01e12

Browse files
committed
simplify similar_tokens from Vec<_> to &[_]
1 parent ccb9674 commit 5f01e12

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: compiler/rustc_ast/src/token.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,13 @@ impl TokenKind {
527527

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

Diff for: compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3114,8 +3114,8 @@ impl<'a> Parser<'a> {
31143114
let span_before_body = this.prev_token.span;
31153115
let arm_body;
31163116
let is_fat_arrow = this.check(exp!(FatArrow));
3117-
let is_almost_fat_arrow = TokenKind::FatArrow
3118-
.similar_tokens().contains(&this.token.kind);
3117+
let is_almost_fat_arrow =
3118+
TokenKind::FatArrow.similar_tokens().contains(&this.token.kind);
31193119

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

0 commit comments

Comments
 (0)