1
Fork 0

Stop tracking namespce in used_imports.

The information was tracked, but unused.
This commit is contained in:
Mara Bos 2021-08-22 16:50:59 +02:00
parent e7f7fe462a
commit abab99e02b
5 changed files with 14 additions and 17 deletions

View file

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

View file

@ -303,7 +303,7 @@ impl<'a> Resolver<'a> {
if self.last_import_segment && check_usable(self, binding).is_err() { if self.last_import_segment && check_usable(self, binding).is_err() {
Err((Determined, Weak::No)) Err((Determined, Weak::No))
} else { } else {
self.record_use(ident, ns, binding, restricted_shadowing); self.record_use(ident, binding, restricted_shadowing);
if let Some(shadowed_glob) = resolution.shadowed_glob { if let Some(shadowed_glob) = resolution.shadowed_glob {
// Forbid expanded shadowing to avoid time travel. // Forbid expanded shadowing to avoid time travel.
@ -609,9 +609,9 @@ impl<'a> Resolver<'a> {
self.per_ns(|this, ns| { self.per_ns(|this, ns| {
let key = this.new_key(target, ns); let key = this.new_key(target, ns);
let _ = this.try_define(import.parent_scope.module, key, dummy_binding); let _ = this.try_define(import.parent_scope.module, key, dummy_binding);
// Consider erroneous imports used to avoid duplicate diagnostics.
this.record_use(target, ns, dummy_binding, false);
}); });
// Consider erroneous imports used to avoid duplicate diagnostics.
self.record_use(target, dummy_binding, false);
} }
} }
} }
@ -709,7 +709,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
} }
} else if is_indeterminate { } else if is_indeterminate {
// Consider erroneous imports used to avoid duplicate diagnostics. // Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((import.id, TypeNS)); self.r.used_imports.insert(import.id);
let path = import_path_to_string( let path = import_path_to_string(
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(), &import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
&import.kind, &import.kind,
@ -902,7 +902,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
import.vis.set(orig_vis); import.vis.set(orig_vis);
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res { if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
// Consider erroneous imports used to avoid duplicate diagnostics. // Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((import.id, TypeNS)); self.r.used_imports.insert(import.id);
} }
let module = match path_res { let module = match path_res {
PathResult::Module(module) => { PathResult::Module(module) => {
@ -1043,7 +1043,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
{ {
this.record_use( this.record_use(
ident, ident,
ns,
target_binding, target_binding,
import.module_path.is_empty(), import.module_path.is_empty(),
); );

View file

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

View file

@ -942,7 +942,7 @@ pub struct Resolver<'a> {
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>, glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
/// Visibilities in "lowered" form, for all entities that have them. /// Visibilities in "lowered" form, for all entities that have them.
visibilities: FxHashMap<LocalDefId, ty::Visibility>, visibilities: FxHashMap<LocalDefId, ty::Visibility>,
used_imports: FxHashSet<(NodeId, Namespace)>, used_imports: FxHashSet<NodeId>,
maybe_unused_trait_imports: FxHashSet<LocalDefId>, maybe_unused_trait_imports: FxHashSet<LocalDefId>,
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>, maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
@ -1656,7 +1656,6 @@ impl<'a> Resolver<'a> {
fn record_use( fn record_use(
&mut self, &mut self,
ident: Ident, ident: Ident,
ns: Namespace,
used_binding: &'a NameBinding<'a>, used_binding: &'a NameBinding<'a>,
is_lexical_scope: bool, is_lexical_scope: bool,
) { ) {
@ -1684,9 +1683,9 @@ impl<'a> Resolver<'a> {
} }
used.set(true); used.set(true);
import.used.set(true); import.used.set(true);
self.used_imports.insert((import.id, ns)); self.used_imports.insert(import.id);
self.add_to_glob_map(&import, ident); self.add_to_glob_map(&import, ident);
self.record_use(ident, ns, binding, false); self.record_use(ident, binding, false);
} }
} }
@ -3241,7 +3240,7 @@ impl<'a> Resolver<'a> {
self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| { self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| {
if let Some(binding) = entry.extern_crate_item { if let Some(binding) = entry.extern_crate_item {
if !speculative && entry.introduced_by_item { if !speculative && entry.introduced_by_item {
self.record_use(ident, TypeNS, binding, false); self.record_use(ident, binding, false);
} }
Some(binding) Some(binding)
} else { } else {
@ -3428,7 +3427,7 @@ impl<'a> Resolver<'a> {
let is_import = name_binding.is_import(); let is_import = name_binding.is_import();
let span = name_binding.span; let span = name_binding.span;
if let Res::Def(DefKind::Fn, _) = res { if let Res::Def(DefKind::Fn, _) = res {
self.record_use(ident, ValueNS, name_binding, false); self.record_use(ident, name_binding, false);
} }
self.main_def = Some(MainDefinition { res, is_import, span }); self.main_def = Some(MainDefinition { res, is_import, span });
} }

View file

@ -1090,7 +1090,7 @@ impl<'a> Resolver<'a> {
) { ) {
Ok(binding) => { Ok(binding) => {
let initial_res = initial_binding.map(|initial_binding| { let initial_res = initial_binding.map(|initial_binding| {
self.record_use(ident, MacroNS, initial_binding, false); self.record_use(ident, initial_binding, false);
initial_binding.res() initial_binding.res()
}); });
let res = binding.res(); let res = binding.res();