aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/from_id.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/from_id.rs')
-rw-r--r--crates/ra_hir/src/from_id.rs65
1 files changed, 63 insertions, 2 deletions
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs
index b7692d407..7042422cc 100644
--- a/crates/ra_hir/src/from_id.rs
+++ b/crates/ra_hir/src/from_id.rs
@@ -3,9 +3,14 @@
3//! It's unclear if we need this long-term, but it's definitelly useful while we 3//! It's unclear if we need this long-term, but it's definitelly useful while we
4//! are splitting the hir. 4//! are splitting the hir.
5 5
6use hir_def::{AdtId, AssocItemId, DefWithBodyId, EnumVariantId, GenericDefId, ModuleDefId}; 6use hir_def::{
7 AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, GenericDefId, ModuleDefId, StructId,
8 TypeAliasId, UnionId,
9};
7 10
8use crate::{Adt, AssocItem, DefWithBody, EnumVariant, GenericDef, ModuleDef}; 11use crate::{
12 ty::TypableDef, Adt, AssocItem, DefWithBody, EnumVariant, GenericDef, ModuleDef, TypeAlias,
13};
9 14
10macro_rules! from_id { 15macro_rules! from_id {
11 ($(($id:path, $ty:path)),*) => {$( 16 ($(($id:path, $ty:path)),*) => {$(
@@ -83,6 +88,16 @@ impl From<DefWithBody> for DefWithBodyId {
83 } 88 }
84} 89}
85 90
91impl From<DefWithBodyId> for DefWithBody {
92 fn from(def: DefWithBodyId) -> Self {
93 match def {
94 DefWithBodyId::FunctionId(it) => DefWithBody::Function(it.into()),
95 DefWithBodyId::StaticId(it) => DefWithBody::Static(it.into()),
96 DefWithBodyId::ConstId(it) => DefWithBody::Const(it.into()),
97 }
98 }
99}
100
86impl From<AssocItemId> for AssocItem { 101impl From<AssocItemId> for AssocItem {
87 fn from(def: AssocItemId) -> Self { 102 fn from(def: AssocItemId) -> Self {
88 match def { 103 match def {
@@ -122,3 +137,49 @@ impl From<GenericDefId> for GenericDef {
122 } 137 }
123 } 138 }
124} 139}
140
141impl From<AdtId> for TypableDef {
142 fn from(id: AdtId) -> Self {
143 Adt::from(id).into()
144 }
145}
146
147impl From<StructId> for TypableDef {
148 fn from(id: StructId) -> Self {
149 AdtId::StructId(id).into()
150 }
151}
152
153impl From<UnionId> for TypableDef {
154 fn from(id: UnionId) -> Self {
155 AdtId::UnionId(id).into()
156 }
157}
158
159impl From<EnumId> for TypableDef {
160 fn from(id: EnumId) -> Self {
161 AdtId::EnumId(id).into()
162 }
163}
164
165impl From<EnumVariantId> for TypableDef {
166 fn from(id: EnumVariantId) -> Self {
167 EnumVariant::from(id).into()
168 }
169}
170
171impl From<TypeAliasId> for TypableDef {
172 fn from(id: TypeAliasId) -> Self {
173 TypeAlias::from(id).into()
174 }
175}
176
177impl From<Adt> for GenericDefId {
178 fn from(id: Adt) -> Self {
179 match id {
180 Adt::Struct(it) => it.id.into(),
181 Adt::Union(it) => it.id.into(),
182 Adt::Enum(it) => it.id.into(),
183 }
184 }
185}