diff options
Diffstat (limited to 'crates/ra_hir_def/src/resolver.rs')
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 0847f6dcf..7d4df222e 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | db::DefDatabase, | 14 | db::DefDatabase, |
15 | expr::{ExprId, PatId}, | 15 | expr::{ExprId, PatId}, |
16 | generics::GenericParams, | 16 | generics::GenericParams, |
17 | nameres::CrateDefMap, | 17 | nameres::{BuiltinShadowMode, CrateDefMap}, |
18 | path::{Path, PathKind}, | 18 | path::{Path, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, |
@@ -91,7 +91,7 @@ pub enum ValueNs { | |||
91 | impl Resolver { | 91 | impl Resolver { |
92 | /// Resolve known trait from std, like `std::futures::Future` | 92 | /// Resolve known trait from std, like `std::futures::Future` |
93 | pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> { | 93 | pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> { |
94 | let res = self.resolve_module_path(db, path).take_types()?; | 94 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
95 | match res { | 95 | match res { |
96 | ModuleDefId::TraitId(it) => Some(it), | 96 | ModuleDefId::TraitId(it) => Some(it), |
97 | _ => None, | 97 | _ => None, |
@@ -100,7 +100,7 @@ impl Resolver { | |||
100 | 100 | ||
101 | /// Resolve known struct from std, like `std::boxed::Box` | 101 | /// Resolve known struct from std, like `std::boxed::Box` |
102 | pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> { | 102 | pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> { |
103 | let res = self.resolve_module_path(db, path).take_types()?; | 103 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
104 | match res { | 104 | match res { |
105 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), | 105 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), |
106 | _ => None, | 106 | _ => None, |
@@ -109,26 +109,34 @@ impl Resolver { | |||
109 | 109 | ||
110 | /// Resolve known enum from std, like `std::result::Result` | 110 | /// Resolve known enum from std, like `std::result::Result` |
111 | pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> { | 111 | pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> { |
112 | let res = self.resolve_module_path(db, path).take_types()?; | 112 | let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; |
113 | match res { | 113 | match res { |
114 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), | 114 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), |
115 | _ => None, | 115 | _ => None, |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | /// pub only for source-binder | 119 | fn resolve_module_path( |
120 | pub fn resolve_module_path(&self, db: &impl DefDatabase, path: &Path) -> PerNs { | 120 | &self, |
121 | db: &impl DefDatabase, | ||
122 | path: &Path, | ||
123 | shadow: BuiltinShadowMode, | ||
124 | ) -> PerNs { | ||
121 | let (item_map, module) = match self.module() { | 125 | let (item_map, module) = match self.module() { |
122 | Some(it) => it, | 126 | Some(it) => it, |
123 | None => return PerNs::none(), | 127 | None => return PerNs::none(), |
124 | }; | 128 | }; |
125 | let (module_res, segment_index) = item_map.resolve_path(db, module, path); | 129 | let (module_res, segment_index) = item_map.resolve_path(db, module, path, shadow); |
126 | if segment_index.is_some() { | 130 | if segment_index.is_some() { |
127 | return PerNs::none(); | 131 | return PerNs::none(); |
128 | } | 132 | } |
129 | module_res | 133 | module_res |
130 | } | 134 | } |
131 | 135 | ||
136 | pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &Path) -> PerNs { | ||
137 | self.resolve_module_path(db, path, BuiltinShadowMode::Module) | ||
138 | } | ||
139 | |||
132 | pub fn resolve_path_in_type_ns( | 140 | pub fn resolve_path_in_type_ns( |
133 | &self, | 141 | &self, |
134 | db: &impl DefDatabase, | 142 | db: &impl DefDatabase, |
@@ -163,7 +171,12 @@ impl Resolver { | |||
163 | } | 171 | } |
164 | } | 172 | } |
165 | Scope::ModuleScope(m) => { | 173 | Scope::ModuleScope(m) => { |
166 | let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); | 174 | let (module_def, idx) = m.crate_def_map.resolve_path( |
175 | db, | ||
176 | m.module_id, | ||
177 | path, | ||
178 | BuiltinShadowMode::Other, | ||
179 | ); | ||
167 | let res = match module_def.take_types()? { | 180 | let res = match module_def.take_types()? { |
168 | ModuleDefId::AdtId(it) => TypeNs::AdtId(it), | 181 | ModuleDefId::AdtId(it) => TypeNs::AdtId(it), |
169 | ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it), | 182 | ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it), |
@@ -256,7 +269,12 @@ impl Resolver { | |||
256 | Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue, | 269 | Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue, |
257 | 270 | ||
258 | Scope::ModuleScope(m) => { | 271 | Scope::ModuleScope(m) => { |
259 | let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); | 272 | let (module_def, idx) = m.crate_def_map.resolve_path( |
273 | db, | ||
274 | m.module_id, | ||
275 | path, | ||
276 | BuiltinShadowMode::Other, | ||
277 | ); | ||
260 | return match idx { | 278 | return match idx { |
261 | None => { | 279 | None => { |
262 | let value = match module_def.take_values()? { | 280 | let value = match module_def.take_values()? { |
@@ -310,7 +328,7 @@ impl Resolver { | |||
310 | 328 | ||
311 | pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { | 329 | pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { |
312 | let (item_map, module) = self.module()?; | 330 | let (item_map, module) = self.module()?; |
313 | item_map.resolve_path(db, module, path).0.take_macros() | 331 | item_map.resolve_path(db, module, path, BuiltinShadowMode::Other).0.take_macros() |
314 | } | 332 | } |
315 | 333 | ||
316 | pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { | 334 | pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |