aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/lib.rs45
1 files changed, 15 insertions, 30 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 564434ccc..b71d626c3 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -65,6 +65,7 @@ use item_tree::{
65 Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, ModItem, Static, Struct, Trait, 65 Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, ModItem, Static, Struct, Trait,
66 TypeAlias, Union, 66 TypeAlias, Union,
67}; 67};
68use stdx::impl_from;
68 69
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 70#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
70pub struct ModuleId { 71pub struct ModuleId {
@@ -223,25 +224,6 @@ pub struct TypeParamId {
223 224
224pub type LocalTypeParamId = Idx<generics::TypeParamData>; 225pub type LocalTypeParamId = Idx<generics::TypeParamData>;
225 226
226macro_rules! impl_froms {
227 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
228 $(
229 impl From<$v> for $e {
230 fn from(it: $v) -> $e {
231 $e::$v(it)
232 }
233 }
234 $($(
235 impl From<$sv> for $e {
236 fn from(it: $sv) -> $e {
237 $e::$v($v::$sv(it))
238 }
239 }
240 )*)?
241 )*
242 }
243}
244
245#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 227#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
246pub enum ContainerId { 228pub enum ContainerId {
247 ModuleId(ModuleId), 229 ModuleId(ModuleId),
@@ -254,7 +236,7 @@ pub enum AssocContainerId {
254 ImplId(ImplId), 236 ImplId(ImplId),
255 TraitId(TraitId), 237 TraitId(TraitId),
256} 238}
257impl_froms!(AssocContainerId: ContainerId); 239impl_from!(ContainerId for AssocContainerId);
258 240
259/// A Data Type 241/// A Data Type
260#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 242#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -263,7 +245,7 @@ pub enum AdtId {
263 UnionId(UnionId), 245 UnionId(UnionId),
264 EnumId(EnumId), 246 EnumId(EnumId),
265} 247}
266impl_froms!(AdtId: StructId, UnionId, EnumId); 248impl_from!(StructId, UnionId, EnumId for AdtId);
267 249
268/// The defs which can be visible in the module. 250/// The defs which can be visible in the module.
269#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 251#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -279,8 +261,8 @@ pub enum ModuleDefId {
279 TypeAliasId(TypeAliasId), 261 TypeAliasId(TypeAliasId),
280 BuiltinType(BuiltinType), 262 BuiltinType(BuiltinType),
281} 263}
282impl_froms!( 264impl_from!(
283 ModuleDefId: ModuleId, 265 ModuleId,
284 FunctionId, 266 FunctionId,
285 AdtId(StructId, EnumId, UnionId), 267 AdtId(StructId, EnumId, UnionId),
286 EnumVariantId, 268 EnumVariantId,
@@ -289,6 +271,7 @@ impl_froms!(
289 TraitId, 271 TraitId,
290 TypeAliasId, 272 TypeAliasId,
291 BuiltinType 273 BuiltinType
274 for ModuleDefId
292); 275);
293 276
294/// The defs which have a body. 277/// The defs which have a body.
@@ -299,7 +282,7 @@ pub enum DefWithBodyId {
299 ConstId(ConstId), 282 ConstId(ConstId),
300} 283}
301 284
302impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId); 285impl_from!(FunctionId, ConstId, StaticId for DefWithBodyId);
303 286
304#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 287#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
305pub enum AssocItemId { 288pub enum AssocItemId {
@@ -311,7 +294,7 @@ pub enum AssocItemId {
311// sure that you can only turn actual assoc items into AssocItemIds. This would 294// sure that you can only turn actual assoc items into AssocItemIds. This would
312// require not implementing From, and instead having some checked way of 295// require not implementing From, and instead having some checked way of
313// casting them, and somehow making the constructors private, which would be annoying. 296// casting them, and somehow making the constructors private, which would be annoying.
314impl_froms!(AssocItemId: FunctionId, ConstId, TypeAliasId); 297impl_from!(FunctionId, ConstId, TypeAliasId for AssocItemId);
315 298
316#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 299#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
317pub enum GenericDefId { 300pub enum GenericDefId {
@@ -326,14 +309,15 @@ pub enum GenericDefId {
326 // consts can have type parameters from their parents (i.e. associated consts of traits) 309 // consts can have type parameters from their parents (i.e. associated consts of traits)
327 ConstId(ConstId), 310 ConstId(ConstId),
328} 311}
329impl_froms!( 312impl_from!(
330 GenericDefId: FunctionId, 313 FunctionId,
331 AdtId(StructId, EnumId, UnionId), 314 AdtId(StructId, EnumId, UnionId),
332 TraitId, 315 TraitId,
333 TypeAliasId, 316 TypeAliasId,
334 ImplId, 317 ImplId,
335 EnumVariantId, 318 EnumVariantId,
336 ConstId 319 ConstId
320 for GenericDefId
337); 321);
338 322
339impl From<AssocItemId> for GenericDefId { 323impl From<AssocItemId> for GenericDefId {
@@ -361,8 +345,8 @@ pub enum AttrDefId {
361 ImplId(ImplId), 345 ImplId(ImplId),
362} 346}
363 347
364impl_froms!( 348impl_from!(
365 AttrDefId: ModuleId, 349 ModuleId,
366 FieldId, 350 FieldId,
367 AdtId(StructId, EnumId, UnionId), 351 AdtId(StructId, EnumId, UnionId),
368 EnumVariantId, 352 EnumVariantId,
@@ -373,6 +357,7 @@ impl_froms!(
373 TypeAliasId, 357 TypeAliasId,
374 MacroDefId, 358 MacroDefId,
375 ImplId 359 ImplId
360 for AttrDefId
376); 361);
377 362
378#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 363#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -381,7 +366,7 @@ pub enum VariantId {
381 StructId(StructId), 366 StructId(StructId),
382 UnionId(UnionId), 367 UnionId(UnionId),
383} 368}
384impl_froms!(VariantId: EnumVariantId, StructId, UnionId); 369impl_from!(EnumVariantId, StructId, UnionId for VariantId);
385 370
386trait Intern { 371trait Intern {
387 type ID; 372 type ID;