aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-03-21 21:20:03 +0000
committerFlorian Diebold <[email protected]>2019-03-21 21:20:03 +0000
commitf10f5a81b326d161d9ed1fba263de972b89de2bf (patch)
treef54d83e74161c51cf8525213bf221b83d276de85 /crates/ra_hir/src/ty
parent8a5fbf471305894094726834f7701747fce9c961 (diff)
TypeName => TypeCtor
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs78
-rw-r--r--crates/ra_hir/src/ty/lower.rs36
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs6
-rw-r--r--crates/ra_hir/src/ty/op.rs20
4 files changed, 70 insertions, 70 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 0dafd8cbd..e975f9217 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -38,7 +38,7 @@ use crate::{
38 resolve::{Resolver, Resolution}, 38 resolve::{Resolver, Resolution},
39 nameres::Namespace 39 nameres::Namespace
40}; 40};
41use super::{Ty, TypableDef, Substs, primitive, op, FnSig, ApplicationTy, TypeName}; 41use super::{Ty, TypableDef, Substs, primitive, op, FnSig, ApplicationTy, TypeCtor};
42 42
43/// The entry point of type inference. 43/// The entry point of type inference.
44pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> { 44pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> {
@@ -278,11 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
278 match ty { 278 match ty {
279 Ty::Unknown => self.new_type_var(), 279 Ty::Unknown => self.new_type_var(),
280 Ty::Apply(ApplicationTy { 280 Ty::Apply(ApplicationTy {
281 name: TypeName::Int(primitive::UncertainIntTy::Unknown), 281 name: TypeCtor::Int(primitive::UncertainIntTy::Unknown),
282 .. 282 ..
283 }) => self.new_integer_var(), 283 }) => self.new_integer_var(),
284 Ty::Apply(ApplicationTy { 284 Ty::Apply(ApplicationTy {
285 name: TypeName::Float(primitive::UncertainFloatTy::Unknown), 285 name: TypeCtor::Float(primitive::UncertainFloatTy::Unknown),
286 .. 286 ..
287 }) => self.new_float_var(), 287 }) => self.new_float_var(),
288 _ => ty, 288 _ => ty,
@@ -629,7 +629,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
629 .collect::<Vec<_>>() 629 .collect::<Vec<_>>()
630 .into(); 630 .into();
631 631
632 Ty::apply(TypeName::Tuple, Substs(inner_tys)) 632 Ty::apply(TypeCtor::Tuple, Substs(inner_tys))
633 } 633 }
634 Pat::Ref { pat, mutability } => { 634 Pat::Ref { pat, mutability } => {
635 let expectation = match expected.as_reference() { 635 let expectation = match expected.as_reference() {
@@ -642,7 +642,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
642 _ => &Ty::Unknown, 642 _ => &Ty::Unknown,
643 }; 643 };
644 let subty = self.infer_pat(*pat, expectation, default_bm); 644 let subty = self.infer_pat(*pat, expectation, default_bm);
645 Ty::apply_one(TypeName::Ref(*mutability), subty.into()) 645 Ty::apply_one(TypeCtor::Ref(*mutability), subty.into())
646 } 646 }
647 Pat::TupleStruct { path: ref p, args: ref subpats } => { 647 Pat::TupleStruct { path: ref p, args: ref subpats } => {
648 self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) 648 self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm)
@@ -670,7 +670,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
670 670
671 let bound_ty = match mode { 671 let bound_ty = match mode {
672 BindingMode::Ref(mutability) => { 672 BindingMode::Ref(mutability) => {
673 Ty::apply_one(TypeName::Ref(mutability), inner_ty.clone().into()) 673 Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone().into())
674 } 674 }
675 BindingMode::Move => inner_ty.clone(), 675 BindingMode::Move => inner_ty.clone(),
676 }; 676 };
@@ -725,7 +725,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
725 Expr::Missing => Ty::Unknown, 725 Expr::Missing => Ty::Unknown,
726 Expr::If { condition, then_branch, else_branch } => { 726 Expr::If { condition, then_branch, else_branch } => {
727 // if let is desugared to match, so this is always simple if 727 // if let is desugared to match, so this is always simple if
728 self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeName::Bool))); 728 self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeCtor::Bool)));
729 let then_ty = self.infer_expr(*then_branch, expected); 729 let then_ty = self.infer_expr(*then_branch, expected);
730 match else_branch { 730 match else_branch {
731 Some(else_branch) => { 731 Some(else_branch) => {
@@ -742,11 +742,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
742 Expr::Loop { body } => { 742 Expr::Loop { body } => {
743 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 743 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
744 // TODO handle break with value 744 // TODO handle break with value
745 Ty::simple(TypeName::Never) 745 Ty::simple(TypeCtor::Never)
746 } 746 }
747 Expr::While { condition, body } => { 747 Expr::While { condition, body } => {
748 // while let is desugared to a match loop, so this is always simple while 748 // while let is desugared to a match loop, so this is always simple while
749 self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeName::Bool))); 749 self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeCtor::Bool)));
750 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 750 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
751 Ty::unit() 751 Ty::unit()
752 } 752 }
@@ -777,11 +777,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
777 let callee_ty = self.infer_expr(*callee, &Expectation::none()); 777 let callee_ty = self.infer_expr(*callee, &Expectation::none());
778 let (param_tys, ret_ty) = match &callee_ty { 778 let (param_tys, ret_ty) = match &callee_ty {
779 Ty::Apply(a_ty) => match a_ty.name { 779 Ty::Apply(a_ty) => match a_ty.name {
780 TypeName::FnPtr => { 780 TypeCtor::FnPtr => {
781 let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); 781 let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
782 (sig.params().to_vec(), sig.ret().clone()) 782 (sig.params().to_vec(), sig.ret().clone())
783 } 783 }
784 TypeName::FnDef(def) => { 784 TypeCtor::FnDef(def) => {
785 let sig = self.db.callable_item_signature(def); 785 let sig = self.db.callable_item_signature(def);
786 let ret_ty = sig.ret().clone().subst(&a_ty.parameters); 786 let ret_ty = sig.ret().clone().subst(&a_ty.parameters);
787 let param_tys = sig 787 let param_tys = sig
@@ -824,7 +824,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
824 let method_ty = self.insert_type_vars(method_ty); 824 let method_ty = self.insert_type_vars(method_ty);
825 let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { 825 let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
826 Ty::Apply(a_ty) => match a_ty.name { 826 Ty::Apply(a_ty) => match a_ty.name {
827 TypeName::FnPtr => { 827 TypeCtor::FnPtr => {
828 let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); 828 let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
829 if !sig.params().is_empty() { 829 if !sig.params().is_empty() {
830 ( 830 (
@@ -836,7 +836,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
836 (Ty::Unknown, Vec::new(), sig.ret().clone()) 836 (Ty::Unknown, Vec::new(), sig.ret().clone())
837 } 837 }
838 } 838 }
839 TypeName::FnDef(def) => { 839 TypeCtor::FnDef(def) => {
840 let sig = self.db.callable_item_signature(def); 840 let sig = self.db.callable_item_signature(def);
841 let ret_ty = sig.ret().clone().subst(&a_ty.parameters); 841 let ret_ty = sig.ret().clone().subst(&a_ty.parameters);
842 842
@@ -858,7 +858,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
858 // Apply autoref so the below unification works correctly 858 // Apply autoref so the below unification works correctly
859 let actual_receiver_ty = match expected_receiver_ty.as_reference() { 859 let actual_receiver_ty = match expected_receiver_ty.as_reference() {
860 Some((_, mutability)) => { 860 Some((_, mutability)) => {
861 Ty::apply_one(TypeName::Ref(mutability), derefed_receiver_ty) 861 Ty::apply_one(TypeCtor::Ref(mutability), derefed_receiver_ty)
862 } 862 }
863 _ => derefed_receiver_ty, 863 _ => derefed_receiver_ty,
864 }; 864 };
@@ -885,7 +885,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
885 if let Some(guard_expr) = arm.guard { 885 if let Some(guard_expr) = arm.guard {
886 self.infer_expr( 886 self.infer_expr(
887 guard_expr, 887 guard_expr,
888 &Expectation::has_type(Ty::simple(TypeName::Bool)), 888 &Expectation::has_type(Ty::simple(TypeCtor::Bool)),
889 ); 889 );
890 } 890 }
891 self.infer_expr(arm.expr, &expected); 891 self.infer_expr(arm.expr, &expected);
@@ -898,19 +898,19 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
898 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); 898 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr);
899 self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) 899 self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
900 } 900 }
901 Expr::Continue => Ty::simple(TypeName::Never), 901 Expr::Continue => Ty::simple(TypeCtor::Never),
902 Expr::Break { expr } => { 902 Expr::Break { expr } => {
903 if let Some(expr) = expr { 903 if let Some(expr) = expr {
904 // TODO handle break with value 904 // TODO handle break with value
905 self.infer_expr(*expr, &Expectation::none()); 905 self.infer_expr(*expr, &Expectation::none());
906 } 906 }
907 Ty::simple(TypeName::Never) 907 Ty::simple(TypeCtor::Never)
908 } 908 }
909 Expr::Return { expr } => { 909 Expr::Return { expr } => {
910 if let Some(expr) = expr { 910 if let Some(expr) = expr {
911 self.infer_expr(*expr, &Expectation::has_type(self.return_ty.clone())); 911 self.infer_expr(*expr, &Expectation::has_type(self.return_ty.clone()));
912 } 912 }
913 Ty::simple(TypeName::Never) 913 Ty::simple(TypeCtor::Never)
914 } 914 }
915 Expr::StructLit { path, fields, spread } => { 915 Expr::StructLit { path, fields, spread } => {
916 let (ty, def_id) = self.resolve_variant(path.as_ref()); 916 let (ty, def_id) = self.resolve_variant(path.as_ref());
@@ -933,11 +933,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
933 .autoderef(self.db) 933 .autoderef(self.db)
934 .find_map(|derefed_ty| match derefed_ty { 934 .find_map(|derefed_ty| match derefed_ty {
935 Ty::Apply(a_ty) => match a_ty.name { 935 Ty::Apply(a_ty) => match a_ty.name {
936 TypeName::Tuple => { 936 TypeCtor::Tuple => {
937 let i = name.to_string().parse::<usize>().ok(); 937 let i = name.to_string().parse::<usize>().ok();
938 i.and_then(|i| a_ty.parameters.0.get(i).cloned()) 938 i.and_then(|i| a_ty.parameters.0.get(i).cloned())
939 } 939 }
940 TypeName::Adt(AdtDef::Struct(s)) => { 940 TypeCtor::Adt(AdtDef::Struct(s)) => {
941 s.field(self.db, name).map(|field| { 941 s.field(self.db, name).map(|field| {
942 self.write_field_resolution(tgt_expr, field); 942 self.write_field_resolution(tgt_expr, field);
943 field.ty(self.db).subst(&a_ty.parameters) 943 field.ty(self.db).subst(&a_ty.parameters)
@@ -973,7 +973,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
973 }; 973 };
974 // TODO reference coercions etc. 974 // TODO reference coercions etc.
975 let inner_ty = self.infer_expr(*expr, &expectation); 975 let inner_ty = self.infer_expr(*expr, &expectation);
976 Ty::apply_one(TypeName::Ref(*mutability), inner_ty) 976 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty)
977 } 977 }
978 Expr::UnaryOp { expr, op } => { 978 Expr::UnaryOp { expr, op } => {
979 let inner_ty = self.infer_expr(*expr, &Expectation::none()); 979 let inner_ty = self.infer_expr(*expr, &Expectation::none());
@@ -989,9 +989,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
989 UnaryOp::Neg => { 989 UnaryOp::Neg => {
990 match &inner_ty { 990 match &inner_ty {
991 Ty::Apply(a_ty) => match a_ty.name { 991 Ty::Apply(a_ty) => match a_ty.name {
992 TypeName::Int(primitive::UncertainIntTy::Unknown) 992 TypeCtor::Int(primitive::UncertainIntTy::Unknown)
993 | TypeName::Int(primitive::UncertainIntTy::Signed(..)) 993 | TypeCtor::Int(primitive::UncertainIntTy::Signed(..))
994 | TypeName::Float(..) => inner_ty, 994 | TypeCtor::Float(..) => inner_ty,
995 _ => Ty::Unknown, 995 _ => Ty::Unknown,
996 }, 996 },
997 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { 997 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => {
@@ -1004,7 +1004,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1004 UnaryOp::Not => { 1004 UnaryOp::Not => {
1005 match &inner_ty { 1005 match &inner_ty {
1006 Ty::Apply(a_ty) => match a_ty.name { 1006 Ty::Apply(a_ty) => match a_ty.name {
1007 TypeName::Bool | TypeName::Int(_) => inner_ty, 1007 TypeCtor::Bool | TypeCtor::Int(_) => inner_ty,
1008 _ => Ty::Unknown, 1008 _ => Ty::Unknown,
1009 }, 1009 },
1010 Ty::Infer(InferTy::IntVar(..)) => inner_ty, 1010 Ty::Infer(InferTy::IntVar(..)) => inner_ty,
@@ -1018,7 +1018,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1018 Some(op) => { 1018 Some(op) => {
1019 let lhs_expectation = match op { 1019 let lhs_expectation = match op {
1020 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => { 1020 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => {
1021 Expectation::has_type(Ty::simple(TypeName::Bool)) 1021 Expectation::has_type(Ty::simple(TypeCtor::Bool))
1022 } 1022 }
1023 _ => Expectation::none(), 1023 _ => Expectation::none(),
1024 }; 1024 };
@@ -1039,12 +1039,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1039 ty_vec.push(self.infer_expr(*arg, &Expectation::none())); 1039 ty_vec.push(self.infer_expr(*arg, &Expectation::none()));
1040 } 1040 }
1041 1041
1042 Ty::apply(TypeName::Tuple, Substs(ty_vec.into())) 1042 Ty::apply(TypeCtor::Tuple, Substs(ty_vec.into()))
1043 } 1043 }
1044 Expr::Array { exprs } => { 1044 Expr::Array { exprs } => {
1045 let elem_ty = match &expected.ty { 1045 let elem_ty = match &expected.ty {
1046 Ty::Apply(a_ty) => match a_ty.name { 1046 Ty::Apply(a_ty) => match a_ty.name {
1047 TypeName::Slice | TypeName::Array => { 1047 TypeCtor::Slice | TypeCtor::Array => {
1048 Ty::clone(&a_ty.parameters.as_single()) 1048 Ty::clone(&a_ty.parameters.as_single())
1049 } 1049 }
1050 _ => self.new_type_var(), 1050 _ => self.new_type_var(),
@@ -1056,23 +1056,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1056 self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); 1056 self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone()));
1057 } 1057 }
1058 1058
1059 Ty::apply_one(TypeName::Array, elem_ty) 1059 Ty::apply_one(TypeCtor::Array, elem_ty)
1060 } 1060 }
1061 Expr::Literal(lit) => match lit { 1061 Expr::Literal(lit) => match lit {
1062 Literal::Bool(..) => Ty::simple(TypeName::Bool), 1062 Literal::Bool(..) => Ty::simple(TypeCtor::Bool),
1063 Literal::String(..) => { 1063 Literal::String(..) => {
1064 Ty::apply_one(TypeName::Ref(Mutability::Shared), Ty::simple(TypeName::Str)) 1064 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str))
1065 } 1065 }
1066 Literal::ByteString(..) => { 1066 Literal::ByteString(..) => {
1067 let byte_type = Ty::simple(TypeName::Int(primitive::UncertainIntTy::Unsigned( 1067 let byte_type = Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Unsigned(
1068 primitive::UintTy::U8, 1068 primitive::UintTy::U8,
1069 ))); 1069 )));
1070 let slice_type = Ty::apply_one(TypeName::Slice, byte_type); 1070 let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type);
1071 Ty::apply_one(TypeName::Ref(Mutability::Shared), slice_type) 1071 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type)
1072 } 1072 }
1073 Literal::Char(..) => Ty::simple(TypeName::Char), 1073 Literal::Char(..) => Ty::simple(TypeCtor::Char),
1074 Literal::Int(_v, ty) => Ty::simple(TypeName::Int(*ty)), 1074 Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int(*ty)),
1075 Literal::Float(_v, ty) => Ty::simple(TypeName::Float(*ty)), 1075 Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float(*ty)),
1076 }, 1076 },
1077 }; 1077 };
1078 // use a new type variable if we got Ty::Unknown here 1078 // use a new type variable if we got Ty::Unknown here
@@ -1208,9 +1208,9 @@ impl InferTy {
1208 match self { 1208 match self {
1209 InferTy::TypeVar(..) => Ty::Unknown, 1209 InferTy::TypeVar(..) => Ty::Unknown,
1210 InferTy::IntVar(..) => { 1210 InferTy::IntVar(..) => {
1211 Ty::simple(TypeName::Int(primitive::UncertainIntTy::Signed(primitive::IntTy::I32))) 1211 Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Signed(primitive::IntTy::I32)))
1212 } 1212 }
1213 InferTy::FloatVar(..) => Ty::simple(TypeName::Float( 1213 InferTy::FloatVar(..) => Ty::simple(TypeCtor::Float(
1214 primitive::UncertainFloatTy::Known(primitive::FloatTy::F64), 1214 primitive::UncertainFloatTy::Known(primitive::FloatTy::F64),
1215 )), 1215 )),
1216 } 1216 }
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index a346879d8..72b1234bf 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -19,40 +19,40 @@ use crate::{
19 generics::GenericParams, 19 generics::GenericParams,
20 adt::VariantDef, 20 adt::VariantDef,
21}; 21};
22use super::{Ty, primitive, FnSig, Substs, TypeName}; 22use super::{Ty, primitive, FnSig, Substs, TypeCtor};
23 23
24impl Ty { 24impl Ty {
25 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { 25 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
26 match type_ref { 26 match type_ref {
27 TypeRef::Never => Ty::simple(TypeName::Never), 27 TypeRef::Never => Ty::simple(TypeCtor::Never),
28 TypeRef::Tuple(inner) => { 28 TypeRef::Tuple(inner) => {
29 let inner_tys = 29 let inner_tys =
30 inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>(); 30 inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>();
31 Ty::apply(TypeName::Tuple, Substs(inner_tys.into())) 31 Ty::apply(TypeCtor::Tuple, Substs(inner_tys.into()))
32 } 32 }
33 TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path), 33 TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path),
34 TypeRef::RawPtr(inner, mutability) => { 34 TypeRef::RawPtr(inner, mutability) => {
35 let inner_ty = Ty::from_hir(db, resolver, inner); 35 let inner_ty = Ty::from_hir(db, resolver, inner);
36 Ty::apply_one(TypeName::RawPtr(*mutability), inner_ty) 36 Ty::apply_one(TypeCtor::RawPtr(*mutability), inner_ty)
37 } 37 }
38 TypeRef::Array(inner) => { 38 TypeRef::Array(inner) => {
39 let inner_ty = Ty::from_hir(db, resolver, inner); 39 let inner_ty = Ty::from_hir(db, resolver, inner);
40 Ty::apply_one(TypeName::Array, inner_ty) 40 Ty::apply_one(TypeCtor::Array, inner_ty)
41 } 41 }
42 TypeRef::Slice(inner) => { 42 TypeRef::Slice(inner) => {
43 let inner_ty = Ty::from_hir(db, resolver, inner); 43 let inner_ty = Ty::from_hir(db, resolver, inner);
44 Ty::apply_one(TypeName::Slice, inner_ty) 44 Ty::apply_one(TypeCtor::Slice, inner_ty)
45 } 45 }
46 TypeRef::Reference(inner, mutability) => { 46 TypeRef::Reference(inner, mutability) => {
47 let inner_ty = Ty::from_hir(db, resolver, inner); 47 let inner_ty = Ty::from_hir(db, resolver, inner);
48 Ty::apply_one(TypeName::Ref(*mutability), inner_ty) 48 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty)
49 } 49 }
50 TypeRef::Placeholder => Ty::Unknown, 50 TypeRef::Placeholder => Ty::Unknown,
51 TypeRef::Fn(params) => { 51 TypeRef::Fn(params) => {
52 let inner_tys = 52 let inner_tys =
53 params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>(); 53 params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>();
54 let sig = Substs(inner_tys.into()); 54 let sig = Substs(inner_tys.into());
55 Ty::apply(TypeName::FnPtr, sig) 55 Ty::apply(TypeCtor::FnPtr, sig)
56 } 56 }
57 TypeRef::Error => Ty::Unknown, 57 TypeRef::Error => Ty::Unknown,
58 } 58 }
@@ -62,14 +62,14 @@ impl Ty {
62 if let Some(name) = path.as_ident() { 62 if let Some(name) = path.as_ident() {
63 // TODO handle primitive type names in resolver as well? 63 // TODO handle primitive type names in resolver as well?
64 if let Some(int_ty) = primitive::UncertainIntTy::from_type_name(name) { 64 if let Some(int_ty) = primitive::UncertainIntTy::from_type_name(name) {
65 return Ty::simple(TypeName::Int(int_ty)); 65 return Ty::simple(TypeCtor::Int(int_ty));
66 } else if let Some(float_ty) = primitive::UncertainFloatTy::from_type_name(name) { 66 } else if let Some(float_ty) = primitive::UncertainFloatTy::from_type_name(name) {
67 return Ty::simple(TypeName::Float(float_ty)); 67 return Ty::simple(TypeCtor::Float(float_ty));
68 } else if let Some(known) = name.as_known_name() { 68 } else if let Some(known) = name.as_known_name() {
69 match known { 69 match known {
70 KnownName::Bool => return Ty::simple(TypeName::Bool), 70 KnownName::Bool => return Ty::simple(TypeCtor::Bool),
71 KnownName::Char => return Ty::simple(TypeName::Char), 71 KnownName::Char => return Ty::simple(TypeCtor::Char),
72 KnownName::Str => return Ty::simple(TypeName::Str), 72 KnownName::Str => return Ty::simple(TypeCtor::Str),
73 _ => {} 73 _ => {}
74 } 74 }
75 } 75 }
@@ -245,7 +245,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig {
245fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { 245fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty {
246 let generics = def.generic_params(db); 246 let generics = def.generic_params(db);
247 let substs = make_substs(&generics); 247 let substs = make_substs(&generics);
248 Ty::apply(TypeName::FnDef(def.into()), substs) 248 Ty::apply(TypeCtor::FnDef(def.into()), substs)
249} 249}
250 250
251/// Build the declared type of a const. 251/// Build the declared type of a const.
@@ -287,7 +287,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
287 } 287 }
288 let generics = def.generic_params(db); 288 let generics = def.generic_params(db);
289 let substs = make_substs(&generics); 289 let substs = make_substs(&generics);
290 Ty::apply(TypeName::FnDef(def.into()), substs) 290 Ty::apply(TypeCtor::FnDef(def.into()), substs)
291} 291}
292 292
293fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { 293fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig {
@@ -315,7 +315,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) ->
315 } 315 }
316 let generics = def.parent_enum(db).generic_params(db); 316 let generics = def.parent_enum(db).generic_params(db);
317 let substs = make_substs(&generics); 317 let substs = make_substs(&generics);
318 Ty::apply(TypeName::FnDef(def.into()), substs) 318 Ty::apply(TypeCtor::FnDef(def.into()), substs)
319} 319}
320 320
321fn make_substs(generics: &GenericParams) -> Substs { 321fn make_substs(generics: &GenericParams) -> Substs {
@@ -331,12 +331,12 @@ fn make_substs(generics: &GenericParams) -> Substs {
331 331
332fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty { 332fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
333 let generics = s.generic_params(db); 333 let generics = s.generic_params(db);
334 Ty::apply(TypeName::Adt(s.into()), make_substs(&generics)) 334 Ty::apply(TypeCtor::Adt(s.into()), make_substs(&generics))
335} 335}
336 336
337fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty { 337fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty {
338 let generics = s.generic_params(db); 338 let generics = s.generic_params(db);
339 Ty::apply(TypeName::Adt(s.into()), make_substs(&generics)) 339 Ty::apply(TypeCtor::Adt(s.into()), make_substs(&generics))
340} 340}
341 341
342fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { 342fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 06bfe85cd..9422bad84 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -10,7 +10,7 @@ use crate::{
10 HirDatabase, Module, Crate, Name, Function, Trait, 10 HirDatabase, Module, Crate, Name, Function, Trait,
11 ids::TraitId, 11 ids::TraitId,
12 impl_block::{ImplId, ImplBlock, ImplItem}, 12 impl_block::{ImplId, ImplBlock, ImplItem},
13 ty::{Ty, TypeName}, 13 ty::{Ty, TypeCtor},
14 nameres::CrateModuleId, 14 nameres::CrateModuleId,
15 15
16}; 16};
@@ -18,7 +18,7 @@ use crate::{
18/// This is used as a key for indexing impls. 18/// This is used as a key for indexing impls.
19#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 19#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
20pub enum TyFingerprint { 20pub enum TyFingerprint {
21 Apply(TypeName), 21 Apply(TypeCtor),
22} 22}
23 23
24impl TyFingerprint { 24impl TyFingerprint {
@@ -112,7 +112,7 @@ impl CrateImplBlocks {
112fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> { 112fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
113 match ty { 113 match ty {
114 Ty::Apply(a_ty) => match a_ty.name { 114 Ty::Apply(a_ty) => match a_ty.name {
115 TypeName::Adt(def_id) => def_id.krate(db), 115 TypeCtor::Adt(def_id) => def_id.krate(db),
116 _ => None, 116 _ => None,
117 }, 117 },
118 _ => None, 118 _ => None,
diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs
index f581004d2..1d230140b 100644
--- a/crates/ra_hir/src/ty/op.rs
+++ b/crates/ra_hir/src/ty/op.rs
@@ -1,5 +1,5 @@
1use crate::{ ty::ApplicationTy, expr::BinaryOp}; 1use crate::{ ty::ApplicationTy, expr::BinaryOp};
2use super::{Ty, TypeName, InferTy}; 2use super::{Ty, TypeCtor, InferTy};
3 3
4pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { 4pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
5 match op { 5 match op {
@@ -10,7 +10,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
10 | BinaryOp::LesserEqualTest 10 | BinaryOp::LesserEqualTest
11 | BinaryOp::GreaterEqualTest 11 | BinaryOp::GreaterEqualTest
12 | BinaryOp::LesserTest 12 | BinaryOp::LesserTest
13 | BinaryOp::GreaterTest => Ty::simple(TypeName::Bool), 13 | BinaryOp::GreaterTest => Ty::simple(TypeCtor::Bool),
14 BinaryOp::Assignment 14 BinaryOp::Assignment
15 | BinaryOp::AddAssign 15 | BinaryOp::AddAssign
16 | BinaryOp::SubAssign 16 | BinaryOp::SubAssign
@@ -33,7 +33,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
33 | BinaryOp::BitwiseOr 33 | BinaryOp::BitwiseOr
34 | BinaryOp::BitwiseXor => match rhs_ty { 34 | BinaryOp::BitwiseXor => match rhs_ty {
35 Ty::Apply(ApplicationTy { name, .. }) => match name { 35 Ty::Apply(ApplicationTy { name, .. }) => match name {
36 TypeName::Int(..) | TypeName::Float(..) => rhs_ty, 36 TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
37 _ => Ty::Unknown, 37 _ => Ty::Unknown,
38 }, 38 },
39 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, 39 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
@@ -45,14 +45,14 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
45 45
46pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { 46pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
47 match op { 47 match op {
48 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeName::Bool), 48 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool),
49 BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { 49 BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty {
50 Ty::Apply(ApplicationTy { name, .. }) => match name { 50 Ty::Apply(ApplicationTy { name, .. }) => match name {
51 TypeName::Int(..) 51 TypeCtor::Int(..)
52 | TypeName::Float(..) 52 | TypeCtor::Float(..)
53 | TypeName::Str 53 | TypeCtor::Str
54 | TypeName::Char 54 | TypeCtor::Char
55 | TypeName::Bool => lhs_ty, 55 | TypeCtor::Bool => lhs_ty,
56 _ => Ty::Unknown, 56 _ => Ty::Unknown,
57 }, 57 },
58 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, 58 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
@@ -83,7 +83,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
83 | BinaryOp::BitwiseOr 83 | BinaryOp::BitwiseOr
84 | BinaryOp::BitwiseXor => match lhs_ty { 84 | BinaryOp::BitwiseXor => match lhs_ty {
85 Ty::Apply(ApplicationTy { name, .. }) => match name { 85 Ty::Apply(ApplicationTy { name, .. }) => match name {
86 TypeName::Int(..) | TypeName::Float(..) => lhs_ty, 86 TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
87 _ => Ty::Unknown, 87 _ => Ty::Unknown,
88 }, 88 },
89 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, 89 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,