diff options
author | Aleksey Kladov <[email protected]> | 2019-11-21 09:21:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-21 10:25:03 +0000 |
commit | 0102fb41337ac0442e689d410bb424d215e9a7bd (patch) | |
tree | c77bf501427adc77c0fc92fe75fd9f314087b120 /crates/ra_hir/src/from_id.rs | |
parent | 612a72fc4ea4376920f2a7da7b3c334227c1716c (diff) |
Decouple Resolver
Diffstat (limited to 'crates/ra_hir/src/from_id.rs')
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 65 |
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 | ||
6 | use hir_def::{AdtId, AssocItemId, DefWithBodyId, EnumVariantId, GenericDefId, ModuleDefId}; | 6 | use hir_def::{ |
7 | AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, GenericDefId, ModuleDefId, StructId, | ||
8 | TypeAliasId, UnionId, | ||
9 | }; | ||
7 | 10 | ||
8 | use crate::{Adt, AssocItem, DefWithBody, EnumVariant, GenericDef, ModuleDef}; | 11 | use crate::{ |
12 | ty::TypableDef, Adt, AssocItem, DefWithBody, EnumVariant, GenericDef, ModuleDef, TypeAlias, | ||
13 | }; | ||
9 | 14 | ||
10 | macro_rules! from_id { | 15 | macro_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 | ||
91 | impl 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 | |||
86 | impl From<AssocItemId> for AssocItem { | 101 | impl 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 | |||
141 | impl From<AdtId> for TypableDef { | ||
142 | fn from(id: AdtId) -> Self { | ||
143 | Adt::from(id).into() | ||
144 | } | ||
145 | } | ||
146 | |||
147 | impl From<StructId> for TypableDef { | ||
148 | fn from(id: StructId) -> Self { | ||
149 | AdtId::StructId(id).into() | ||
150 | } | ||
151 | } | ||
152 | |||
153 | impl From<UnionId> for TypableDef { | ||
154 | fn from(id: UnionId) -> Self { | ||
155 | AdtId::UnionId(id).into() | ||
156 | } | ||
157 | } | ||
158 | |||
159 | impl From<EnumId> for TypableDef { | ||
160 | fn from(id: EnumId) -> Self { | ||
161 | AdtId::EnumId(id).into() | ||
162 | } | ||
163 | } | ||
164 | |||
165 | impl From<EnumVariantId> for TypableDef { | ||
166 | fn from(id: EnumVariantId) -> Self { | ||
167 | EnumVariant::from(id).into() | ||
168 | } | ||
169 | } | ||
170 | |||
171 | impl From<TypeAliasId> for TypableDef { | ||
172 | fn from(id: TypeAliasId) -> Self { | ||
173 | TypeAlias::from(id).into() | ||
174 | } | ||
175 | } | ||
176 | |||
177 | impl 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 | } | ||