File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
1010error: 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 |
1313LL | use crate::parent::child::deep::{ItemA, ItemB};
1414 | ^^^^^^^^^^^^^^^^^^^^ help: remove redundant use path prefix: `self`
1515
1616error: 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 |
1919LL | use crate::parent::child::deep::*;
2020 | ^^^^^^^^^^^^^^^^^^^^ help: remove redundant use path prefix: `self`
You can’t perform that action at this time.
0 commit comments