Skip to content

Commit d4dea4b

Browse files
authored
Fix false positive in useless_attribute with redundant_imports (#15318)
Fix false positive in `useless_attribute` with `redundant_imports` Add `redundant_imports` to the list of allowed lints on use items to prevent `useless_attribute` from triggering false positives when `#[expect(redundant_imports)]` or similar attributes are used on use statements. fixes #15316 --- changelog: [`useless_attribute`]: fix false positive when using `#[expect(redundant_imports)]` and similar lint attributes on `use` statements
2 parents 0b16881 + 92111dc commit d4dea4b

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)