aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres.rs')
-rw-r--r--crates/ra_hir_def/src/nameres.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index df42ea84a..3e1521870 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -149,6 +149,15 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
149 .collect() 149 .collect()
150}); 150});
151 151
152/// Shadow mode for builtin type which can be shadowed by module.
153#[derive(Debug, Copy, Clone, PartialEq, Eq)]
154pub enum BuiltinShadowMode {
155 // Prefer Module
156 Module,
157 // Prefer Other Types
158 Other,
159}
160
152/// Legacy macros can only be accessed through special methods like `get_legacy_macros`. 161/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
153/// Other methods will only resolve values, types and module scoped macros only. 162/// Other methods will only resolve values, types and module scoped macros only.
154impl ModuleScope { 163impl ModuleScope {
@@ -178,8 +187,20 @@ impl ModuleScope {
178 } 187 }
179 188
180 /// Get a name from current module scope, legacy macros are not included 189 /// Get a name from current module scope, legacy macros are not included
181 pub fn get(&self, name: &Name) -> Option<&Resolution> { 190 pub fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&Resolution> {
182 self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)) 191 match shadow {
192 BuiltinShadowMode::Module => self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)),
193 BuiltinShadowMode::Other => {
194 let item = self.items.get(name);
195 if let Some(res) = item {
196 if let Some(ModuleDefId::ModuleId(_)) = res.def.take_types() {
197 return BUILTIN_SCOPE.get(name).or(item);
198 }
199 }
200
201 item.or_else(|| BUILTIN_SCOPE.get(name))
202 }
203 }
183 } 204 }
184 205
185 pub fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a { 206 pub fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
@@ -250,8 +271,10 @@ impl CrateDefMap {
250 db: &impl DefDatabase, 271 db: &impl DefDatabase,
251 original_module: LocalModuleId, 272 original_module: LocalModuleId,
252 path: &Path, 273 path: &Path,
274 shadow: BuiltinShadowMode,
253 ) -> (PerNs, Option<usize>) { 275 ) -> (PerNs, Option<usize>) {
254 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); 276 let res =
277 self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path, shadow);
255 (res.resolved_def, res.segment_index) 278 (res.resolved_def, res.segment_index)
256 } 279 }
257} 280}