diff options
Diffstat (limited to 'crates/hir_def/src/lib.rs')
-rw-r--r-- | crates/hir_def/src/lib.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index c9e07de86..e2af0e514 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs | |||
@@ -27,6 +27,7 @@ pub mod dyn_map; | |||
27 | pub mod keys; | 27 | pub mod keys; |
28 | 28 | ||
29 | pub mod item_tree; | 29 | pub mod item_tree; |
30 | pub mod intern; | ||
30 | 31 | ||
31 | pub mod adt; | 32 | pub mod adt; |
32 | pub mod data; | 33 | pub mod data; |
@@ -55,6 +56,7 @@ use std::{ | |||
55 | sync::Arc, | 56 | sync::Arc, |
56 | }; | 57 | }; |
57 | 58 | ||
59 | use adt::VariantData; | ||
58 | use base_db::{impl_intern_key, salsa, CrateId}; | 60 | use base_db::{impl_intern_key, salsa, CrateId}; |
59 | use hir_expand::{ | 61 | use hir_expand::{ |
60 | ast_id_map::FileAstId, | 62 | ast_id_map::FileAstId, |
@@ -441,6 +443,26 @@ pub enum VariantId { | |||
441 | } | 443 | } |
442 | impl_from!(EnumVariantId, StructId, UnionId for VariantId); | 444 | impl_from!(EnumVariantId, StructId, UnionId for VariantId); |
443 | 445 | ||
446 | impl VariantId { | ||
447 | pub fn variant_data(self, db: &dyn db::DefDatabase) -> Arc<VariantData> { | ||
448 | match self { | ||
449 | VariantId::StructId(it) => db.struct_data(it).variant_data.clone(), | ||
450 | VariantId::UnionId(it) => db.union_data(it).variant_data.clone(), | ||
451 | VariantId::EnumVariantId(it) => { | ||
452 | db.enum_data(it.parent).variants[it.local_id].variant_data.clone() | ||
453 | } | ||
454 | } | ||
455 | } | ||
456 | |||
457 | pub fn file_id(self, db: &dyn db::DefDatabase) -> HirFileId { | ||
458 | match self { | ||
459 | VariantId::EnumVariantId(it) => it.parent.lookup(db).id.file_id(), | ||
460 | VariantId::StructId(it) => it.lookup(db).id.file_id(), | ||
461 | VariantId::UnionId(it) => it.lookup(db).id.file_id(), | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | |||
444 | trait Intern { | 466 | trait Intern { |
445 | type ID; | 467 | type ID; |
446 | fn intern(self, db: &dyn db::DefDatabase) -> Self::ID; | 468 | fn intern(self, db: &dyn db::DefDatabase) -> Self::ID; |