aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/utils.rs')
-rw-r--r--crates/ra_hir/src/ty/utils.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/utils.rs b/crates/ra_hir/src/ty/utils.rs
index 80ffceb4b..f82e6ac9b 100644
--- a/crates/ra_hir/src/ty/utils.rs
+++ b/crates/ra_hir/src/ty/utils.rs
@@ -1,11 +1,13 @@
1//! Helper functions for working with def, which don't need to be a separate 1//! Helper functions for working with def, which don't need to be a separate
2//! query, but can't be computed directly from `*Data` (ie, which need a `db`). 2//! query, but can't be computed directly from `*Data` (ie, which need a `db`).
3use std::sync::Arc;
3 4
4use hir_def::{ 5use hir_def::{
6 adt::VariantData,
5 db::DefDatabase, 7 db::DefDatabase,
6 resolver::{HasResolver, TypeNs}, 8 resolver::{HasResolver, TypeNs},
7 type_ref::TypeRef, 9 type_ref::TypeRef,
8 TraitId, TypeAliasId, 10 TraitId, TypeAliasId, VariantId,
9}; 11};
10use hir_expand::name::{self, Name}; 12use hir_expand::name::{self, Name};
11 13
@@ -61,3 +63,13 @@ pub(super) fn associated_type_by_name_including_super_traits(
61 .into_iter() 63 .into_iter()
62 .find_map(|t| db.trait_data(t).associated_type_by_name(name)) 64 .find_map(|t| db.trait_data(t).associated_type_by_name(name))
63} 65}
66
67pub(super) fn variant_data(db: &impl DefDatabase, var: VariantId) -> Arc<VariantData> {
68 match var {
69 VariantId::StructId(it) => db.struct_data(it).variant_data.clone(),
70 VariantId::UnionId(it) => db.union_data(it).variant_data.clone(),
71 VariantId::EnumVariantId(it) => {
72 db.enum_data(it.parent).variants[it.local_id].variant_data.clone()
73 }
74 }
75}