Use impl PartialEq<TokenKind> for Token more.

This lets us compare a `Token` with a `TokenKind`. It's used a lot, but
can be used even more, avoiding the need for some `.kind` uses.
This commit is contained in:
Nicholas Nethercote
2024-08-09 17:44:47 +10:00
parent bbcfd90cd1
commit 7923b20dd9
16 changed files with 121 additions and 128 deletions

View File

@@ -358,9 +358,9 @@ impl<'a> Parser<'a> {
})?;
let span = lo.to(self.prev_token.span);
AngleBracketedArgs { args, span }.into()
} else if self.token.kind == token::OpenDelim(Delimiter::Parenthesis)
} else if self.token == token::OpenDelim(Delimiter::Parenthesis)
// FIXME(return_type_notation): Could also recover `...` here.
&& self.look_ahead(1, |tok| tok.kind == token::DotDot)
&& self.look_ahead(1, |t| *t == token::DotDot)
{
self.bump(); // (
self.bump(); // ..
@@ -384,7 +384,7 @@ impl<'a> Parser<'a> {
let token_before_parsing = self.token.clone();
let mut snapshot = None;
if self.may_recover()
&& prev_token_before_parsing.kind == token::PathSep
&& prev_token_before_parsing == token::PathSep
&& (style == PathStyle::Expr && self.token.can_begin_expr()
|| style == PathStyle::Pat && self.token.can_begin_pattern())
{
@@ -393,7 +393,7 @@ impl<'a> Parser<'a> {
let (inputs, _) = match self.parse_paren_comma_seq(|p| p.parse_ty()) {
Ok(output) => output,
Err(mut error) if prev_token_before_parsing.kind == token::PathSep => {
Err(mut error) if prev_token_before_parsing == token::PathSep => {
error.span_label(
prev_token_before_parsing.span.to(token_before_parsing.span),
"while parsing this parenthesized list of type arguments starting here",