Skip to content

Commit b295ec6

Browse files
committed
report unused_import for empty reexports even it is pub
1 parent 136d74f commit b295ec6

File tree

7 files changed

+55
-4
lines changed

7 files changed

+55
-4
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ mod arg_matrix;
44
mod checks;
55
mod suggestions;
66

7-
pub use _impl::*;
87
use rustc_errors::ErrorGuaranteed;
9-
pub use suggestions::*;
108

119
use crate::coercion::DynamicCoerceMany;
1210
use crate::{Diverges, EnclosingBreakables, Inherited};

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 max_vis.get().is_none() {
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(),

library/portable-simd/crates/core_simd/src/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ pub mod simd {
3535
pub use crate::core_simd::masks::*;
3636
pub use crate::core_simd::ord::*;
3737
pub use crate::core_simd::swizzle::*;
38-
pub use crate::core_simd::swizzle_dyn::*;
3938
pub use crate::core_simd::vector::*;
4039
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
mod d {
19+
const D: i32 = 1;
20+
}
21+
22+
pub use d::*;
23+
//~^ ERROR: unused import: `d::*`
24+
25+
fn main() {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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: unused import: `d::*`
14+
--> $DIR/pub-reexport-empty.rs:22:9
15+
|
16+
LL | pub use d::*;
17+
| ^^^^
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)