Skip to content

Commit 7e18a26

Browse files
committed
rm import.used
1 parent 97e7252 commit 7e18a26

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
374374
root_span,
375375
root_id,
376376
vis,
377-
used: Default::default(),
378377
});
379378

380379
self.r.indeterminate_imports.push(import);
@@ -890,8 +889,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
890889
span: item.span,
891890
module_path: Vec::new(),
892891
vis,
893-
used: Cell::new(used.then_some(Used::Other)),
894892
});
893+
used.then(|| self.r.import_used_map.insert(import, Used::Other));
895894
self.r.potentially_unused_imports.push(import);
896895
let imported_binding = self.r.import(binding, import);
897896
if parent == self.r.graph_root {
@@ -1091,7 +1090,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10911090
span,
10921091
module_path: Vec::new(),
10931092
vis: ty::Visibility::Restricted(CRATE_DEF_ID),
1094-
used: Default::default(),
10951093
})
10961094
};
10971095

@@ -1256,8 +1254,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12561254
span,
12571255
module_path: Vec::new(),
12581256
vis,
1259-
used: Cell::new(Some(Used::Other)),
12601257
});
1258+
self.r.import_used_map.insert(import, Used::Other);
12611259
let import_binding = self.r.import(binding, import);
12621260
self.r.define(self.r.graph_root, ident, MacroNS, import_binding);
12631261
} else {

compiler/rustc_resolve/src/check_unused.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ impl Resolver<'_, '_> {
381381

382382
for import in self.potentially_unused_imports.iter() {
383383
match import.kind {
384-
_ if import.used.get().is_some()
385-
|| import.vis.is_public()
386-
|| import.span.is_dummy() =>
384+
_ if import.vis.is_public()
385+
|| import.span.is_dummy()
386+
|| self.import_used_map.contains_key(import) =>
387387
{
388388
if let ImportKind::MacroUse { .. } = import.kind {
389389
if !import.span.is_dummy() {

compiler/rustc_resolve/src/imports.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ pub(crate) struct ImportData<'a> {
176176
/// The resolution of `module_path`.
177177
pub imported_module: Cell<Option<ModuleOrUniformRoot<'a>>>,
178178
pub vis: ty::Visibility,
179-
pub used: Cell<Option<Used>>,
180179
}
181180

182181
/// All imports are unique and allocated on a same arena,
@@ -484,7 +483,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
484483
});
485484
self.record_use(target, dummy_binding, Used::Other);
486485
} else if import.imported_module.get().is_none() {
487-
import.used.set(Some(Used::Other));
486+
self.import_used_map.insert(import, Used::Other);
488487
if let Some(id) = import.id() {
489488
self.used_imports.insert(id);
490489
}
@@ -1347,7 +1346,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13471346
// module defined by a block).
13481347
// Skip if the import is public or was used through non scope-based resolution,
13491348
// e.g. through a module-relative path.
1350-
if import.used.get() == Some(Used::Other)
1349+
if self.import_used_map.get(&import).copied() == Some(Used::Other)
13511350
|| self.effective_visibilities.is_exported(self.local_def_id(id))
13521351
{
13531352
return false;

compiler/rustc_resolve/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,9 @@ pub struct Resolver<'a, 'tcx> {
10161016
partial_res_map: NodeMap<PartialRes>,
10171017
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
10181018
import_res_map: NodeMap<PerNS<Option<Res>>>,
1019+
1020+
import_used_map: FxHashMap<Import<'a>, Used>,
1021+
10191022
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
10201023
label_res_map: NodeMap<NodeId>,
10211024
/// Resolutions for lifetimes.
@@ -1422,6 +1425,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14221425
pat_span_map: Default::default(),
14231426
partial_res_map: Default::default(),
14241427
import_res_map: Default::default(),
1428+
import_used_map: Default::default(),
14251429
label_res_map: Default::default(),
14261430
lifetimes_res_map: Default::default(),
14271431
extra_lifetime_params_map: Default::default(),
@@ -1839,7 +1843,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18391843
}
18401844

18411845
/// Test if AmbiguityError ambi is any identical to any one inside ambiguity_errors
1842-
fn matches_previous_ambiguity_error(&mut self, ambi: &AmbiguityError<'_>) -> bool {
1846+
fn matches_previous_ambiguity_error(&self, ambi: &AmbiguityError<'_>) -> bool {
18431847
for ambiguity_error in &self.ambiguity_errors {
18441848
// if the span location and ident as well as its span are the same
18451849
if ambiguity_error.kind == ambi.kind
@@ -1900,10 +1904,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19001904
}
19011905
}
19021906
}
1903-
let old_used = import.used.get();
1904-
let new_used = Some(used);
1905-
if new_used > old_used {
1906-
import.used.set(new_used);
1907+
let old_used = self.import_used_map.get(&import).copied();
1908+
if old_used < Some(used) {
1909+
self.import_used_map.insert(import, used);
19071910
}
19081911
if let Some(id) = import.id() {
19091912
self.used_imports.insert(id);

0 commit comments

Comments
 (0)