From 12501fcdd02fec9d43dfd810d65e927ddebb1b56 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 16:39:58 +0300 Subject: Remove TypableDef --- crates/ra_hir/src/from_id.rs | 60 +++---------------------------------------- crates/ra_hir/src/ty.rs | 2 +- crates/ra_hir/src/ty/lower.rs | 39 +--------------------------- crates/ra_hir/src/ty/op.rs | 4 +-- 4 files changed, 7 insertions(+), 98 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index 38daa5e59..e96a18d12 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs @@ -4,13 +4,13 @@ //! are splitting the hir. use hir_def::{ - AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, - GenericDefId, ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId, + AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, ModuleDefId, + StructFieldId, VariantId, }; use crate::{ - ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, - GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef, + Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField, + VariantDef, }; impl From for Crate { @@ -137,58 +137,6 @@ impl From for GenericDefId { } } -impl From for TypableDef { - fn from(id: AdtId) -> Self { - Adt::from(id).into() - } -} - -impl From for TypableDef { - fn from(id: StructId) -> Self { - AdtId::StructId(id).into() - } -} - -impl From for TypableDef { - fn from(id: UnionId) -> Self { - AdtId::UnionId(id).into() - } -} - -impl From for TypableDef { - fn from(id: EnumId) -> Self { - AdtId::EnumId(id).into() - } -} - -impl From for TypableDef { - fn from(id: EnumVariantId) -> Self { - EnumVariant::from(id).into() - } -} - -impl From for TypableDef { - fn from(id: TypeAliasId) -> Self { - TypeAlias::from(id).into() - } -} - -impl From for TypableDef { - fn from(id: FunctionId) -> Self { - Function::from(id).into() - } -} -impl From for TypableDef { - fn from(id: ConstId) -> Self { - Const::from(id).into() - } -} -impl From for TypableDef { - fn from(id: StaticId) -> Self { - Static::from(id).into() - } -} - impl From for GenericDefId { fn from(id: Adt) -> Self { match id { diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index a26776b26..e4ba8afa6 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -38,7 +38,7 @@ pub use lower::CallableDef; pub(crate) use lower::{ callable_item_sig, field_types_query, generic_defaults_query, generic_predicates_for_param_query, generic_predicates_query, ty_query, value_ty_query, - TyDefId, TypableDef, ValueTyDefId, + TyDefId, ValueTyDefId, }; pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index d776b6cd0..5dce2f342 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -31,8 +31,7 @@ use crate::{ utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data}, }, util::make_mut_slice, - Adt, Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Static, Struct, Trait, - TypeAlias, Union, + ImplBlock, Trait, }; impl Ty { @@ -693,42 +692,6 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Ty { inner.subst(&substs) } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum TypableDef { - Function(Function), - Adt(Adt), - EnumVariant(EnumVariant), - TypeAlias(TypeAlias), - Const(Const), - Static(Static), - BuiltinType(BuiltinType), -} -impl_froms!( - TypableDef: Function, - Adt(Struct, Enum, Union), - EnumVariant, - TypeAlias, - Const, - Static, - BuiltinType -); - -impl From for Option { - fn from(def: ModuleDef) -> Option { - let res = match def { - ModuleDef::Function(f) => f.into(), - ModuleDef::Adt(adt) => adt.into(), - ModuleDef::EnumVariant(v) => v.into(), - ModuleDef::TypeAlias(t) => t.into(), - ModuleDef::Const(v) => v.into(), - ModuleDef::Static(v) => v.into(), - ModuleDef::BuiltinType(t) => t.into(), - ModuleDef::Module(_) | ModuleDef::Trait(_) => return None, - }; - Some(res) - } -} - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum CallableDef { FunctionId(FunctionId), diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs index 80d4111a0..cc6e244f4 100644 --- a/crates/ra_hir/src/ty/op.rs +++ b/crates/ra_hir/src/ty/op.rs @@ -2,9 +2,7 @@ use hir_def::expr::{BinaryOp, CmpOp}; use super::{InferTy, Ty, TypeCtor}; -use crate::{ - ty::ApplicationTy, -}; +use crate::ty::ApplicationTy; pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { match op { -- cgit v1.2.3