From 1ee779d1f74f48d9f3098001c63108b794dbc0b5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 21 Mar 2019 22:39:31 +0100 Subject: Assert in apply_substs that the number of parameters doesn't change ... and fix a small bug revealed by that. --- crates/ra_hir/src/ty.rs | 7 ++++++- crates/ra_hir/src/ty/infer.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 5cd766b85..7d25ade47 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -148,6 +148,10 @@ impl Substs { self.0.iter() } + pub fn len(&self) -> usize { + self.0.len() + } + pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { // Without an Arc::make_mut_slice, we can't avoid the clone here: let mut v: Vec<_> = self.0.iter().cloned().collect(); @@ -286,7 +290,8 @@ impl Ty { /// `Option` afterwards.) pub fn apply_substs(self, substs: Substs) -> Ty { match self { - Ty::Apply(ApplicationTy { ctor, .. }) => { + Ty::Apply(ApplicationTy { ctor, parameters: previous_substs }) => { + assert_eq!(previous_substs.len(), substs.len()); Ty::Apply(ApplicationTy { ctor, parameters: substs }) } _ => self, diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index be74b9fa6..bf42befbb 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -817,7 +817,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Some(func.generic_params(self.db)), ) } - None => (Ty::Unknown, receiver_ty, None), + None => (receiver_ty, Ty::Unknown, None), }; let substs = self.substs_for_method_call(def_generics, generic_args); let method_ty = method_ty.apply_substs(substs); -- cgit v1.2.3