Skip to content

Commit 02dd264

Browse files
committed
don't lint public exports in unused_import_prefixes
1 parent 5d6c15c commit 02dd264

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

clippy_lints/src/unused_import_prefixes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ impl LateLintPass<'_> for UnusedImportPrefixes {
6666
return;
6767
}
6868

69+
// Do not lint public exports
70+
if cx.tcx.visibility(item.owner_id.def_id).is_public() {
71+
return;
72+
}
73+
6974
// Only check imports starting with the `crate` keyword
7075
if use_path.segments.is_empty() || use_path.segments[0].ident.name != kw::Crate {
7176
return;

tests/ui/unused_import_prefixes.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ mod parent {
1212
// the `crate::` prefix is needed
1313
use crate::mod_one::StructOne;
1414

15+
// don't lint public exports
16+
pub use crate::parent::child::deep::ItemC;
17+
1518
use self::deep::{ItemA, ItemB};
1619
//~^ unused_import_prefixes
1720

@@ -23,6 +26,7 @@ mod parent {
2326
pub struct DeepStruct;
2427
pub struct ItemA;
2528
pub struct ItemB;
29+
pub struct ItemC;
2630
}
2731
}
2832
}

tests/ui/unused_import_prefixes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ mod parent {
1212
// the `crate::` prefix is needed
1313
use crate::mod_one::StructOne;
1414

15+
// don't lint public exports
16+
pub use crate::parent::child::deep::ItemC;
17+
1518
use crate::parent::child::deep::{ItemA, ItemB};
1619
//~^ unused_import_prefixes
1720

@@ -23,6 +26,7 @@ mod parent {
2326
pub struct DeepStruct;
2427
pub struct ItemA;
2528
pub struct ItemB;
29+
pub struct ItemC;
2630
}
2731
}
2832
}

tests/ui/unused_import_prefixes.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ LL | use crate::parent::child::deep::DeepStruct;
88
= help: to override `-D warnings` add `#[allow(clippy::unused_import_prefixes)]`
99

1010
error: redundant `crate::...` prefix in an use statement
11-
--> tests/ui/unused_import_prefixes.rs:15:13
11+
--> tests/ui/unused_import_prefixes.rs:18:13
1212
|
1313
LL | use crate::parent::child::deep::{ItemA, ItemB};
1414
| ^^^^^^^^^^^^^^^^^^^^ help: remove redundant use path prefix: `self`
1515

1616
error: redundant `crate::...` prefix in an use statement
17-
--> tests/ui/unused_import_prefixes.rs:19:13
17+
--> tests/ui/unused_import_prefixes.rs:22:13
1818
|
1919
LL | use crate::parent::child::deep::*;
2020
| ^^^^^^^^^^^^^^^^^^^^ help: remove redundant use path prefix: `self`

0 commit comments

Comments
 (0)