Skip to content

Commit 544ab0b

Browse files
committed
report unused_import for empty reexports even it is pub
1 parent e4a361a commit 544ab0b

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
173173
self.base_use_tree = Some(use_tree);
174174
}
175175

176-
if self.base_use_is_pub {
176+
if self.base_use_is_pub && !self.r.empty_glob_reexports.contains(&id) {
177177
self.check_import_as_underscore(use_tree, id);
178178
return;
179179
}

compiler/rustc_resolve/src/imports.rs

+4
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
987987
candidates: None,
988988
});
989989
}
990+
991+
if self.resolutions(module).borrow().is_empty() {
992+
self.empty_glob_reexports.insert(id);
993+
}
990994
}
991995
if !is_prelude
992996
&& let Some(max_vis) = max_vis.get()

compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,9 @@ pub struct Resolver<'a, 'tcx> {
11081108
/// Whether lifetime elision was successful.
11091109
lifetime_elision_allowed: FxHashSet<NodeId>,
11101110

1111+
/// These glob imports which doesn't has any reexports
1112+
empty_glob_reexports: FxHashSet<NodeId>,
1113+
11111114
/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
11121115
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>>,
11131116

@@ -1336,6 +1339,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13361339
determined_imports: Vec::new(),
13371340
indeterminate_imports: Vec::new(),
13381341

1342+
empty_glob_reexports: Default::default(),
1343+
13391344
pat_span_map: Default::default(),
13401345
partial_res_map: Default::default(),
13411346
import_res_map: Default::default(),
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![deny(unused_imports)]
2+
3+
mod a {}
4+
5+
pub use a::*;
6+
//~^ ERROR: unused import: `a::*`
7+
8+
mod b {
9+
mod c {
10+
#[derive(Clone)]
11+
pub struct D;
12+
}
13+
pub use self::c::*; // don't show unused import lint
14+
}
15+
16+
pub use b::*; // don't show unused import lint
17+
18+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused import: `a::*`
2+
--> $DIR/pub-reexport-empty.rs:5:9
3+
|
4+
LL | pub use a::*;
5+
| ^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/pub-reexport-empty.rs:1:9
9+
|
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)