diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-21 12:50:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-21 12:50:12 +0000 |
commit | 1f61915bde4c5d8d4fe2e9b8dfa9445008730b79 (patch) | |
tree | a6fd0b6ad8b6c87d28e6e1b36bb9b2fbae2c1b09 /crates/ra_hir/src/from_id.rs | |
parent | 612a72fc4ea4376920f2a7da7b3c334227c1716c (diff) | |
parent | c37d1c5b381365ce2d07dfe4b871e43995ccea2d (diff) |
Merge #2337
2337: Move resolver to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/from_id.rs')
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index b7692d407..a3e9d8525 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs | |||
@@ -3,9 +3,21 @@ | |||
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::TypableDef, Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, | ||
13 | ModuleDef, Static, TypeAlias, | ||
14 | }; | ||
15 | |||
16 | impl From<ra_db::CrateId> for Crate { | ||
17 | fn from(crate_id: ra_db::CrateId) -> Self { | ||
18 | Crate { crate_id } | ||
19 | } | ||
20 | } | ||
9 | 21 | ||
10 | macro_rules! from_id { | 22 | macro_rules! from_id { |
11 | ($(($id:path, $ty:path)),*) => {$( | 23 | ($(($id:path, $ty:path)),*) => {$( |
@@ -83,6 +95,16 @@ impl From<DefWithBody> for DefWithBodyId { | |||
83 | } | 95 | } |
84 | } | 96 | } |
85 | 97 | ||
98 | impl From<DefWithBodyId> for DefWithBody { | ||
99 | fn from(def: DefWithBodyId) -> Self { | ||
100 | match def { | ||
101 | DefWithBodyId::FunctionId(it) => DefWithBody::Function(it.into()), | ||
102 | DefWithBodyId::StaticId(it) => DefWithBody::Static(it.into()), | ||
103 | DefWithBodyId::ConstId(it) => DefWithBody::Const(it.into()), | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
86 | impl From<AssocItemId> for AssocItem { | 108 | impl From<AssocItemId> for AssocItem { |
87 | fn from(def: AssocItemId) -> Self { | 109 | fn from(def: AssocItemId) -> Self { |
88 | match def { | 110 | match def { |
@@ -122,3 +144,65 @@ impl From<GenericDefId> for GenericDef { | |||
122 | } | 144 | } |
123 | } | 145 | } |
124 | } | 146 | } |
147 | |||
148 | impl From<AdtId> for TypableDef { | ||
149 | fn from(id: AdtId) -> Self { | ||
150 | Adt::from(id).into() | ||
151 | } | ||
152 | } | ||
153 | |||
154 | impl From<StructId> for TypableDef { | ||
155 | fn from(id: StructId) -> Self { | ||
156 | AdtId::StructId(id).into() | ||
157 | } | ||
158 | } | ||
159 | |||
160 | impl From<UnionId> for TypableDef { | ||
161 | fn from(id: UnionId) -> Self { | ||
162 | AdtId::UnionId(id).into() | ||
163 | } | ||
164 | } | ||
165 | |||
166 | impl From<EnumId> for TypableDef { | ||
167 | fn from(id: EnumId) -> Self { | ||
168 | AdtId::EnumId(id).into() | ||
169 | } | ||
170 | } | ||
171 | |||
172 | impl From<EnumVariantId> for TypableDef { | ||
173 | fn from(id: EnumVariantId) -> Self { | ||
174 | EnumVariant::from(id).into() | ||
175 | } | ||
176 | } | ||
177 | |||
178 | impl From<TypeAliasId> for TypableDef { | ||
179 | fn from(id: TypeAliasId) -> Self { | ||
180 | TypeAlias::from(id).into() | ||
181 | } | ||
182 | } | ||
183 | |||
184 | impl From<FunctionId> for TypableDef { | ||
185 | fn from(id: FunctionId) -> Self { | ||
186 | Function::from(id).into() | ||
187 | } | ||
188 | } | ||
189 | impl From<ConstId> for TypableDef { | ||
190 | fn from(id: ConstId) -> Self { | ||
191 | Const::from(id).into() | ||
192 | } | ||
193 | } | ||
194 | impl From<StaticId> for TypableDef { | ||
195 | fn from(id: StaticId) -> Self { | ||
196 | Static::from(id).into() | ||
197 | } | ||
198 | } | ||
199 | |||
200 | impl From<Adt> for GenericDefId { | ||
201 | fn from(id: Adt) -> Self { | ||
202 | match id { | ||
203 | Adt::Struct(it) => it.id.into(), | ||
204 | Adt::Union(it) => it.id.into(), | ||
205 | Adt::Enum(it) => it.id.into(), | ||
206 | } | ||
207 | } | ||
208 | } | ||