diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-15 21:25:42 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-15 21:25:42 +0100 |
commit | cffa70be01d4353184f874fc4768b692e255dd30 (patch) | |
tree | 481c93f91eec65f98a82fa28a123140d5a227eea /crates/ra_hir_def/src | |
parent | d51c1f62178c383363a2d95e865131d9a7b969d0 (diff) | |
parent | 3f42b2e837c4672a0fbe953e14ae2fd3fe6fc3b6 (diff) |
Merge #4470
4470: Handle `Self` in values and patterns r=matklad a=flodiebold
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.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 |
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)] |
88 | pub enum ValueNs { | 88 | pub 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( |