aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/defs.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-15 15:23:55 +0100
committerAleksey Kladov <[email protected]>2020-10-15 16:37:36 +0100
commitbc287b8f9b7711a38d97be3b619758bb05d54c45 (patch)
treea9c3d129e8781451f7425e547317d82dd1ef9bed /crates/ide_db/src/defs.rs
parentfa3c449d8f5a67865cab8d4717b3e32dca5b672a (diff)
Unconfuse expression and pattern field init shorthands
Diffstat (limited to 'crates/ide_db/src/defs.rs')
-rw-r--r--crates/ide_db/src/defs.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index a243dcd15..a2682d73c 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -83,7 +83,8 @@ pub enum NameClass {
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 FieldShorthand { 86 /// `field` in `if let Foo { field } = todo!() {}`
87 PatFieldShorthand {
87 local: Local, 88 local: Local,
88 field: Definition, 89 field: Definition,
89 }, 90 },
@@ -91,19 +92,22 @@ pub enum NameClass {
91 92
92impl NameClass { 93impl NameClass {
93 pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> { 94 pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> {
94 Some(match self { 95 let res = match self {
95 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), 96 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
96 NameClass::Definition(it) => it, 97 NameClass::Definition(it) => it,
97 NameClass::ConstReference(_) => return None, 98 NameClass::ConstReference(_) => return None,
98 NameClass::FieldShorthand { local, field: _ } => Definition::Local(local), 99 /// Both `local` and `field` are definitions here, but only `local`
99 }) 100 /// is the definition which is introduced by this name.
101 NameClass::PatFieldShorthand { local, field: _ } => Definition::Local(local),
102 };
103 Some(res)
100 } 104 }
101 105
102 pub fn definition_or_reference(self, db: &dyn HirDatabase) -> Definition { 106 pub fn definition_or_reference(self, db: &dyn HirDatabase) -> Definition {
103 match self { 107 match self {
104 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), 108 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
105 NameClass::Definition(it) | NameClass::ConstReference(it) => it, 109 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
106 NameClass::FieldShorthand { local: _, field } => field, 110 NameClass::PatFieldShorthand { local: _, field } => field,
107 } 111 }
108 } 112 }
109} 113}
@@ -161,7 +165,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
161 if record_pat_field.name_ref().is_none() { 165 if record_pat_field.name_ref().is_none() {
162 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) {
163 let field = Definition::Field(field); 167 let field = Definition::Field(field);
164 return Some(NameClass::FieldShorthand { local, field }); 168 return Some(NameClass::PatFieldShorthand { local, field });
165 } 169 }
166 } 170 }
167 } 171 }