aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/doc_links.rs2
-rw-r--r--crates/ide/src/goto_definition.rs2
-rw-r--r--crates/ide/src/references.rs2
-rw-r--r--crates/ide/src/syntax_highlighting.rs4
-rw-r--r--crates/ide_db/src/defs.rs20
-rw-r--r--crates/ide_db/src/search.rs4
6 files changed, 17 insertions, 17 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 71382f13e..5e4147362 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -233,7 +233,7 @@ pub(crate) fn external_docs(
233 let definition = match_ast! { 233 let definition = match_ast! {
234 match node { 234 match node {
235 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), 235 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)),
236 ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition_or_reference(sema.db)), 236 ast::Name(name) => classify_name(&sema, &name).map(|d| d.reference_or_definition(sema.db)),
237 _ => None, 237 _ => None,
238 } 238 }
239 }; 239 };
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 79fdb75ed..be2f81aab 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -40,7 +40,7 @@ pub(crate) fn goto_definition(
40 reference_definition(&sema, &name_ref).to_vec() 40 reference_definition(&sema, &name_ref).to_vec()
41 }, 41 },
42 ast::Name(name) => { 42 ast::Name(name) => {
43 let def = classify_name(&sema, &name)?.definition_or_reference(sema.db); 43 let def = classify_name(&sema, &name)?.reference_or_definition(sema.db);
44 let nav = def.try_to_nav(sema.db)?; 44 let nav = def.try_to_nav(sema.db)?;
45 vec![nav] 45 vec![nav]
46 }, 46 },
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index ec64207d2..95d872b83 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -132,7 +132,7 @@ fn find_name(
132 opt_name: Option<ast::Name>, 132 opt_name: Option<ast::Name>,
133) -> Option<RangeInfo<Definition>> { 133) -> Option<RangeInfo<Definition>> {
134 if let Some(name) = opt_name { 134 if let Some(name) = opt_name {
135 let def = classify_name(sema, &name)?.definition_or_reference(sema.db); 135 let def = classify_name(sema, &name)?.reference_or_definition(sema.db);
136 let range = name.syntax().text_range(); 136 let range = name.syntax().text_range();
137 return Some(RangeInfo::new(range, def)); 137 return Some(RangeInfo::new(range, def));
138 } 138 }
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 4d8cd98c7..928f771a9 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -459,9 +459,9 @@ 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::PatFieldShorthand { field, .. }) => { 462 Some(NameClass::PatFieldShorthand { field_ref, .. }) => {
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_ref {
465 if let VariantDef::Union(_) = field.parent_def(db) { 465 if let VariantDef::Union(_) = field.parent_def(db) {
466 h |= HighlightModifier::Unsafe; 466 h |= HighlightModifier::Unsafe;
467 } 467 }
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 }
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