Rollup merge of #129065 - nnethercote:PartialEq-TokenKind, r=spastorino

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.

r? `@spastorino`
This commit is contained in:
Matthias Krüger 2024-08-15 19:32:35 +02:00 committed by GitHub
commit bb63d75ac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 122 additions and 129 deletions

View file

@ -470,7 +470,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
});
// Find both the last lint declaration (declare_clippy_lint!) and the lint pass impl
while let Some(LintDeclSearchResult { content, .. }) = iter.find(|result| result.token_kind == TokenKind::Ident) {
while let Some(LintDeclSearchResult { content, .. }) = iter.find(|result| result.token == TokenKind::Ident) {
let mut iter = iter
.by_ref()
.filter(|t| !matches!(t.token_kind, TokenKind::Whitespace | TokenKind::LineComment { .. }));
@ -480,7 +480,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
// matches `!{`
match_tokens!(iter, Bang OpenBrace);
if let Some(LintDeclSearchResult { range, .. }) =
iter.find(|result| result.token_kind == TokenKind::CloseBrace)
iter.find(|result| result.token == TokenKind::CloseBrace)
{
last_decl_curly_offset = Some(range.end);
}

View file

@ -84,9 +84,7 @@ pub(crate) struct ParsedMacroArgs {
fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
for &keyword in RUST_KW.iter() {
if parser.token.is_keyword(keyword)
&& parser.look_ahead(1, |t| {
t.kind == TokenKind::Eof || t.kind == TokenKind::Comma
})
&& parser.look_ahead(1, |t| *t == TokenKind::Eof || *t == TokenKind::Comma)
{
parser.bump();
return Some(MacroArg::Keyword(
@ -131,7 +129,7 @@ pub(crate) fn parse_macro_args(
Some(arg) => {
args.push(arg);
parser.bump();
if parser.token.kind == TokenKind::Eof && args.len() == 2 {
if parser.token == TokenKind::Eof && args.len() == 2 {
vec_with_semi = true;
break;
}
@ -150,7 +148,7 @@ pub(crate) fn parse_macro_args(
parser.bump();
if parser.token.kind == TokenKind::Eof {
if parser.token == TokenKind::Eof {
trailing_comma = true;
break;
}