Skip to content

Commit 92111dc

Browse files
committed
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
1 parent 0b16881 commit 92111dc

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
3636
| sym::unused_braces
3737
| sym::unused_import_braces
3838
| sym::unused_imports
39+
| sym::redundant_imports
3940
)
4041
{
4142
return;

clippy_utils/src/sym.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ generate! {
261261
read_to_end,
262262
read_to_string,
263263
read_unaligned,
264+
redundant_imports,
264265
redundant_pub_crate,
265266
regex,
266267
rem_euclid,

tests/ui/useless_attribute.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,15 @@ pub mod unknown_namespace {
146146
#[allow(rustc::non_glob_import_of_type_ir_inherent)]
147147
use some_module::SomeType;
148148
}
149+
150+
// Regression test for https://github.com/rust-lang/rust-clippy/issues/15316
151+
pub mod redundant_imports_issue {
152+
macro_rules! empty {
153+
() => {};
154+
}
155+
156+
#[expect(redundant_imports)]
157+
pub(crate) use empty;
158+
159+
empty!();
160+
}

tests/ui/useless_attribute.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,15 @@ pub mod unknown_namespace {
146146
#[allow(rustc::non_glob_import_of_type_ir_inherent)]
147147
use some_module::SomeType;
148148
}
149+
150+
// Regression test for https://github.com/rust-lang/rust-clippy/issues/15316
151+
pub mod redundant_imports_issue {
152+
macro_rules! empty {
153+
() => {};
154+
}
155+
156+
#[expect(redundant_imports)]
157+
pub(crate) use empty;
158+
159+
empty!();
160+
}

0 commit comments

Comments
 (0)