diff options
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 3c797c0c3..75b24d386 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -1,6 +1,12 @@ | |||
1 | //! Name resolution. | 1 | //! Name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_def::{ | ||
5 | builtin_type::BuiltinType, | ||
6 | path::{Path, PathKind}, | ||
7 | CrateModuleId, | ||
8 | }; | ||
9 | use hir_expand::name::{self, Name}; | ||
4 | use rustc_hash::FxHashSet; | 10 | use rustc_hash::FxHashSet; |
5 | 11 | ||
6 | use crate::{ | 12 | use crate::{ |
@@ -12,11 +18,8 @@ use crate::{ | |||
12 | }, | 18 | }, |
13 | generics::GenericParams, | 19 | generics::GenericParams, |
14 | impl_block::ImplBlock, | 20 | impl_block::ImplBlock, |
15 | name::{Name, SELF_PARAM, SELF_TYPE}, | 21 | nameres::{CrateDefMap, PerNs}, |
16 | nameres::{CrateDefMap, CrateModuleId, PerNs}, | 22 | Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias, |
17 | path::{Path, PathKind}, | ||
18 | Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, | ||
19 | Trait, TypeAlias, | ||
20 | }; | 23 | }; |
21 | 24 | ||
22 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -149,13 +152,13 @@ impl Resolver { | |||
149 | } | 152 | } |
150 | } | 153 | } |
151 | Scope::ImplBlockScope(impl_) => { | 154 | Scope::ImplBlockScope(impl_) => { |
152 | if first_name == &SELF_TYPE { | 155 | if first_name == &name::SELF_TYPE { |
153 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 156 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
154 | return Some((TypeNs::SelfType(*impl_), idx)); | 157 | return Some((TypeNs::SelfType(*impl_), idx)); |
155 | } | 158 | } |
156 | } | 159 | } |
157 | Scope::AdtScope(adt) => { | 160 | Scope::AdtScope(adt) => { |
158 | if first_name == &SELF_TYPE { | 161 | if first_name == &name::SELF_TYPE { |
159 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 162 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
160 | return Some((TypeNs::AdtSelfType(*adt), idx)); | 163 | return Some((TypeNs::AdtSelfType(*adt), idx)); |
161 | } | 164 | } |
@@ -204,7 +207,7 @@ impl Resolver { | |||
204 | return None; | 207 | return None; |
205 | } | 208 | } |
206 | let n_segments = path.segments.len(); | 209 | let n_segments = path.segments.len(); |
207 | let tmp = SELF_PARAM; | 210 | let tmp = name::SELF_PARAM; |
208 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; | 211 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; |
209 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); | 212 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); |
210 | for scope in self.scopes.iter().rev() { | 213 | for scope in self.scopes.iter().rev() { |
@@ -240,13 +243,13 @@ impl Resolver { | |||
240 | Scope::GenericParams(_) => continue, | 243 | Scope::GenericParams(_) => continue, |
241 | 244 | ||
242 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { | 245 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { |
243 | if first_name == &SELF_TYPE { | 246 | if first_name == &name::SELF_TYPE { |
244 | let ty = TypeNs::SelfType(*impl_); | 247 | let ty = TypeNs::SelfType(*impl_); |
245 | return Some(ResolveValueResult::Partial(ty, 1)); | 248 | return Some(ResolveValueResult::Partial(ty, 1)); |
246 | } | 249 | } |
247 | } | 250 | } |
248 | Scope::AdtScope(adt) if n_segments > 1 => { | 251 | Scope::AdtScope(adt) if n_segments > 1 => { |
249 | if first_name == &SELF_TYPE { | 252 | if first_name == &name::SELF_TYPE { |
250 | let ty = TypeNs::AdtSelfType(*adt); | 253 | let ty = TypeNs::AdtSelfType(*adt); |
251 | return Some(ResolveValueResult::Partial(ty, 1)); | 254 | return Some(ResolveValueResult::Partial(ty, 1)); |
252 | } | 255 | } |
@@ -330,8 +333,8 @@ impl Resolver { | |||
330 | for scope in &self.scopes { | 333 | for scope in &self.scopes { |
331 | if let Scope::ModuleScope(m) = scope { | 334 | if let Scope::ModuleScope(m) = scope { |
332 | if let Some(prelude) = m.crate_def_map.prelude() { | 335 | if let Some(prelude) = m.crate_def_map.prelude() { |
333 | let prelude_def_map = db.crate_def_map(prelude.krate); | 336 | let prelude_def_map = db.crate_def_map(prelude.krate()); |
334 | traits.extend(prelude_def_map[prelude.module_id].scope.traits()); | 337 | traits.extend(prelude_def_map[prelude.id.module_id].scope.traits()); |
335 | } | 338 | } |
336 | traits.extend(m.crate_def_map[m.module_id].scope.traits()); | 339 | traits.extend(m.crate_def_map[m.module_id].scope.traits()); |
337 | } | 340 | } |
@@ -444,10 +447,12 @@ impl Scope { | |||
444 | f(name.clone(), ScopeDef::ModuleDef(*def)); | 447 | f(name.clone(), ScopeDef::ModuleDef(*def)); |
445 | }); | 448 | }); |
446 | if let Some(prelude) = m.crate_def_map.prelude() { | 449 | if let Some(prelude) = m.crate_def_map.prelude() { |
447 | let prelude_def_map = db.crate_def_map(prelude.krate); | 450 | let prelude_def_map = db.crate_def_map(prelude.krate()); |
448 | prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| { | 451 | prelude_def_map[prelude.id.module_id].scope.entries().for_each( |
449 | f(name.clone(), res.def.into()); | 452 | |(name, res)| { |
450 | }); | 453 | f(name.clone(), res.def.into()); |
454 | }, | ||
455 | ); | ||
451 | } | 456 | } |
452 | } | 457 | } |
453 | Scope::GenericParams(gp) => { | 458 | Scope::GenericParams(gp) => { |
@@ -456,10 +461,10 @@ impl Scope { | |||
456 | } | 461 | } |
457 | } | 462 | } |
458 | Scope::ImplBlockScope(i) => { | 463 | Scope::ImplBlockScope(i) => { |
459 | f(SELF_TYPE, ScopeDef::ImplSelfType(*i)); | 464 | f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i)); |
460 | } | 465 | } |
461 | Scope::AdtScope(i) => { | 466 | Scope::AdtScope(i) => { |
462 | f(SELF_TYPE, ScopeDef::AdtSelfType(*i)); | 467 | f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); |
463 | } | 468 | } |
464 | Scope::ExprScope(e) => { | 469 | Scope::ExprScope(e) => { |
465 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { | 470 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { |