aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/resolver.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-14 18:16:48 +0000
committerGitHub <[email protected]>2019-12-14 18:16:48 +0000
commitd6223253b628b279f9ddae8f83f7173d01f6b32c (patch)
tree12f2ccc5c52c1c0b67932d3a35fe18668b8e5d62 /crates/ra_hir_def/src/resolver.rs
parent202ad1e2d9376565cb273cf085be600ed10e5a93 (diff)
parent2619950b3b405324ab1c1745876165c834b3b4b9 (diff)
Merge #2561
2561: Split generic and non-generic paths r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/resolver.rs')
-rw-r--r--crates/ra_hir_def/src/resolver.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index b6d595a20..2694c0438 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -15,7 +15,7 @@ use crate::{
15 expr::{ExprId, PatId}, 15 expr::{ExprId, PatId},
16 generics::GenericParams, 16 generics::GenericParams,
17 nameres::{BuiltinShadowMode, CrateDefMap}, 17 nameres::{BuiltinShadowMode, CrateDefMap},
18 path::{Path, PathKind}, 18 path::{ModPath, PathKind},
19 per_ns::PerNs, 19 per_ns::PerNs,
20 AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, 20 AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId,
21 HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, 21 HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
@@ -91,7 +91,7 @@ pub enum ValueNs {
91 91
92impl Resolver { 92impl Resolver {
93 /// Resolve known trait from std, like `std::futures::Future` 93 /// Resolve known trait from std, like `std::futures::Future`
94 pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> { 94 pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &ModPath) -> Option<TraitId> {
95 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 95 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
96 match res { 96 match res {
97 ModuleDefId::TraitId(it) => Some(it), 97 ModuleDefId::TraitId(it) => Some(it),
@@ -100,7 +100,7 @@ impl Resolver {
100 } 100 }
101 101
102 /// Resolve known struct from std, like `std::boxed::Box` 102 /// Resolve known struct from std, like `std::boxed::Box`
103 pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> { 103 pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &ModPath) -> Option<StructId> {
104 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 104 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
105 match res { 105 match res {
106 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), 106 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
@@ -109,7 +109,7 @@ impl Resolver {
109 } 109 }
110 110
111 /// Resolve known enum from std, like `std::result::Result` 111 /// Resolve known enum from std, like `std::result::Result`
112 pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> { 112 pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &ModPath) -> Option<EnumId> {
113 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 113 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
114 match res { 114 match res {
115 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), 115 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
@@ -120,33 +120,30 @@ impl Resolver {
120 fn resolve_module_path( 120 fn resolve_module_path(
121 &self, 121 &self,
122 db: &impl DefDatabase, 122 db: &impl DefDatabase,
123 path: &Path, 123 path: &ModPath,
124 shadow: BuiltinShadowMode, 124 shadow: BuiltinShadowMode,
125 ) -> PerNs { 125 ) -> PerNs {
126 let (item_map, module) = match self.module() { 126 let (item_map, module) = match self.module() {
127 Some(it) => it, 127 Some(it) => it,
128 None => return PerNs::none(), 128 None => return PerNs::none(),
129 }; 129 };
130 let (module_res, segment_index) = item_map.resolve_path(db, module, path, shadow); 130 let (module_res, segment_index) = item_map.resolve_path(db, module, &path, shadow);
131 if segment_index.is_some() { 131 if segment_index.is_some() {
132 return PerNs::none(); 132 return PerNs::none();
133 } 133 }
134 module_res 134 module_res
135 } 135 }
136 136
137 pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &Path) -> PerNs { 137 pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &ModPath) -> PerNs {
138 self.resolve_module_path(db, path, BuiltinShadowMode::Module) 138 self.resolve_module_path(db, path, BuiltinShadowMode::Module)
139 } 139 }
140 140
141 pub fn resolve_path_in_type_ns( 141 pub fn resolve_path_in_type_ns(
142 &self, 142 &self,
143 db: &impl DefDatabase, 143 db: &impl DefDatabase,
144 path: &Path, 144 path: &ModPath,
145 ) -> Option<(TypeNs, Option<usize>)> { 145 ) -> Option<(TypeNs, Option<usize>)> {
146 if path.is_type_relative() { 146 let first_name = path.segments.first()?;
147 return None;
148 }
149 let first_name = &path.segments.first()?.name;
150 let skip_to_mod = path.kind != PathKind::Plain; 147 let skip_to_mod = path.kind != PathKind::Plain;
151 for scope in self.scopes.iter().rev() { 148 for scope in self.scopes.iter().rev() {
152 match scope { 149 match scope {
@@ -178,7 +175,7 @@ impl Resolver {
178 let (module_def, idx) = m.crate_def_map.resolve_path( 175 let (module_def, idx) = m.crate_def_map.resolve_path(
179 db, 176 db,
180 m.module_id, 177 m.module_id,
181 path, 178 &path,
182 BuiltinShadowMode::Other, 179 BuiltinShadowMode::Other,
183 ); 180 );
184 let res = match module_def.take_types()? { 181 let res = match module_def.take_types()? {
@@ -205,7 +202,7 @@ impl Resolver {
205 pub fn resolve_path_in_type_ns_fully( 202 pub fn resolve_path_in_type_ns_fully(
206 &self, 203 &self,
207 db: &impl DefDatabase, 204 db: &impl DefDatabase,
208 path: &Path, 205 path: &ModPath,
209 ) -> Option<TypeNs> { 206 ) -> Option<TypeNs> {
210 let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; 207 let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?;
211 if unresolved.is_some() { 208 if unresolved.is_some() {
@@ -214,17 +211,14 @@ impl Resolver {
214 Some(res) 211 Some(res)
215 } 212 }
216 213
217 pub fn resolve_path_in_value_ns<'p>( 214 pub fn resolve_path_in_value_ns(
218 &self, 215 &self,
219 db: &impl DefDatabase, 216 db: &impl DefDatabase,
220 path: &'p Path, 217 path: &ModPath,
221 ) -> Option<ResolveValueResult> { 218 ) -> Option<ResolveValueResult> {
222 if path.is_type_relative() {
223 return None;
224 }
225 let n_segments = path.segments.len(); 219 let n_segments = path.segments.len();
226 let tmp = name![self]; 220 let tmp = name![self];
227 let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; 221 let first_name = if path.is_self() { &tmp } else { &path.segments.first()? };
228 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); 222 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
229 for scope in self.scopes.iter().rev() { 223 for scope in self.scopes.iter().rev() {
230 match scope { 224 match scope {
@@ -276,7 +270,7 @@ impl Resolver {
276 let (module_def, idx) = m.crate_def_map.resolve_path( 270 let (module_def, idx) = m.crate_def_map.resolve_path(
277 db, 271 db,
278 m.module_id, 272 m.module_id,
279 path, 273 &path,
280 BuiltinShadowMode::Other, 274 BuiltinShadowMode::Other,
281 ); 275 );
282 return match idx { 276 return match idx {
@@ -322,7 +316,7 @@ impl Resolver {
322 pub fn resolve_path_in_value_ns_fully( 316 pub fn resolve_path_in_value_ns_fully(
323 &self, 317 &self,
324 db: &impl DefDatabase, 318 db: &impl DefDatabase,
325 path: &Path, 319 path: &ModPath,
326 ) -> Option<ValueNs> { 320 ) -> Option<ValueNs> {
327 match self.resolve_path_in_value_ns(db, path)? { 321 match self.resolve_path_in_value_ns(db, path)? {
328 ResolveValueResult::ValueNs(it) => Some(it), 322 ResolveValueResult::ValueNs(it) => Some(it),
@@ -330,9 +324,13 @@ impl Resolver {
330 } 324 }
331 } 325 }
332 326
333 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 327 pub fn resolve_path_as_macro(
328 &self,
329 db: &impl DefDatabase,
330 path: &ModPath,
331 ) -> Option<MacroDefId> {
334 let (item_map, module) = self.module()?; 332 let (item_map, module) = self.module()?;
335 item_map.resolve_path(db, module, path, BuiltinShadowMode::Other).0.take_macros() 333 item_map.resolve_path(db, module, &path, BuiltinShadowMode::Other).0.take_macros()
336 } 334 }
337 335
338 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 336 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {