diff options
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 19a1fa793..d6de844a8 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -709,8 +709,9 @@ pub(crate) fn inherent_impl_substs( | |||
709 | ) -> Option<Substitution> { | 709 | ) -> Option<Substitution> { |
710 | // we create a var for each type parameter of the impl; we need to keep in | 710 | // we create a var for each type parameter of the impl; we need to keep in |
711 | // mind here that `self_ty` might have vars of its own | 711 | // mind here that `self_ty` might have vars of its own |
712 | let self_ty_vars = self_ty.binders.len(&Interner); | ||
712 | let vars = TyBuilder::subst_for_def(db, impl_id) | 713 | let vars = TyBuilder::subst_for_def(db, impl_id) |
713 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner)) | 714 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty_vars) |
714 | .build(); | 715 | .build(); |
715 | let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&Interner, &vars); | 716 | let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&Interner, &vars); |
716 | let mut kinds = self_ty.binders.interned().to_vec(); | 717 | let mut kinds = self_ty.binders.interned().to_vec(); |
@@ -725,14 +726,15 @@ pub(crate) fn inherent_impl_substs( | |||
725 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), | 726 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), |
726 | value: (self_ty_with_vars, self_ty.value.clone()), | 727 | value: (self_ty_with_vars, self_ty.value.clone()), |
727 | }; | 728 | }; |
728 | let substs = super::infer::unify(&tys); | 729 | let substs = super::infer::unify(&tys)?; |
729 | // We only want the substs for the vars we added, not the ones from self_ty. | 730 | // We only want the substs for the vars we added, not the ones from self_ty. |
730 | // Also, if any of the vars we added are still in there, we replace them by | 731 | // Also, if any of the vars we added are still in there, we replace them by |
731 | // Unknown. I think this can only really happen if self_ty contained | 732 | // Unknown. I think this can only really happen if self_ty contained |
732 | // Unknown, and in that case we want the result to contain Unknown in those | 733 | // Unknown, and in that case we want the result to contain Unknown in those |
733 | // places again. | 734 | // places again. |
734 | substs | 735 | let suffix = |
735 | .map(|s| fallback_bound_vars(s.suffix(vars.len(&Interner)), self_ty.binders.len(&Interner))) | 736 | Substitution::from_iter(&Interner, substs.iter(&Interner).cloned().skip(self_ty_vars)); |
737 | Some(fallback_bound_vars(suffix, self_ty_vars)) | ||
736 | } | 738 | } |
737 | 739 | ||
738 | /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past | 740 | /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past |