about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCatherine Flores <catherine.3.flores@gmail.com>2025-02-27 19:51:57 +0000
committerGitHub <noreply@github.com>2025-02-27 19:51:57 +0000
commit15180d4eb9dcff9441a8c3ff3382804123c5b0a1 (patch)
treefaf003d0fc41cc929cca9ab561f01b850f8ffda8
parent4a9b8c6415c59ef81c023e1f1de01b7bdb3d9675 (diff)
parent063d6aef0eb8fe81d83a896400c15c6fe9cf0c34 (diff)
downloadrust-15180d4eb9dcff9441a8c3ff3382804123c5b0a1.tar.gz
rust-15180d4eb9dcff9441a8c3ff3382804123c5b0a1.zip
macro_use_import: Don't check is attribute comes from expansion (#14317)
It is not possible to write a declarative macro, that produces an
attribute w/o
an item attached to it. This means that the `check_item` will already
insert the
span in the map, if it came from an expansion. So additionally checking
if the
macro came from an expansion doesn't add anything here. So the
`check_attribute` function, and with that the problematic `attr.span()`
call can
be completely removed.

Fixes https://github.com/rust-lang/rust-clippy/issues/14303

r? @y21

cc @jdonszelmann

changelog: Fix ICE in [`macro_use_import`] lint
-rw-r--r--clippy_lints/src/macro_use.rs5
-rw-r--r--tests/ui/crashes/ice-14303.rs12
2 files changed, 12 insertions, 5 deletions
diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs
index bb6e22d9e5c..68dc1903a24 100644
--- a/clippy_lints/src/macro_use.rs
+++ b/clippy_lints/src/macro_use.rs
@@ -117,11 +117,6 @@ impl LateLintPass<'_> for MacroUseImports {
             self.push_unique_macro_pat_ty(cx, item.span);
         }
     }
-    fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &hir::Attribute) {
-        if attr.span.from_expansion() {
-            self.push_unique_macro(cx, attr.span);
-        }
-    }
     fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
         if expr.span.from_expansion() {
             self.push_unique_macro(cx, expr.span);
diff --git a/tests/ui/crashes/ice-14303.rs b/tests/ui/crashes/ice-14303.rs
new file mode 100644
index 00000000000..e81f29cd7af
--- /dev/null
+++ b/tests/ui/crashes/ice-14303.rs
@@ -0,0 +1,12 @@
+//@check-pass
+#![warn(clippy::macro_use_imports)]
+
+#[repr(transparent)]
+pub struct X(());
+
+#[repr(u8)]
+pub enum Action {
+    Off = 0,
+}
+
+fn main() {}