diff options
author | Seivan Heidari <[email protected]> | 2019-11-22 00:54:34 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-22 00:54:34 +0000 |
commit | a63a269ec84192114cc1ac7f079e96144ae877a1 (patch) | |
tree | bfa5b8496a958e825423d09f6abbdf5db5c54efa /crates/ra_hir/src/from_id.rs | |
parent | 358a1bcd708c622836723e5201b6de77cc9ff327 (diff) | |
parent | c9273828b3c44fba62d1b989480c287d923839d2 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir/src/from_id.rs')
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index b7692d407..e8ed04056 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs | |||
@@ -3,9 +3,22 @@ | |||
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, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, | ||
8 | ModuleDefId, StaticId, StructId, TypeAliasId, UnionId, | ||
9 | }; | ||
7 | 10 | ||
8 | use crate::{Adt, AssocItem, DefWithBody, EnumVariant, GenericDef, ModuleDef}; | 11 | use crate::{ |
12 | ty::{CallableDef, TypableDef}, | ||
13 | Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, ModuleDef, | ||
14 | Static, TypeAlias, | ||
15 | }; | ||
16 | |||
17 | impl From<ra_db::CrateId> for Crate { | ||
18 | fn from(crate_id: ra_db::CrateId) -> Self { | ||
19 | Crate { crate_id } | ||
20 | } | ||
21 | } | ||
9 | 22 | ||
10 | macro_rules! from_id { | 23 | macro_rules! from_id { |
11 | ($(($id:path, $ty:path)),*) => {$( | 24 | ($(($id:path, $ty:path)),*) => {$( |
@@ -83,6 +96,16 @@ impl From<DefWithBody> for DefWithBodyId { | |||
83 | } | 96 | } |
84 | } | 97 | } |
85 | 98 | ||
99 | impl From<DefWithBodyId> for DefWithBody { | ||
100 | fn from(def: DefWithBodyId) -> Self { | ||
101 | match def { | ||
102 | DefWithBodyId::FunctionId(it) => DefWithBody::Function(it.into()), | ||
103 | DefWithBodyId::StaticId(it) => DefWithBody::Static(it.into()), | ||
104 | DefWithBodyId::ConstId(it) => DefWithBody::Const(it.into()), | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | |||
86 | impl From<AssocItemId> for AssocItem { | 109 | impl From<AssocItemId> for AssocItem { |
87 | fn from(def: AssocItemId) -> Self { | 110 | fn from(def: AssocItemId) -> Self { |
88 | match def { | 111 | match def { |
@@ -122,3 +145,77 @@ impl From<GenericDefId> for GenericDef { | |||
122 | } | 145 | } |
123 | } | 146 | } |
124 | } | 147 | } |
148 | |||
149 | impl From<AdtId> for TypableDef { | ||
150 | fn from(id: AdtId) -> Self { | ||
151 | Adt::from(id).into() | ||
152 | } | ||
153 | } | ||
154 | |||
155 | impl From<StructId> for TypableDef { | ||
156 | fn from(id: StructId) -> Self { | ||
157 | AdtId::StructId(id).into() | ||
158 | } | ||
159 | } | ||
160 | |||
161 | impl From<UnionId> for TypableDef { | ||
162 | fn from(id: UnionId) -> Self { | ||
163 | AdtId::UnionId(id).into() | ||
164 | } | ||
165 | } | ||
166 | |||
167 | impl From<EnumId> for TypableDef { | ||
168 | fn from(id: EnumId) -> Self { | ||
169 | AdtId::EnumId(id).into() | ||
170 | } | ||
171 | } | ||
172 | |||
173 | impl From<EnumVariantId> for TypableDef { | ||
174 | fn from(id: EnumVariantId) -> Self { | ||
175 | EnumVariant::from(id).into() | ||
176 | } | ||
177 | } | ||
178 | |||
179 | impl From<TypeAliasId> for TypableDef { | ||
180 | fn from(id: TypeAliasId) -> Self { | ||
181 | TypeAlias::from(id).into() | ||
182 | } | ||
183 | } | ||
184 | |||
185 | impl From<FunctionId> for TypableDef { | ||
186 | fn from(id: FunctionId) -> Self { | ||
187 | Function::from(id).into() | ||
188 | } | ||
189 | } | ||
190 | impl From<ConstId> for TypableDef { | ||
191 | fn from(id: ConstId) -> Self { | ||
192 | Const::from(id).into() | ||
193 | } | ||
194 | } | ||
195 | impl From<StaticId> for TypableDef { | ||
196 | fn from(id: StaticId) -> Self { | ||
197 | Static::from(id).into() | ||
198 | } | ||
199 | } | ||
200 | |||
201 | impl From<Adt> for GenericDefId { | ||
202 | fn from(id: Adt) -> Self { | ||
203 | match id { | ||
204 | Adt::Struct(it) => it.id.into(), | ||
205 | Adt::Union(it) => it.id.into(), | ||
206 | Adt::Enum(it) => it.id.into(), | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | impl From<CallableDef> for GenericDefId { | ||
212 | fn from(def: CallableDef) -> Self { | ||
213 | match def { | ||
214 | CallableDef::Function(it) => it.id.into(), | ||
215 | CallableDef::Struct(it) => it.id.into(), | ||
216 | CallableDef::EnumVariant(it) => { | ||
217 | EnumVariantId { parent: it.parent.id, local_id: it.id }.into() | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||