diff options
author | Aleksey Kladov <[email protected]> | 2020-10-15 16:18:07 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-10-15 16:37:55 +0100 |
commit | f9c1336873d65805ad34129939d800dbf59daf61 (patch) | |
tree | 6ab5f2b70691fb4dc1098769459741e54d0d3807 /crates/ide_db | |
parent | bc287b8f9b7711a38d97be3b619758bb05d54c45 (diff) |
More clarifications
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/defs.rs | 20 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 4 |
2 files changed, 12 insertions, 12 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index a2682d73c..717581593 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -81,12 +81,12 @@ impl Definition { | |||
81 | pub enum NameClass { | 81 | pub enum NameClass { |
82 | ExternCrate(Crate), | 82 | ExternCrate(Crate), |
83 | Definition(Definition), | 83 | Definition(Definition), |
84 | /// `None` in `if let None = Some(82) {}` | 84 | /// `None` in `if let None = Some(82) {}`. |
85 | ConstReference(Definition), | 85 | ConstReference(Definition), |
86 | /// `field` in `if let Foo { field } = todo!() {}` | 86 | /// `field` in `if let Foo { field } = foo`. |
87 | PatFieldShorthand { | 87 | PatFieldShorthand { |
88 | local: Local, | 88 | local_def: Local, |
89 | field: Definition, | 89 | field_ref: Definition, |
90 | }, | 90 | }, |
91 | } | 91 | } |
92 | 92 | ||
@@ -96,18 +96,18 @@ impl NameClass { | |||
96 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), | 96 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), |
97 | NameClass::Definition(it) => it, | 97 | NameClass::Definition(it) => it, |
98 | NameClass::ConstReference(_) => return None, | 98 | NameClass::ConstReference(_) => return None, |
99 | /// Both `local` and `field` are definitions here, but only `local` | 99 | NameClass::PatFieldShorthand { local_def, field_ref: _ } => { |
100 | /// is the definition which is introduced by this name. | 100 | Definition::Local(local_def) |
101 | NameClass::PatFieldShorthand { local, field: _ } => Definition::Local(local), | 101 | } |
102 | }; | 102 | }; |
103 | Some(res) | 103 | Some(res) |
104 | } | 104 | } |
105 | 105 | ||
106 | pub fn definition_or_reference(self, db: &dyn HirDatabase) -> Definition { | 106 | pub fn reference_or_definition(self, db: &dyn HirDatabase) -> Definition { |
107 | match self { | 107 | match self { |
108 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), | 108 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), |
109 | NameClass::Definition(it) | NameClass::ConstReference(it) => it, | 109 | NameClass::Definition(it) | NameClass::ConstReference(it) => it, |
110 | NameClass::PatFieldShorthand { local: _, field } => field, | 110 | NameClass::PatFieldShorthand { local_def: _, field_ref } => field_ref, |
111 | } | 111 | } |
112 | } | 112 | } |
113 | } | 113 | } |
@@ -165,7 +165,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
165 | if record_pat_field.name_ref().is_none() { | 165 | if record_pat_field.name_ref().is_none() { |
166 | if let Some(field) = sema.resolve_record_pat_field(&record_pat_field) { | 166 | if let Some(field) = sema.resolve_record_pat_field(&record_pat_field) { |
167 | let field = Definition::Field(field); | 167 | let field = Definition::Field(field); |
168 | return Some(NameClass::PatFieldShorthand { local, field }); | 168 | return Some(NameClass::PatFieldShorthand { local_def: local, field_ref: field }); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 43b8560ca..8048aa621 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -314,9 +314,9 @@ impl<'a> FindUsages<'a> { | |||
314 | 314 | ||
315 | fn found_name(&self, name: &ast::Name, sink: &mut dyn FnMut(Reference) -> bool) -> bool { | 315 | fn found_name(&self, name: &ast::Name, sink: &mut dyn FnMut(Reference) -> bool) -> bool { |
316 | match classify_name(self.sema, name) { | 316 | match classify_name(self.sema, name) { |
317 | Some(NameClass::PatFieldShorthand { local: _, field }) => { | 317 | Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => { |
318 | let reference = match self.def { | 318 | let reference = match self.def { |
319 | Definition::Field(_) if &field == self.def => Reference { | 319 | Definition::Field(_) if &field_ref == self.def => Reference { |
320 | file_range: self.sema.original_range(name.syntax()), | 320 | file_range: self.sema.original_range(name.syntax()), |
321 | kind: ReferenceKind::FieldShorthandForField, | 321 | kind: ReferenceKind::FieldShorthandForField, |
322 | // FIXME: mutable patterns should have `Write` access | 322 | // FIXME: mutable patterns should have `Write` access |