diff --git a/crates/hir_def/src/per_ns.rs b/crates/hir_def/src/per_ns.rs index 74665c5885..a594afce66 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 e4152a0be4..61059c3499 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -490,6 +490,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? @@ -503,7 +504,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))); @@ -514,7 +517,10 @@ 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)); + let seen_tuple = (name.clone(), def); + if !seen.contains(&seen_tuple) { + f(seen_tuple.0, ScopeDef::PerNs(def)); + } }); } } diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs index e6e0853a30..f3bc9d6800 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),