aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/item_scope.rs19
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs14
2 files changed, 17 insertions, 16 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index 08d788cc9..e8ddcc3c2 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -70,20 +70,27 @@ impl ItemScope {
70 } 70 }
71 71
72 /// Get a name from current module scope, legacy macros are not included 72 /// Get a name from current module scope, legacy macros are not included
73 pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<PerNs> { 73 pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> PerNs {
74 match shadow { 74 match shadow {
75 BuiltinShadowMode::Module => { 75 BuiltinShadowMode::Module => self
76 self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)).copied() 76 .visible
77 } 77 .get(name)
78 .or_else(|| BUILTIN_SCOPE.get(name))
79 .copied()
80 .unwrap_or_else(PerNs::none),
78 BuiltinShadowMode::Other => { 81 BuiltinShadowMode::Other => {
79 let item = self.visible.get(name).copied(); 82 let item = self.visible.get(name).copied();
80 if let Some(def) = item { 83 if let Some(def) = item {
81 if let Some(ModuleDefId::ModuleId(_)) = def.take_types() { 84 if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
82 return BUILTIN_SCOPE.get(name).copied().or(item); 85 return BUILTIN_SCOPE
86 .get(name)
87 .copied()
88 .or(item)
89 .unwrap_or_else(PerNs::none);
83 } 90 }
84 } 91 }
85 92
86 item.or_else(|| BUILTIN_SCOPE.get(name).copied()) 93 item.or_else(|| BUILTIN_SCOPE.get(name).copied()).unwrap_or_else(PerNs::none)
87 } 94 }
88 } 95 }
89 } 96 }
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index 9b85ae018..695014c7b 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -180,13 +180,7 @@ impl CrateDefMap {
180 } 180 }
181 181
182 // Since it is a qualified path here, it should not contains legacy macros 182 // Since it is a qualified path here, it should not contains legacy macros
183 match self[module.local_id].scope.get(&segment, prefer_module(i)) { 183 self[module.local_id].scope.get(&segment, prefer_module(i))
184 Some(def) => def,
185 _ => {
186 log::debug!("path segment {:?} not found", segment);
187 return ResolvePathResult::empty(ReachedFixedPoint::No);
188 }
189 }
190 } 184 }
191 ModuleDefId::AdtId(AdtId::EnumId(e)) => { 185 ModuleDefId::AdtId(AdtId::EnumId(e)) => {
192 // enum variant 186 // enum variant
@@ -243,7 +237,7 @@ impl CrateDefMap {
243 // - std prelude 237 // - std prelude
244 let from_legacy_macro = 238 let from_legacy_macro =
245 self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); 239 self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros);
246 let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none); 240 let from_scope = self[module].scope.get(name, shadow);
247 let from_extern_prelude = 241 let from_extern_prelude =
248 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); 242 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
249 let from_prelude = self.resolve_in_prelude(db, name, shadow); 243 let from_prelude = self.resolve_in_prelude(db, name, shadow);
@@ -256,7 +250,7 @@ impl CrateDefMap {
256 name: &Name, 250 name: &Name,
257 shadow: BuiltinShadowMode, 251 shadow: BuiltinShadowMode,
258 ) -> PerNs { 252 ) -> PerNs {
259 let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none); 253 let from_crate_root = self[self.root].scope.get(name, shadow);
260 let from_extern_prelude = self.resolve_name_in_extern_prelude(name); 254 let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
261 255
262 from_crate_root.or(from_extern_prelude) 256 from_crate_root.or(from_extern_prelude)
@@ -277,7 +271,7 @@ impl CrateDefMap {
277 keep = db.crate_def_map(prelude.krate); 271 keep = db.crate_def_map(prelude.krate);
278 &keep 272 &keep
279 }; 273 };
280 def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none) 274 def_map[prelude.local_id].scope.get(name, shadow)
281 } else { 275 } else {
282 PerNs::none() 276 PerNs::none()
283 } 277 }