1
Fork 0

Make sure we don't deny macro vars w keyword names

This commit is contained in:
Michael Goulet 2024-05-07 19:13:33 -04:00
parent 14081a255d
commit 1d9d6715ae
8 changed files with 70 additions and 34 deletions

View file

@ -40,6 +40,7 @@ use crate::{
},
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
};
use ast::token::TokenKind;
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::visit::{FnCtxt, FnKind};
use rustc_ast::{self as ast, *};
@ -1869,16 +1870,24 @@ struct UnderMacro(bool);
impl KeywordIdents {
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: &TokenStream) {
// Check if the preceding token is `$`, because we want to allow `$async`, etc.
let mut prev_dollar = false;
for tt in tokens.trees() {
match tt {
// Only report non-raw idents.
TokenTree::Token(token, _) => {
if let Some((ident, token::IdentIsRaw::No)) = token.ident() {
self.check_ident_token(cx, UnderMacro(true), ident);
if !prev_dollar {
self.check_ident_token(cx, UnderMacro(true), ident);
}
} else if token.kind == TokenKind::Dollar {
prev_dollar = true;
continue;
}
}
TokenTree::Delimited(.., tts) => self.check_tokens(cx, tts),
}
prev_dollar = false;
}
}