aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-27 13:39:58 +0000
committerAleksey Kladov <[email protected]>2019-11-27 13:39:58 +0000
commit12501fcdd02fec9d43dfd810d65e927ddebb1b56 (patch)
tree55f1a6eddc328b20e3a4f71036d59a9573bfaa9c /crates
parentd6e8f27488f8bf4ae7024b9b7a9c4797c2b52b12 (diff)
Remove TypableDef
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/from_id.rs60
-rw-r--r--crates/ra_hir/src/ty.rs2
-rw-r--r--crates/ra_hir/src/ty/lower.rs39
-rw-r--r--crates/ra_hir/src/ty/op.rs4
4 files changed, 7 insertions, 98 deletions
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 @@
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::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, 12 Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField,
13 GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef, 13 VariantDef,
14}; 14};
15 15
16impl From<ra_db::CrateId> for Crate { 16impl From<ra_db::CrateId> for Crate {
@@ -137,58 +137,6 @@ impl From<GenericDef> for GenericDefId {
137 } 137 }
138} 138}
139 139
140impl From<AdtId> for TypableDef {
141 fn from(id: AdtId) -> Self {
142 Adt::from(id).into()
143 }
144}
145
146impl From<StructId> for TypableDef {
147 fn from(id: StructId) -> Self {
148 AdtId::StructId(id).into()
149 }
150}
151
152impl From<UnionId> for TypableDef {
153 fn from(id: UnionId) -> Self {
154 AdtId::UnionId(id).into()
155 }
156}
157
158impl From<EnumId> for TypableDef {
159 fn from(id: EnumId) -> Self {
160 AdtId::EnumId(id).into()
161 }
162}
163
164impl From<EnumVariantId> for TypableDef {
165 fn from(id: EnumVariantId) -> Self {
166 EnumVariant::from(id).into()
167 }
168}
169
170impl From<TypeAliasId> for TypableDef {
171 fn from(id: TypeAliasId) -> Self {
172 TypeAlias::from(id).into()
173 }
174}
175
176impl From<FunctionId> for TypableDef {
177 fn from(id: FunctionId) -> Self {
178 Function::from(id).into()
179 }
180}
181impl From<ConstId> for TypableDef {
182 fn from(id: ConstId) -> Self {
183 Const::from(id).into()
184 }
185}
186impl From<StaticId> for TypableDef {
187 fn from(id: StaticId) -> Self {
188 Static::from(id).into()
189 }
190}
191
192impl From<Adt> for GenericDefId { 140impl From<Adt> for GenericDefId {
193 fn from(id: Adt) -> Self { 141 fn from(id: Adt) -> Self {
194 match id { 142 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;
38pub(crate) use lower::{ 38pub(crate) use lower::{
39 callable_item_sig, field_types_query, generic_defaults_query, 39 callable_item_sig, field_types_query, generic_defaults_query,
40 generic_predicates_for_param_query, generic_predicates_query, ty_query, value_ty_query, 40 generic_predicates_for_param_query, generic_predicates_query, ty_query, value_ty_query,
41 TyDefId, TypableDef, ValueTyDefId, 41 TyDefId, ValueTyDefId,
42}; 42};
43pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 43pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
44 44
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::{
31 utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data}, 31 utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data},
32 }, 32 },
33 util::make_mut_slice, 33 util::make_mut_slice,
34 Adt, Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Static, Struct, Trait, 34 ImplBlock, Trait,
35 TypeAlias, Union,
36}; 35};
37 36
38impl Ty { 37impl Ty {
@@ -694,42 +693,6 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Ty {
694} 693}
695 694
696#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 695#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
697pub enum TypableDef {
698 Function(Function),
699 Adt(Adt),
700 EnumVariant(EnumVariant),
701 TypeAlias(TypeAlias),
702 Const(Const),
703 Static(Static),
704 BuiltinType(BuiltinType),
705}
706impl_froms!(
707 TypableDef: Function,
708 Adt(Struct, Enum, Union),
709 EnumVariant,
710 TypeAlias,
711 Const,
712 Static,
713 BuiltinType
714);
715
716impl From<ModuleDef> for Option<TypableDef> {
717 fn from(def: ModuleDef) -> Option<TypableDef> {
718 let res = match def {
719 ModuleDef::Function(f) => f.into(),
720 ModuleDef::Adt(adt) => adt.into(),
721 ModuleDef::EnumVariant(v) => v.into(),
722 ModuleDef::TypeAlias(t) => t.into(),
723 ModuleDef::Const(v) => v.into(),
724 ModuleDef::Static(v) => v.into(),
725 ModuleDef::BuiltinType(t) => t.into(),
726 ModuleDef::Module(_) | ModuleDef::Trait(_) => return None,
727 };
728 Some(res)
729 }
730}
731
732#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
733pub enum CallableDef { 696pub enum CallableDef {
734 FunctionId(FunctionId), 697 FunctionId(FunctionId),
735 StructId(StructId), 698 StructId(StructId),
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 @@
2use hir_def::expr::{BinaryOp, CmpOp}; 2use hir_def::expr::{BinaryOp, CmpOp};
3 3
4use super::{InferTy, Ty, TypeCtor}; 4use super::{InferTy, Ty, TypeCtor};
5use crate::{ 5use crate::ty::ApplicationTy;
6 ty::ApplicationTy,
7};
8 6
9pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { 7pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
10 match op { 8 match op {