aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 735cdecb9..69af8fb92 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}; 41use super::{Ty, TypableDef, Substs, primitive, op, FnSig};
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> {
@@ -257,10 +257,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
257 self.unify_inner(t1, t2, depth + 1) 257 self.unify_inner(t1, t2, depth + 1)
258 } 258 }
259 (Ty::Ref(t1, m1), Ty::Ref(t2, m2)) if m1 == m2 => self.unify_inner(t1, t2, depth + 1), 259 (Ty::Ref(t1, m1), Ty::Ref(t2, m2)) if m1 == m2 => self.unify_inner(t1, t2, depth + 1),
260 (Ty::FnPtr(sig1), Ty::FnPtr(sig2)) if sig1 == sig2 => true, 260 (Ty::FnPtr(sig1), Ty::FnPtr(sig2)) => self.unify_substs(sig1, sig2, depth + 1),
261 (Ty::Tuple(ts1), Ty::Tuple(ts2)) if ts1.len() == ts2.len() => { 261 (Ty::Tuple(ts1), Ty::Tuple(ts2)) => self.unify_substs(ts1, ts2, depth + 1),
262 ts1.iter().zip(ts2.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth + 1))
263 }
264 (Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2))) 262 (Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2)))
265 | (Ty::Infer(InferTy::IntVar(tv1)), Ty::Infer(InferTy::IntVar(tv2))) 263 | (Ty::Infer(InferTy::IntVar(tv1)), Ty::Infer(InferTy::IntVar(tv2)))
266 | (Ty::Infer(InferTy::FloatVar(tv1)), Ty::Infer(InferTy::FloatVar(tv2))) => { 264 | (Ty::Infer(InferTy::FloatVar(tv1)), Ty::Infer(InferTy::FloatVar(tv2))) => {
@@ -632,7 +630,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
632 let ty = match &body[pat] { 630 let ty = match &body[pat] {
633 Pat::Tuple(ref args) => { 631 Pat::Tuple(ref args) => {
634 let expectations = match *expected { 632 let expectations = match *expected {
635 Ty::Tuple(ref tuple_args) => &**tuple_args, 633 Ty::Tuple(ref tuple_args) => &*tuple_args.0,
636 _ => &[], 634 _ => &[],
637 }; 635 };
638 let expectations_iter = expectations.iter().chain(repeat(&Ty::Unknown)); 636 let expectations_iter = expectations.iter().chain(repeat(&Ty::Unknown));
@@ -644,7 +642,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
644 .collect::<Vec<_>>() 642 .collect::<Vec<_>>()
645 .into(); 643 .into();
646 644
647 Ty::Tuple(inner_tys) 645 Ty::Tuple(Substs(inner_tys))
648 } 646 }
649 Pat::Ref { pat, mutability } => { 647 Pat::Ref { pat, mutability } => {
650 let expectation = match *expected { 648 let expectation = match *expected {
@@ -789,7 +787,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
789 Expr::Call { callee, args } => { 787 Expr::Call { callee, args } => {
790 let callee_ty = self.infer_expr(*callee, &Expectation::none()); 788 let callee_ty = self.infer_expr(*callee, &Expectation::none());
791 let (param_tys, ret_ty) = match &callee_ty { 789 let (param_tys, ret_ty) = match &callee_ty {
792 Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), 790 Ty::FnPtr(sig) => {
791 let sig = FnSig::from_fn_ptr_substs(sig);
792 (sig.params().to_vec(), sig.ret().clone())
793 }
793 Ty::FnDef { substs, def, .. } => { 794 Ty::FnDef { substs, def, .. } => {
794 let sig = self.db.callable_item_signature(*def); 795 let sig = self.db.callable_item_signature(*def);
795 let ret_ty = sig.ret().clone().subst(&substs); 796 let ret_ty = sig.ret().clone().subst(&substs);
@@ -828,6 +829,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
828 let method_ty = self.insert_type_vars(method_ty); 829 let method_ty = self.insert_type_vars(method_ty);
829 let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { 830 let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
830 Ty::FnPtr(sig) => { 831 Ty::FnPtr(sig) => {
832 let sig = FnSig::from_fn_ptr_substs(sig);
831 if !sig.params().is_empty() { 833 if !sig.params().is_empty() {
832 (sig.params()[0].clone(), sig.params()[1..].to_vec(), sig.ret().clone()) 834 (sig.params()[0].clone(), sig.params()[1..].to_vec(), sig.ret().clone())
833 } else { 835 } else {
@@ -923,7 +925,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
923 .find_map(|derefed_ty| match derefed_ty { 925 .find_map(|derefed_ty| match derefed_ty {
924 Ty::Tuple(fields) => { 926 Ty::Tuple(fields) => {
925 let i = name.to_string().parse::<usize>().ok(); 927 let i = name.to_string().parse::<usize>().ok();
926 i.and_then(|i| fields.get(i).cloned()) 928 i.and_then(|i| fields.0.get(i).cloned())
927 } 929 }
928 Ty::Adt { def_id: AdtDef::Struct(s), ref substs, .. } => { 930 Ty::Adt { def_id: AdtDef::Struct(s), ref substs, .. } => {
929 s.field(self.db, name).map(|field| { 931 s.field(self.db, name).map(|field| {
@@ -1016,7 +1018,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1016 ty_vec.push(self.infer_expr(*arg, &Expectation::none())); 1018 ty_vec.push(self.infer_expr(*arg, &Expectation::none()));
1017 } 1019 }
1018 1020
1019 Ty::Tuple(Arc::from(ty_vec)) 1021 Ty::Tuple(Substs(ty_vec.into()))
1020 } 1022 }
1021 Expr::Array { exprs } => { 1023 Expr::Array { exprs } => {
1022 let elem_ty = match &expected.ty { 1024 let elem_ty = match &expected.ty {