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

@ -162,7 +162,7 @@ impl<'a> Parser<'a> {
}
loop {
// skip any other attributes, we want the item
if snapshot.token.kind == token::Pound {
if snapshot.token == token::Pound {
if let Err(err) = snapshot.parse_attribute(InnerAttrPolicy::Permitted) {
err.cancel();
return Some(replacement_span);
@ -343,7 +343,7 @@ impl<'a> Parser<'a> {
// Presumably, the majority of the time there will only be one attr.
let mut expanded_attrs = Vec::with_capacity(1);
while self.token.kind != token::Eof {
while self.token != token::Eof {
let lo = self.token.span;
let item = self.parse_attr_item(ForceCollect::Yes)?;
expanded_attrs.push((item, lo.to(self.prev_token.span)));
@ -359,7 +359,7 @@ impl<'a> Parser<'a> {
pub(crate) fn parse_meta_seq_top(&mut self) -> PResult<'a, ThinVec<ast::NestedMetaItem>> {
// Presumably, the majority of the time there will only be one attr.
let mut nmis = ThinVec::with_capacity(1);
while self.token.kind != token::Eof {
while self.token != token::Eof {
nmis.push(self.parse_meta_item_inner()?);
if !self.eat(&token::Comma) {
break;