aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/from_id.rs
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-11-28 07:19:14 +0000
committerSeivan Heidari <[email protected]>2019-11-28 07:19:14 +0000
commit18a0937585b836ec5ed054b9ae48e0156ab6d9ef (patch)
tree9de2c0267ddcc00df717f90034d0843d751a851b /crates/ra_hir/src/from_id.rs
parenta7394b44c870f585eacfeb3036a33471aff49ff8 (diff)
parent484acc8a61d599662ed63a4cbda091d38a982551 (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.rs104
1 files changed, 26 insertions, 78 deletions
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs
index 529ac8251..e96a18d12 100644
--- a/crates/ra_hir/src/from_id.rs
+++ b/crates/ra_hir/src/from_id.rs
@@ -4,14 +4,13 @@
4//! are splitting the hir. 4//! are splitting the hir.
5 5
6use hir_def::{ 6use hir_def::{
7 AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, 7 AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, ModuleDefId,
8 GenericDefId, ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId, 8 StructFieldId, VariantId,
9}; 9};
10 10
11use crate::{ 11use crate::{
12 ty::{CallableDef, TypableDef}, 12 Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField,
13 Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, 13 VariantDef,
14 ModuleDef, Static, StructField, TypeAlias, VariantDef,
15}; 14};
16 15
17impl From<ra_db::CrateId> for Crate { 16impl From<ra_db::CrateId> for Crate {
@@ -138,72 +137,6 @@ impl From<GenericDef> for GenericDefId {
138 } 137 }
139} 138}
140 139
141impl From<GenericDefId> for GenericDef {
142 fn from(def: GenericDefId) -> Self {
143 match def {
144 GenericDefId::FunctionId(it) => GenericDef::Function(it.into()),
145 GenericDefId::AdtId(it) => GenericDef::Adt(it.into()),
146 GenericDefId::TraitId(it) => GenericDef::Trait(it.into()),
147 GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()),
148 GenericDefId::ImplId(it) => GenericDef::ImplBlock(it.into()),
149 GenericDefId::EnumVariantId(it) => GenericDef::EnumVariant(it.into()),
150 GenericDefId::ConstId(it) => GenericDef::Const(it.into()),
151 }
152 }
153}
154
155impl From<AdtId> for TypableDef {
156 fn from(id: AdtId) -> Self {
157 Adt::from(id).into()
158 }
159}
160
161impl From<StructId> for TypableDef {
162 fn from(id: StructId) -> Self {
163 AdtId::StructId(id).into()
164 }
165}
166
167impl From<UnionId> for TypableDef {
168 fn from(id: UnionId) -> Self {
169 AdtId::UnionId(id).into()
170 }
171}
172
173impl From<EnumId> for TypableDef {
174 fn from(id: EnumId) -> Self {
175 AdtId::EnumId(id).into()
176 }
177}
178
179impl From<EnumVariantId> for TypableDef {
180 fn from(id: EnumVariantId) -> Self {
181 EnumVariant::from(id).into()
182 }
183}
184
185impl From<TypeAliasId> for TypableDef {
186 fn from(id: TypeAliasId) -> Self {
187 TypeAlias::from(id).into()
188 }
189}
190
191impl From<FunctionId> for TypableDef {
192 fn from(id: FunctionId) -> Self {
193 Function::from(id).into()
194 }
195}
196impl From<ConstId> for TypableDef {
197 fn from(id: ConstId) -> Self {
198 Const::from(id).into()
199 }
200}
201impl From<StaticId> for TypableDef {
202 fn from(id: StaticId) -> Self {
203 Static::from(id).into()
204 }
205}
206
207impl From<Adt> for GenericDefId { 140impl From<Adt> for GenericDefId {
208 fn from(id: Adt) -> Self { 141 fn from(id: Adt) -> Self {
209 match id { 142 match id {
@@ -214,14 +147,12 @@ impl From<Adt> for GenericDefId {
214 } 147 }
215} 148}
216 149
217impl From<CallableDef> for GenericDefId { 150impl From<VariantId> for VariantDef {
218 fn from(def: CallableDef) -> Self { 151 fn from(def: VariantId) -> Self {
219 match def { 152 match def {
220 CallableDef::Function(it) => it.id.into(), 153 VariantId::StructId(it) => VariantDef::Struct(it.into()),
221 CallableDef::Struct(it) => it.id.into(), 154 VariantId::EnumVariantId(it) => VariantDef::EnumVariant(it.into()),
222 CallableDef::EnumVariant(it) => { 155 VariantId::UnionId(it) => VariantDef::Union(it.into()),
223 EnumVariantId { parent: it.parent.id, local_id: it.id }.into()
224 }
225 } 156 }
226 } 157 }
227} 158}
@@ -231,6 +162,7 @@ impl From<VariantDef> for VariantId {
231 match def { 162 match def {
232 VariantDef::Struct(it) => VariantId::StructId(it.id), 163 VariantDef::Struct(it) => VariantId::StructId(it.id),
233 VariantDef::EnumVariant(it) => VariantId::EnumVariantId(it.into()), 164 VariantDef::EnumVariant(it) => VariantId::EnumVariantId(it.into()),
165 VariantDef::Union(it) => VariantId::UnionId(it.id),
234 } 166 }
235 } 167 }
236} 168}
@@ -241,6 +173,12 @@ impl From<StructField> for StructFieldId {
241 } 173 }
242} 174}
243 175
176impl From<StructFieldId> for StructField {
177 fn from(def: StructFieldId) -> Self {
178 StructField { parent: def.parent.into(), id: def.local_id }
179 }
180}
181
244impl From<AttrDef> for AttrDefId { 182impl From<AttrDef> for AttrDefId {
245 fn from(def: AttrDef) -> Self { 183 fn from(def: AttrDef) -> Self {
246 match def { 184 match def {
@@ -257,3 +195,13 @@ impl From<AttrDef> for AttrDefId {
257 } 195 }
258 } 196 }
259} 197}
198
199impl From<AssocItem> for GenericDefId {
200 fn from(item: AssocItem) -> Self {
201 match item {
202 AssocItem::Function(f) => f.id.into(),
203 AssocItem::Const(c) => c.id.into(),
204 AssocItem::TypeAlias(t) => t.id.into(),
205 }
206 }
207}