aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-05-15 16:15:40 +0100
committerFlorian Diebold <[email protected]>2020-05-15 16:25:28 +0100
commit3f42b2e837c4672a0fbe953e14ae2fd3fe6fc3b6 (patch)
tree481c93f91eec65f98a82fa28a123140d5a227eea /crates/ra_hir_def
parentd51c1f62178c383363a2d95e865131d9a7b969d0 (diff)
Handle `Self` in values and patterns
I.e. - `Self(x)` or `Self` in tuple/unit struct impls - `Self::Variant(x)` or `Self::Variant` in enum impls - the same in patterns Fixes #4454.
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/resolver.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 717506358..15fdd9019 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -86,6 +86,7 @@ pub enum ResolveValueResult {
86 86
87#[derive(Debug, Clone, PartialEq, Eq, Hash)] 87#[derive(Debug, Clone, PartialEq, Eq, Hash)]
88pub enum ValueNs { 88pub enum ValueNs {
89 ImplSelf(ImplId),
89 LocalBinding(PatId), 90 LocalBinding(PatId),
90 FunctionId(FunctionId), 91 FunctionId(FunctionId),
91 ConstId(ConstId), 92 ConstId(ConstId),
@@ -291,19 +292,26 @@ impl Resolver {
291 } 292 }
292 Scope::GenericParams { .. } => continue, 293 Scope::GenericParams { .. } => continue,
293 294
294 Scope::ImplDefScope(impl_) if n_segments > 1 => { 295 Scope::ImplDefScope(impl_) => {
295 if first_name == &name![Self] { 296 if first_name == &name![Self] {
296 let ty = TypeNs::SelfType(*impl_); 297 if n_segments > 1 {
297 return Some(ResolveValueResult::Partial(ty, 1)); 298 let ty = TypeNs::SelfType(*impl_);
299 return Some(ResolveValueResult::Partial(ty, 1));
300 } else {
301 return Some(ResolveValueResult::ValueNs(ValueNs::ImplSelf(*impl_)));
302 }
298 } 303 }
299 } 304 }
300 Scope::AdtScope(adt) if n_segments > 1 => { 305 Scope::AdtScope(adt) => {
306 if n_segments == 1 {
307 // bare `Self` doesn't work in the value namespace in a struct/enum definition
308 continue;
309 }
301 if first_name == &name![Self] { 310 if first_name == &name![Self] {
302 let ty = TypeNs::AdtSelfType(*adt); 311 let ty = TypeNs::AdtSelfType(*adt);
303 return Some(ResolveValueResult::Partial(ty, 1)); 312 return Some(ResolveValueResult::Partial(ty, 1));
304 } 313 }
305 } 314 }
306 Scope::ImplDefScope(_) | Scope::AdtScope(_) => continue,
307 315
308 Scope::ModuleScope(m) => { 316 Scope::ModuleScope(m) => {
309 let (module_def, idx) = m.crate_def_map.resolve_path( 317 let (module_def, idx) = m.crate_def_map.resolve_path(