aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/adt.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs10
-rw-r--r--crates/ra_hir_def/src/test_db.rs4
3 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 0091bfbc3..0cf418d30 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -129,6 +129,10 @@ impl VariantData {
129 } 129 }
130 } 130 }
131 131
132 pub fn field(&self, name: &Name) -> Option<LocalStructFieldId> {
133 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None })
134 }
135
132 pub fn is_unit(&self) -> bool { 136 pub fn is_unit(&self) -> bool {
133 match self { 137 match self {
134 VariantData::Unit => true, 138 VariantData::Unit => true,
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index a88a78b38..274dd1467 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -489,6 +489,16 @@ impl HasModule for AdtId {
489 } 489 }
490} 490}
491 491
492impl HasModule for DefWithBodyId {
493 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
494 match self {
495 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
496 DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
497 DefWithBodyId::ConstId(it) => it.lookup(db).module(db),
498 }
499 }
500}
501
492impl HasModule for StaticLoc { 502impl HasModule for StaticLoc {
493 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { 503 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
494 self.container 504 self.container
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs
index 439e8a412..54e3a84bd 100644
--- a/crates/ra_hir_def/src/test_db.rs
+++ b/crates/ra_hir_def/src/test_db.rs
@@ -24,7 +24,9 @@ impl salsa::Database for TestDB {
24 fn salsa_runtime(&self) -> &salsa::Runtime<Self> { 24 fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
25 &self.runtime 25 &self.runtime
26 } 26 }
27 27 fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> {
28 &mut self.runtime
29 }
28 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) { 30 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
29 let mut events = self.events.lock().unwrap(); 31 let mut events = self.events.lock().unwrap();
30 if let Some(events) = &mut *events { 32 if let Some(events) = &mut *events {