Skip to content

Commit 3e8e8d2

Browse files
Rollup merge of rust-lang#88238 - m-ou-se:used-imports-no-track-namespace, r=estebank
Stop tracking namespace in used_imports. This changes `used_imports` from a `FxHashSet<(NodeId, Namespace)>` to a `FxHashSet<NodeId>`, as the Namespace information isn't used. The only point that uses it did three lookups, `|=`'ing them together. r? `@estebank`
2 parents 518b27b + abab99e commit 3e8e8d2

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

compiler/rustc_resolve/src/check_unused.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
6363
// We have information about whether `use` (import) items are actually
6464
// used now. If an import is not used at all, we signal a lint error.
6565
fn check_import(&mut self, id: ast::NodeId) {
66-
let mut used = false;
67-
self.r.per_ns(|this, ns| used |= this.used_imports.contains(&(id, ns)));
66+
let used = self.r.used_imports.contains(&id);
6867
let def_id = self.r.local_def_id(id);
6968
if !used {
7069
if self.r.maybe_unused_trait_imports.contains(&def_id) {

compiler/rustc_resolve/src/imports.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a> Resolver<'a> {
303303
if self.last_import_segment && check_usable(self, binding).is_err() {
304304
Err((Determined, Weak::No))
305305
} else {
306-
self.record_use(ident, ns, binding, restricted_shadowing);
306+
self.record_use(ident, binding, restricted_shadowing);
307307

308308
if let Some(shadowed_glob) = resolution.shadowed_glob {
309309
// Forbid expanded shadowing to avoid time travel.
@@ -609,9 +609,9 @@ impl<'a> Resolver<'a> {
609609
self.per_ns(|this, ns| {
610610
let key = this.new_key(target, ns);
611611
let _ = this.try_define(import.parent_scope.module, key, dummy_binding);
612-
// Consider erroneous imports used to avoid duplicate diagnostics.
613-
this.record_use(target, ns, dummy_binding, false);
614612
});
613+
// Consider erroneous imports used to avoid duplicate diagnostics.
614+
self.record_use(target, dummy_binding, false);
615615
}
616616
}
617617
}
@@ -709,7 +709,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
709709
}
710710
} else if is_indeterminate {
711711
// Consider erroneous imports used to avoid duplicate diagnostics.
712-
self.r.used_imports.insert((import.id, TypeNS));
712+
self.r.used_imports.insert(import.id);
713713
let path = import_path_to_string(
714714
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
715715
&import.kind,
@@ -902,7 +902,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
902902
import.vis.set(orig_vis);
903903
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
904904
// Consider erroneous imports used to avoid duplicate diagnostics.
905-
self.r.used_imports.insert((import.id, TypeNS));
905+
self.r.used_imports.insert(import.id);
906906
}
907907
let module = match path_res {
908908
PathResult::Module(module) => {
@@ -1043,7 +1043,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
10431043
{
10441044
this.record_use(
10451045
ident,
1046-
ns,
10471046
target_binding,
10481047
import.module_path.is_empty(),
10491048
);

compiler/rustc_resolve/src/late.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
17381738
// whether they can be shadowed by fresh bindings or not, so force an error.
17391739
// issues/33118#issuecomment-233962221 (see below) still applies here,
17401740
// but we have to ignore it for backward compatibility.
1741-
self.r.record_use(ident, ValueNS, binding, false);
1741+
self.r.record_use(ident, binding, false);
17421742
return None;
17431743
}
17441744
LexicalScopeBinding::Item(binding) => (binding.res(), Some(binding)),
@@ -1753,7 +1753,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
17531753
) if is_syntactic_ambiguity => {
17541754
// Disambiguate in favor of a unit struct/variant or constant pattern.
17551755
if let Some(binding) = binding {
1756-
self.r.record_use(ident, ValueNS, binding, false);
1756+
self.r.record_use(ident, binding, false);
17571757
}
17581758
Some(res)
17591759
}

compiler/rustc_resolve/src/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ pub struct Resolver<'a> {
942942
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
943943
/// Visibilities in "lowered" form, for all entities that have them.
944944
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
945-
used_imports: FxHashSet<(NodeId, Namespace)>,
945+
used_imports: FxHashSet<NodeId>,
946946
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
947947
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
948948

@@ -1656,7 +1656,6 @@ impl<'a> Resolver<'a> {
16561656
fn record_use(
16571657
&mut self,
16581658
ident: Ident,
1659-
ns: Namespace,
16601659
used_binding: &'a NameBinding<'a>,
16611660
is_lexical_scope: bool,
16621661
) {
@@ -1684,9 +1683,9 @@ impl<'a> Resolver<'a> {
16841683
}
16851684
used.set(true);
16861685
import.used.set(true);
1687-
self.used_imports.insert((import.id, ns));
1686+
self.used_imports.insert(import.id);
16881687
self.add_to_glob_map(&import, ident);
1689-
self.record_use(ident, ns, binding, false);
1688+
self.record_use(ident, binding, false);
16901689
}
16911690
}
16921691

@@ -3241,7 +3240,7 @@ impl<'a> Resolver<'a> {
32413240
self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| {
32423241
if let Some(binding) = entry.extern_crate_item {
32433242
if !speculative && entry.introduced_by_item {
3244-
self.record_use(ident, TypeNS, binding, false);
3243+
self.record_use(ident, binding, false);
32453244
}
32463245
Some(binding)
32473246
} else {
@@ -3428,7 +3427,7 @@ impl<'a> Resolver<'a> {
34283427
let is_import = name_binding.is_import();
34293428
let span = name_binding.span;
34303429
if let Res::Def(DefKind::Fn, _) = res {
3431-
self.record_use(ident, ValueNS, name_binding, false);
3430+
self.record_use(ident, name_binding, false);
34323431
}
34333432
self.main_def = Some(MainDefinition { res, is_import, span });
34343433
}

compiler/rustc_resolve/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ impl<'a> Resolver<'a> {
10901090
) {
10911091
Ok(binding) => {
10921092
let initial_res = initial_binding.map(|initial_binding| {
1093-
self.record_use(ident, MacroNS, initial_binding, false);
1093+
self.record_use(ident, initial_binding, false);
10941094
initial_binding.res()
10951095
});
10961096
let res = binding.res();

0 commit comments

Comments
 (0)