aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/resolve.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r--crates/ra_hir/src/resolve.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 39f8e1d8a..3c797c0c3 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -43,8 +43,10 @@ pub(crate) enum Scope {
43 ModuleScope(ModuleItemMap), 43 ModuleScope(ModuleItemMap),
44 /// Brings the generic parameters of an item into scope 44 /// Brings the generic parameters of an item into scope
45 GenericParams(Arc<GenericParams>), 45 GenericParams(Arc<GenericParams>),
46 /// Brings `Self` into scope 46 /// Brings `Self` in `impl` block into scope
47 ImplBlockScope(ImplBlock), 47 ImplBlockScope(ImplBlock),
48 /// Brings `Self` in enum, struct and union definitions into scope
49 AdtScope(Adt),
48 /// Local bindings 50 /// Local bindings
49 ExprScope(ExprScope), 51 ExprScope(ExprScope),
50} 52}
@@ -54,6 +56,7 @@ pub enum TypeNs {
54 SelfType(ImplBlock), 56 SelfType(ImplBlock),
55 GenericParam(u32), 57 GenericParam(u32),
56 Adt(Adt), 58 Adt(Adt),
59 AdtSelfType(Adt),
57 EnumVariant(EnumVariant), 60 EnumVariant(EnumVariant),
58 TypeAlias(TypeAlias), 61 TypeAlias(TypeAlias),
59 BuiltinType(BuiltinType), 62 BuiltinType(BuiltinType),
@@ -151,6 +154,12 @@ impl Resolver {
151 return Some((TypeNs::SelfType(*impl_), idx)); 154 return Some((TypeNs::SelfType(*impl_), idx));
152 } 155 }
153 } 156 }
157 Scope::AdtScope(adt) => {
158 if first_name == &SELF_TYPE {
159 let idx = if path.segments.len() == 1 { None } else { Some(1) };
160 return Some((TypeNs::AdtSelfType(*adt), idx));
161 }
162 }
154 Scope::ModuleScope(m) => { 163 Scope::ModuleScope(m) => {
155 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); 164 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path);
156 let res = match module_def.take_types()? { 165 let res = match module_def.take_types()? {
@@ -200,7 +209,10 @@ impl Resolver {
200 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); 209 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
201 for scope in self.scopes.iter().rev() { 210 for scope in self.scopes.iter().rev() {
202 match scope { 211 match scope {
203 Scope::ExprScope(_) | Scope::GenericParams(_) | Scope::ImplBlockScope(_) 212 Scope::AdtScope(_)
213 | Scope::ExprScope(_)
214 | Scope::GenericParams(_)
215 | Scope::ImplBlockScope(_)
204 if skip_to_mod => 216 if skip_to_mod =>
205 { 217 {
206 continue 218 continue
@@ -233,7 +245,13 @@ impl Resolver {
233 return Some(ResolveValueResult::Partial(ty, 1)); 245 return Some(ResolveValueResult::Partial(ty, 1));
234 } 246 }
235 } 247 }
236 Scope::ImplBlockScope(_) => continue, 248 Scope::AdtScope(adt) if n_segments > 1 => {
249 if first_name == &SELF_TYPE {
250 let ty = TypeNs::AdtSelfType(*adt);
251 return Some(ResolveValueResult::Partial(ty, 1));
252 }
253 }
254 Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue,
237 255
238 Scope::ModuleScope(m) => { 256 Scope::ModuleScope(m) => {
239 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); 257 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path);
@@ -389,7 +407,8 @@ pub enum ScopeDef {
389 ModuleDef(ModuleDef), 407 ModuleDef(ModuleDef),
390 MacroDef(MacroDef), 408 MacroDef(MacroDef),
391 GenericParam(u32), 409 GenericParam(u32),
392 SelfType(ImplBlock), 410 ImplSelfType(ImplBlock),
411 AdtSelfType(Adt),
393 LocalBinding(PatId), 412 LocalBinding(PatId),
394 Unknown, 413 Unknown,
395} 414}
@@ -437,7 +456,10 @@ impl Scope {
437 } 456 }
438 } 457 }
439 Scope::ImplBlockScope(i) => { 458 Scope::ImplBlockScope(i) => {
440 f(SELF_TYPE, ScopeDef::SelfType(*i)); 459 f(SELF_TYPE, ScopeDef::ImplSelfType(*i));
460 }
461 Scope::AdtScope(i) => {
462 f(SELF_TYPE, ScopeDef::AdtSelfType(*i));
441 } 463 }
442 Scope::ExprScope(e) => { 464 Scope::ExprScope(e) => {
443 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { 465 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {