From 336a3c6121edf54a19728dbbd880f62bc835d7c8 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 1 Mar 2020 14:31:35 +0100 Subject: Fix #3373 Basically, we need to allow variables in the caller self type to unify with the impl's declared self type. That requires some more contortions in the variable handling. I'm looking forward to (hopefully) handling this in a cleaner way when we switch to Chalk's types and unification code. --- crates/ra_hir_ty/src/method_resolution.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/method_resolution.rs') diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 74b908c2e..b7e8855fb 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -508,10 +508,17 @@ pub(crate) fn inherent_impl_substs( impl_id: ImplId, self_ty: &Canonical, ) -> Option { - let vars = Substs::build_for_def(db, impl_id).fill_with_bound_vars(0).build(); + // we create a var for each type parameter of the impl; we need to keep in + // mind here that `self_ty` might have vars of its own + let vars = + Substs::build_for_def(db, impl_id).fill_with_bound_vars(self_ty.num_vars as u32).build(); let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); - let self_ty_with_vars = Canonical { num_vars: vars.len(), value: self_ty_with_vars }; - super::infer::unify(&self_ty_with_vars, self_ty) + let self_ty_with_vars = + Canonical { num_vars: vars.len() + self_ty.num_vars, value: self_ty_with_vars }; + let substs = super::infer::unify(&self_ty_with_vars, self_ty); + // we only want the substs for the vars we added, not the ones from self_ty + let result = substs.map(|s| s.suffix(vars.len())); + result } fn transform_receiver_ty( -- cgit v1.2.3