Merge #2141
2141: add ModuleDefId to hir_def r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
d067afb064
@ -3,7 +3,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::type_ref::TypeRef;
|
||||
use hir_def::{type_ref::TypeRef, LocalEnumVariantId};
|
||||
use hir_expand::name::AsName;
|
||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||
use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
|
||||
@ -68,7 +68,7 @@ pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EnumData {
|
||||
pub(crate) name: Option<Name>,
|
||||
pub(crate) variants: Arena<EnumVariantId, EnumVariantData>,
|
||||
pub(crate) variants: Arena<LocalEnumVariantId, EnumVariantData>,
|
||||
}
|
||||
|
||||
impl EnumData {
|
||||
@ -85,10 +85,6 @@ pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) ->
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct EnumVariantId(RawId);
|
||||
impl_arena_id!(EnumVariantId);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct EnumVariantData {
|
||||
pub(crate) name: Option<Name>,
|
||||
|
@ -8,14 +8,14 @@
|
||||
use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
CrateModuleId, ModuleId,
|
||||
CrateModuleId, LocalEnumVariantId, ModuleId,
|
||||
};
|
||||
use hir_expand::name::{self, AsName};
|
||||
use ra_db::{CrateId, Edition};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
adt::{EnumVariantId, StructFieldId, VariantDef},
|
||||
adt::{StructFieldId, VariantDef},
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
diagnostics::DiagnosticSink,
|
||||
expr::{validation::ExprValidator, Body, BodySourceMap},
|
||||
@ -410,7 +410,7 @@ pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct EnumVariant {
|
||||
pub(crate) parent: Enum,
|
||||
pub(crate) id: EnumVariantId,
|
||||
pub(crate) id: LocalEnumVariantId,
|
||||
}
|
||||
|
||||
impl EnumVariant {
|
||||
|
@ -23,7 +23,7 @@
|
||||
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<T> {
|
||||
@ -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 @@ fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> {
|
||||
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
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user