simplify similar_tokens from Vec<_> to &[_]
This commit is contained in:
parent
ccb967438d
commit
5f01e12ea8
2 changed files with 8 additions and 8 deletions
|
@ -527,13 +527,13 @@ impl TokenKind {
|
||||||
|
|
||||||
/// Returns tokens that are likely to be typed accidentally instead of the current token.
|
/// Returns tokens that are likely to be typed accidentally instead of the current token.
|
||||||
/// Enables better error recovery when the wrong token is found.
|
/// 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 {
|
match self {
|
||||||
Comma => vec![Dot, Lt, Semi],
|
Comma => &[Dot, Lt, Semi],
|
||||||
Semi => vec![Colon, Comma],
|
Semi => &[Colon, Comma],
|
||||||
Colon => vec![Semi],
|
Colon => &[Semi],
|
||||||
FatArrow => vec![Eq, RArrow, Ge, Gt],
|
FatArrow => &[Eq, RArrow, Ge, Gt],
|
||||||
_ => vec![],
|
_ => &[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3114,8 +3114,8 @@ impl<'a> Parser<'a> {
|
||||||
let span_before_body = this.prev_token.span;
|
let span_before_body = this.prev_token.span;
|
||||||
let arm_body;
|
let arm_body;
|
||||||
let is_fat_arrow = this.check(exp!(FatArrow));
|
let is_fat_arrow = this.check(exp!(FatArrow));
|
||||||
let is_almost_fat_arrow = TokenKind::FatArrow
|
let is_almost_fat_arrow =
|
||||||
.similar_tokens().contains(&this.token.kind);
|
TokenKind::FatArrow.similar_tokens().contains(&this.token.kind);
|
||||||
|
|
||||||
// this avoids the compiler saying that a `,` or `}` was expected even though
|
// 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)
|
// the pattern isn't a never pattern (and thus an arm body is required)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue