Refactor crate_in_macro_def:

* Don't clone the token stream
* Check the HIR tree before reading attributes
This commit is contained in:
Jason Newcomb 2024-06-09 00:03:20 -04:00
parent 1f530ab7e2
commit d15ec0ff85

View file

@ -53,10 +53,9 @@ declare_lint_pass!(CrateInMacroDef => [CRATE_IN_MACRO_DEF]);
impl EarlyLintPass for CrateInMacroDef {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if item.attrs.iter().any(is_macro_export)
&& let ItemKind::MacroDef(macro_def) = &item.kind
&& let tts = macro_def.body.tokens.clone()
&& let Some(span) = contains_unhygienic_crate_reference(&tts)
if let ItemKind::MacroDef(macro_def) = &item.kind
&& item.attrs.iter().any(is_macro_export)
&& let Some(span) = contains_unhygienic_crate_reference(&macro_def.body.tokens)
{
span_lint_and_sugg(
cx,