aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/defs.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-15 16:18:07 +0100
committerAleksey Kladov <[email protected]>2020-10-15 16:37:55 +0100
commitf9c1336873d65805ad34129939d800dbf59daf61 (patch)
tree6ab5f2b70691fb4dc1098769459741e54d0d3807 /crates/ide_db/src/defs.rs
parentbc287b8f9b7711a38d97be3b619758bb05d54c45 (diff)
More clarifications
Diffstat (limited to 'crates/ide_db/src/defs.rs')
-rw-r--r--crates/ide_db/src/defs.rs20
1 files changed, 10 insertions, 10 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 {
81pub enum NameClass { 81pub 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 }