From 435c189c803486a30d3fa0cdcc354e04b9993310 Mon Sep 17 00:00:00 2001 From: AdnoC Date: Thu, 31 Dec 2020 13:41:49 -0700 Subject: deduplicate macro completions from legacy macros and prelude --- crates/hir_def/src/per_ns.rs | 2 +- crates/hir_def/src/resolver.rs | 9 +++++++-- crates/hir_def/src/visibility.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/per_ns.rs b/crates/hir_def/src/per_ns.rs index 74665c588..a594afce6 100644 --- a/crates/hir_def/src/per_ns.rs +++ b/crates/hir_def/src/per_ns.rs @@ -7,7 +7,7 @@ use hir_expand::MacroDefId; use crate::{item_scope::ItemInNs, visibility::Visibility, ModuleDefId}; -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct PerNs { pub types: Option<(ModuleDefId, Visibility)>, pub values: Option<(ModuleDefId, Visibility)>, diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index f8cc5e075..cc66dcf31 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -483,6 +483,7 @@ pub enum ScopeDef { impl Scope { fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { + let mut seen = FxHashSet::default(); match self { Scope::ModuleScope(m) => { // FIXME: should we provide `self` here? @@ -496,7 +497,9 @@ impl Scope { f(name.clone(), ScopeDef::PerNs(def)); }); m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { - f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); + let scope = PerNs::macros(macro_, Visibility::Public); + seen.insert((name.clone(), scope)); + f(name.clone(), ScopeDef::PerNs(scope)); }); m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); @@ -507,7 +510,9 @@ impl Scope { if let Some(prelude) = m.crate_def_map.prelude { let prelude_def_map = db.crate_def_map(prelude.krate); prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { - f(name.clone(), ScopeDef::PerNs(def)); + if !seen.contains(&(name.clone(), def)) { + f(name.clone(), ScopeDef::PerNs(def)); + } }); } } diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs index e6e0853a3..f3bc9d680 100644 --- a/crates/hir_def/src/visibility.rs +++ b/crates/hir_def/src/visibility.rs @@ -85,7 +85,7 @@ impl RawVisibility { } /// Visibility of an item, with the path resolved. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Visibility { /// Visibility is restricted to a certain module. Module(ModuleId), -- cgit v1.2.3 From cca0dfa79ed968d41464eb7beb7aaa970e2d429f Mon Sep 17 00:00:00 2001 From: AdnoC Date: Thu, 31 Dec 2020 13:46:13 -0700 Subject: we can have one less call to name.clone() --- crates/hir_def/src/resolver.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index cc66dcf31..779754ada 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -510,8 +510,9 @@ impl Scope { if let Some(prelude) = m.crate_def_map.prelude { let prelude_def_map = db.crate_def_map(prelude.krate); prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { - if !seen.contains(&(name.clone(), def)) { - f(name.clone(), ScopeDef::PerNs(def)); + let seen_tuple = (name.clone(), def); + if !seen.contains(&seen_tuple) { + f(seen_tuple.0, ScopeDef::PerNs(def)); } }); } -- cgit v1.2.3