Skip to content

Commit

Permalink
report unused_import for empty reexports even it is pub
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Sep 23, 2023
1 parent 136d74f commit b295ec6
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ mod arg_matrix;
mod checks;
mod suggestions;

pub use _impl::*;
use rustc_errors::ErrorGuaranteed;
pub use suggestions::*;

use crate::coercion::DynamicCoerceMany;
use crate::{Diverges, EnclosingBreakables, Inherited};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
self.base_use_tree = Some(use_tree);
}

if self.base_use_is_pub {
if self.base_use_is_pub && !self.r.empty_glob_reexports.contains(&id) {
self.check_import_as_underscore(use_tree, id);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
candidates: None,
});
}

if max_vis.get().is_none() {
self.empty_glob_reexports.insert(id);
}
}
if !is_prelude
&& let Some(max_vis) = max_vis.get()
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ pub struct Resolver<'a, 'tcx> {
/// Whether lifetime elision was successful.
lifetime_elision_allowed: FxHashSet<NodeId>,

/// These glob imports which doesn't has any reexports
empty_glob_reexports: FxHashSet<NodeId>,

/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>>,

Expand Down Expand Up @@ -1336,6 +1339,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
determined_imports: Vec::new(),
indeterminate_imports: Vec::new(),

empty_glob_reexports: Default::default(),

pat_span_map: Default::default(),
partial_res_map: Default::default(),
import_res_map: Default::default(),
Expand Down
1 change: 0 additions & 1 deletion library/portable-simd/crates/core_simd/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ pub mod simd {
pub use crate::core_simd::masks::*;
pub use crate::core_simd::ord::*;
pub use crate::core_simd::swizzle::*;
pub use crate::core_simd::swizzle_dyn::*;
pub use crate::core_simd::vector::*;
}
25 changes: 25 additions & 0 deletions tests/ui/imports/pub-reexport-empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![deny(unused_imports)]

mod a {}

pub use a::*;
//~^ ERROR: unused import: `a::*`

mod b {
mod c {
#[derive(Clone)]
pub struct D;
}
pub use self::c::*; // don't show unused import lint
}

pub use b::*; // don't show unused import lint

mod d {
const D: i32 = 1;
}

pub use d::*;
//~^ ERROR: unused import: `d::*`

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/imports/pub-reexport-empty.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unused import: `a::*`
--> $DIR/pub-reexport-empty.rs:5:9
|
LL | pub use a::*;
| ^^^^
|
note: the lint level is defined here
--> $DIR/pub-reexport-empty.rs:1:9
|
LL | #![deny(unused_imports)]
| ^^^^^^^^^^^^^^

error: unused import: `d::*`
--> $DIR/pub-reexport-empty.rs:22:9
|
LL | pub use d::*;
| ^^^^

error: aborting due to 2 previous errors

0 comments on commit b295ec6

Please sign in to comment.