From a9ddaba905348897606948658798f9f46854acf7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Mar 2019 17:21:32 +0100 Subject: Refactor FnSig a bit --- crates/ra_hir/src/ty/infer.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 268d2c110..2eb73726e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -724,11 +724,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::Call { callee, args } => { let callee_ty = self.infer_expr(*callee, &Expectation::none()); let (param_tys, ret_ty) = match &callee_ty { - Ty::FnPtr(sig) => (sig.input.clone(), sig.output.clone()), + Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), Ty::FnDef { substs, sig, .. } => { - let ret_ty = sig.output.clone().subst(&substs); + let ret_ty = sig.ret().clone().subst(&substs); let param_tys = - sig.input.iter().map(|ty| ty.clone().subst(&substs)).collect(); + sig.params().iter().map(|ty| ty.clone().subst(&substs)).collect(); (param_tys, ret_ty) } _ => { @@ -762,19 +762,20 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let method_ty = self.insert_type_vars(method_ty); let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { Ty::FnPtr(sig) => { - if !sig.input.is_empty() { - (sig.input[0].clone(), sig.input[1..].to_vec(), sig.output.clone()) + if !sig.params().is_empty() { + (sig.params()[0].clone(), sig.params()[1..].to_vec(), sig.ret().clone()) } else { - (Ty::Unknown, Vec::new(), sig.output.clone()) + (Ty::Unknown, Vec::new(), sig.ret().clone()) } } Ty::FnDef { substs, sig, .. } => { - let ret_ty = sig.output.clone().subst(&substs); + let ret_ty = sig.ret().clone().subst(&substs); - if !sig.input.is_empty() { - let mut arg_iter = sig.input.iter().map(|ty| ty.clone().subst(&substs)); - let receiver_ty = arg_iter.next().unwrap(); - (receiver_ty, arg_iter.collect(), ret_ty) + if !sig.params().is_empty() { + let mut params_iter = + sig.params().iter().map(|ty| ty.clone().subst(&substs)); + let receiver_ty = params_iter.next().unwrap(); + (receiver_ty, params_iter.collect(), ret_ty) } else { (Ty::Unknown, Vec::new(), ret_ty) } -- cgit v1.2.3 From 7faae12311895b20b4dec47825708d15f3aaf034 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Mar 2019 17:29:55 +0100 Subject: Remove FnSig from FnDef type It doesn't need to be in there since it's just information from the def. Another step towards aligning Ty with Chalk's representation. --- crates/ra_hir/src/ty/infer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 2eb73726e..c9a5bc7a1 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -725,7 +725,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let callee_ty = self.infer_expr(*callee, &Expectation::none()); let (param_tys, ret_ty) = match &callee_ty { Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), - Ty::FnDef { substs, sig, .. } => { + Ty::FnDef { substs, def, .. } => { + let sig = self.db.callable_item_signature(*def); let ret_ty = sig.ret().clone().subst(&substs); let param_tys = sig.params().iter().map(|ty| ty.clone().subst(&substs)).collect(); @@ -768,7 +769,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (Ty::Unknown, Vec::new(), sig.ret().clone()) } } - Ty::FnDef { substs, sig, .. } => { + Ty::FnDef { substs, def, .. } => { + let sig = self.db.callable_item_signature(*def); let ret_ty = sig.ret().clone().subst(&substs); if !sig.params().is_empty() { -- cgit v1.2.3