about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKrishna Ketan Rai <prafulrai522@gmail.com>2025-07-21 17:13:43 +0530
committerKrishna Ketan Rai <prafulrai522@gmail.com>2025-07-21 17:13:43 +0530
commit92111dcc67a4f19c6a6e8f22633b2f88f64ed6bb (patch)
treef6120e5215b8a1b29930666c191c3f1b7407fb78
parent0b168815a46bd8132871b909405bf15f12a5438c (diff)
downloadrust-92111dcc67a4f19c6a6e8f22633b2f88f64ed6bb.tar.gz
rust-92111dcc67a4f19c6a6e8f22633b2f88f64ed6bb.zip
Fix false positive in useless_attribute with redundant_imports
The useless_attribute lint was incorrectly flagging #[expect(redundant_imports)]
as useless when applied to macro re-exports. This occurred because the lint
didn't recognize 'redundant_imports' as a valid rustc lint name.

This commit:
- Adds 'redundant_imports' to the list of known rustc lints in sym.rs
- Updates the useless_attribute lint to properly handle this case
- Adds a regression test to prevent future false positives
-rw-r--r--clippy_lints/src/attrs/useless_attribute.rs1
-rw-r--r--clippy_utils/src/sym.rs1
-rw-r--r--tests/ui/useless_attribute.fixed12
-rw-r--r--tests/ui/useless_attribute.rs12
4 files changed, 26 insertions, 0 deletions
diff --git a/clippy_lints/src/attrs/useless_attribute.rs b/clippy_lints/src/attrs/useless_attribute.rs
index 4059f9603c3..b9b5cedb5aa 100644
--- a/clippy_lints/src/attrs/useless_attribute.rs
+++ b/clippy_lints/src/attrs/useless_attribute.rs
@@ -36,6 +36,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
                                     | sym::unused_braces
                                     | sym::unused_import_braces
                                     | sym::unused_imports
+                                    | sym::redundant_imports
                             )
                         {
                             return;
diff --git a/clippy_utils/src/sym.rs b/clippy_utils/src/sym.rs
index 8a8218c6976..eee2cef2aaf 100644
--- a/clippy_utils/src/sym.rs
+++ b/clippy_utils/src/sym.rs
@@ -261,6 +261,7 @@ generate! {
     read_to_end,
     read_to_string,
     read_unaligned,
+    redundant_imports,
     redundant_pub_crate,
     regex,
     rem_euclid,
diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed
index a96c8f46f55..830aa3c976f 100644
--- a/tests/ui/useless_attribute.fixed
+++ b/tests/ui/useless_attribute.fixed
@@ -146,3 +146,15 @@ pub mod unknown_namespace {
     #[allow(rustc::non_glob_import_of_type_ir_inherent)]
     use some_module::SomeType;
 }
+
+// Regression test for https://github.com/rust-lang/rust-clippy/issues/15316
+pub mod redundant_imports_issue {
+    macro_rules! empty {
+        () => {};
+    }
+
+    #[expect(redundant_imports)]
+    pub(crate) use empty;
+
+    empty!();
+}
diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs
index b26410134bb..14c69ccf2ed 100644
--- a/tests/ui/useless_attribute.rs
+++ b/tests/ui/useless_attribute.rs
@@ -146,3 +146,15 @@ pub mod unknown_namespace {
     #[allow(rustc::non_glob_import_of_type_ir_inherent)]
     use some_module::SomeType;
 }
+
+// Regression test for https://github.com/rust-lang/rust-clippy/issues/15316
+pub mod redundant_imports_issue {
+    macro_rules! empty {
+        () => {};
+    }
+
+    #[expect(redundant_imports)]
+    pub(crate) use empty;
+
+    empty!();
+}