aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/syntax_highlighting.rs2
-rw-r--r--crates/ide_db/src/defs.rs16
-rw-r--r--crates/ide_db/src/search.rs2
3 files changed, 12 insertions, 8 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 527888306..4d8cd98c7 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -459,7 +459,7 @@ fn highlight_element(
459 highlight_def(db, def) | HighlightModifier::Definition 459 highlight_def(db, def) | HighlightModifier::Definition
460 } 460 }
461 Some(NameClass::ConstReference(def)) => highlight_def(db, def), 461 Some(NameClass::ConstReference(def)) => highlight_def(db, def),
462 Some(NameClass::FieldShorthand { field, .. }) => { 462 Some(NameClass::PatFieldShorthand { field, .. }) => {
463 let mut h = HighlightTag::Field.into(); 463 let mut h = HighlightTag::Field.into();
464 if let Definition::Field(field) = field { 464 if let Definition::Field(field) = field {
465 if let VariantDef::Union(_) = field.parent_def(db) { 465 if let VariantDef::Union(_) = field.parent_def(db) {
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 }
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 8e3dcd99c..43b8560ca 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -314,7 +314,7 @@ 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::FieldShorthand { local: _, field }) => { 317 Some(NameClass::PatFieldShorthand { local: _, field }) => {
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 == self.def => Reference {
320 file_range: self.sema.original_range(name.syntax()), 320 file_range: self.sema.original_range(name.syntax()),