aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/item_scope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/item_scope.rs')
-rw-r--r--crates/ra_hir_def/src/item_scope.rs33
1 files changed, 6 insertions, 27 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index 6e958ca75..5e943b780 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -30,7 +30,7 @@ pub struct ItemScope {
30 legacy_macros: FxHashMap<Name, MacroDefId>, 30 legacy_macros: FxHashMap<Name, MacroDefId>,
31} 31}
32 32
33static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| { 33pub(crate) static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| {
34 BuiltinType::ALL 34 BuiltinType::ALL
35 .iter() 35 .iter()
36 .map(|(name, ty)| (name.clone(), PerNs::types(ty.clone().into(), Visibility::Public))) 36 .map(|(name, ty)| (name.clone(), PerNs::types(ty.clone().into(), Visibility::Public)))
@@ -40,9 +40,9 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| {
40/// Shadow mode for builtin type which can be shadowed by module. 40/// Shadow mode for builtin type which can be shadowed by module.
41#[derive(Debug, Copy, Clone, PartialEq, Eq)] 41#[derive(Debug, Copy, Clone, PartialEq, Eq)]
42pub(crate) enum BuiltinShadowMode { 42pub(crate) enum BuiltinShadowMode {
43 // Prefer Module 43 /// Prefer user-defined modules (or other types) over builtins.
44 Module, 44 Module,
45 // Prefer Other Types 45 /// Prefer builtins over user-defined modules (but not other types).
46 Other, 46 Other,
47} 47}
48 48
@@ -51,7 +51,7 @@ pub(crate) enum BuiltinShadowMode {
51impl ItemScope { 51impl ItemScope {
52 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a { 52 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a {
53 //FIXME: shadowing 53 //FIXME: shadowing
54 self.visible.iter().chain(BUILTIN_SCOPE.iter()).map(|(n, def)| (n, *def)) 54 self.visible.iter().map(|(n, def)| (n, *def))
55 } 55 }
56 56
57 pub fn entries_without_primitives<'a>( 57 pub fn entries_without_primitives<'a>(
@@ -79,29 +79,8 @@ impl ItemScope {
79 } 79 }
80 80
81 /// Get a name from current module scope, legacy macros are not included 81 /// Get a name from current module scope, legacy macros are not included
82 pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> PerNs { 82 pub(crate) fn get(&self, name: &Name) -> PerNs {
83 match shadow { 83 self.visible.get(name).copied().unwrap_or_else(PerNs::none)
84 BuiltinShadowMode::Module => self
85 .visible
86 .get(name)
87 .or_else(|| BUILTIN_SCOPE.get(name))
88 .copied()
89 .unwrap_or_else(PerNs::none),
90 BuiltinShadowMode::Other => {
91 let item = self.visible.get(name).copied();
92 if let Some(def) = item {
93 if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
94 return BUILTIN_SCOPE
95 .get(name)
96 .copied()
97 .or(item)
98 .unwrap_or_else(PerNs::none);
99 }
100 }
101
102 item.or_else(|| BUILTIN_SCOPE.get(name).copied()).unwrap_or_else(PerNs::none)
103 }
104 }
105 } 84 }
106 85
107 pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> { 86 pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {