about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2024-06-09 00:03:20 -0400
committerJason Newcomb <jsnewcomb@pm.me>2024-07-05 03:03:56 -0400
commitd15ec0ff852f8e1befc34e83dc2865b78f506898 (patch)
tree1c56b2e98adae75161adcb166a95b12542ceabb0
parent1f530ab7e2bd74efdfc5c0ac7f1c0d9f8df8c029 (diff)
downloadrust-d15ec0ff852f8e1befc34e83dc2865b78f506898.tar.gz
rust-d15ec0ff852f8e1befc34e83dc2865b78f506898.zip
Refactor `crate_in_macro_def`:
* Don't clone the token stream
* Check the HIR tree before reading attributes
-rw-r--r--clippy_lints/src/crate_in_macro_def.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs
index adf6f7c4737..678bdbc0ffb 100644
--- a/clippy_lints/src/crate_in_macro_def.rs
+++ b/clippy_lints/src/crate_in_macro_def.rs
@@ -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,