Skip to content

Commit

Permalink
rm import.used
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Aug 9, 2024
1 parent 97e7252 commit 7e18a26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
root_span,
root_id,
vis,
used: Default::default(),
});

self.r.indeterminate_imports.push(import);
Expand Down Expand Up @@ -890,8 +889,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
span: item.span,
module_path: Vec::new(),
vis,
used: Cell::new(used.then_some(Used::Other)),
});
used.then(|| self.r.import_used_map.insert(import, Used::Other));
self.r.potentially_unused_imports.push(import);
let imported_binding = self.r.import(binding, import);
if parent == self.r.graph_root {
Expand Down Expand Up @@ -1091,7 +1090,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
span,
module_path: Vec::new(),
vis: ty::Visibility::Restricted(CRATE_DEF_ID),
used: Default::default(),
})
};

Expand Down Expand Up @@ -1256,8 +1254,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
span,
module_path: Vec::new(),
vis,
used: Cell::new(Some(Used::Other)),
});
self.r.import_used_map.insert(import, Used::Other);
let import_binding = self.r.import(binding, import);
self.r.define(self.r.graph_root, ident, MacroNS, import_binding);
} else {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ impl Resolver<'_, '_> {

for import in self.potentially_unused_imports.iter() {
match import.kind {
_ if import.used.get().is_some()
|| import.vis.is_public()
|| import.span.is_dummy() =>
_ if import.vis.is_public()
|| import.span.is_dummy()
|| self.import_used_map.contains_key(import) =>
{
if let ImportKind::MacroUse { .. } = import.kind {
if !import.span.is_dummy() {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ pub(crate) struct ImportData<'a> {
/// The resolution of `module_path`.
pub imported_module: Cell<Option<ModuleOrUniformRoot<'a>>>,
pub vis: ty::Visibility,
pub used: Cell<Option<Used>>,
}

/// All imports are unique and allocated on a same arena,
Expand Down Expand Up @@ -484,7 +483,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
});
self.record_use(target, dummy_binding, Used::Other);
} else if import.imported_module.get().is_none() {
import.used.set(Some(Used::Other));
self.import_used_map.insert(import, Used::Other);
if let Some(id) = import.id() {
self.used_imports.insert(id);
}
Expand Down Expand Up @@ -1347,7 +1346,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// module defined by a block).
// Skip if the import is public or was used through non scope-based resolution,
// e.g. through a module-relative path.
if import.used.get() == Some(Used::Other)
if self.import_used_map.get(&import).copied() == Some(Used::Other)
|| self.effective_visibilities.is_exported(self.local_def_id(id))
{
return false;
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,9 @@ pub struct Resolver<'a, 'tcx> {
partial_res_map: NodeMap<PartialRes>,
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
import_res_map: NodeMap<PerNS<Option<Res>>>,

import_used_map: FxHashMap<Import<'a>, Used>,

/// Resolutions for labels (node IDs of their corresponding blocks or loops).
label_res_map: NodeMap<NodeId>,
/// Resolutions for lifetimes.
Expand Down Expand Up @@ -1422,6 +1425,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
pat_span_map: Default::default(),
partial_res_map: Default::default(),
import_res_map: Default::default(),
import_used_map: Default::default(),
label_res_map: Default::default(),
lifetimes_res_map: Default::default(),
extra_lifetime_params_map: Default::default(),
Expand Down Expand Up @@ -1839,7 +1843,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

/// Test if AmbiguityError ambi is any identical to any one inside ambiguity_errors
fn matches_previous_ambiguity_error(&mut self, ambi: &AmbiguityError<'_>) -> bool {
fn matches_previous_ambiguity_error(&self, ambi: &AmbiguityError<'_>) -> bool {
for ambiguity_error in &self.ambiguity_errors {
// if the span location and ident as well as its span are the same
if ambiguity_error.kind == ambi.kind
Expand Down Expand Up @@ -1900,10 +1904,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}
}
let old_used = import.used.get();
let new_used = Some(used);
if new_used > old_used {
import.used.set(new_used);
let old_used = self.import_used_map.get(&import).copied();
if old_used < Some(used) {
self.import_used_map.insert(import, used);
}
if let Some(id) = import.id() {
self.used_imports.insert(id);
Expand Down

0 comments on commit 7e18a26

Please sign in to comment.