From 1602db7d7d6aa38b4ee50de8cbe734529853d615 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Oct 2019 11:23:30 +0300 Subject: add ModuleDefId to hir_def --- crates/ra_hir_def/src/lib.rs | 58 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 8cbff673c..93ad40005 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -23,7 +23,7 @@ use ra_arena::{impl_arena_id, RawId}; use ra_db::{salsa, CrateId, FileId}; use ra_syntax::{ast, AstNode, SyntaxNode}; -use crate::db::InternDatabase; +use crate::{builtin_type::BuiltinType, db::InternDatabase}; #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub struct Source { @@ -256,7 +256,7 @@ pub struct EnumVariantId { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct LocalEnumVariantId(RawId); +pub struct LocalEnumVariantId(RawId); impl_arena_id!(LocalEnumVariantId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -306,3 +306,57 @@ impl AstItemDef for TypeAliasId { db.lookup_intern_type_alias(self) } } + +macro_rules! impl_froms { + ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { + $( + impl From<$v> for $e { + fn from(it: $v) -> $e { + $e::$v(it) + } + } + $($( + impl From<$sv> for $e { + fn from(it: $sv) -> $e { + $e::$v($v::$sv(it)) + } + } + )*)? + )* + } +} + +/// A Data Type +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum AdtId { + StructId(StructId), + UnionId(UnionId), + EnumId(EnumId), +} +impl_froms!(AdtId: StructId, UnionId, EnumId); + +/// The defs which can be visible in the module. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum ModuleDefId { + ModuleId(ModuleId), + FunctionId(FunctionId), + AdtId(AdtId), + // Can't be directly declared, but can be imported. + EnumVariantId(EnumVariantId), + ConstId(ConstId), + StaticId(StaticId), + TraitId(TraitId), + TypeAliasId(TypeAliasId), + BuiltinType(BuiltinType), +} +impl_froms!( + ModuleDefId: ModuleId, + FunctionId, + AdtId(StructId, EnumId, UnionId), + EnumVariantId, + ConstId, + StaticId, + TraitId, + TypeAliasId, + BuiltinType +); -- cgit v1.2.3