Rollup merge of #124869 - compiler-errors:keyword, r=Nilstrieb
Make sure we don't deny macro vars w keyword names `$async:ident`, etc are all valid. Fixes #124862
This commit is contained in:
commit
952f12ea7a
8 changed files with 70 additions and 34 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue