From 2a83645e1bb01578c4bbe5f71418d354108dfd77 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 21:49:27 +0200 Subject: Get rid of Substitution::suffix --- crates/hir_ty/src/lib.rs | 6 ------ crates/hir_ty/src/method_resolution.rs | 10 ++++++---- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 2c70c4277..abdcf8829 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -79,12 +79,6 @@ impl Substitution { pub fn prefix(&self, n: usize) -> Substitution { Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into()) } - - pub fn suffix(&self, n: usize) -> Substitution { - Substitution::intern( - self.interned()[self.len(&Interner) - std::cmp::min(self.len(&Interner), n)..].into(), - ) - } } /// Return an index of a parameter in the generic type parameter list by it's id. 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( ) -> Option { // 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 self_ty_vars = self_ty.binders.len(&Interner); let vars = TyBuilder::subst_for_def(db, impl_id) - .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner)) + .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty_vars) .build(); let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&Interner, &vars); let mut kinds = self_ty.binders.interned().to_vec(); @@ -725,14 +726,15 @@ pub(crate) fn inherent_impl_substs( binders: CanonicalVarKinds::from_iter(&Interner, kinds), value: (self_ty_with_vars, self_ty.value.clone()), }; - let substs = super::infer::unify(&tys); + let substs = super::infer::unify(&tys)?; // We only want the substs for the vars we added, not the ones from self_ty. // Also, if any of the vars we added are still in there, we replace them by // Unknown. I think this can only really happen if self_ty contained // Unknown, and in that case we want the result to contain Unknown in those // places again. - substs - .map(|s| fallback_bound_vars(s.suffix(vars.len(&Interner)), self_ty.binders.len(&Interner))) + let suffix = + Substitution::from_iter(&Interner, substs.iter(&Interner).cloned().skip(self_ty_vars)); + Some(fallback_bound_vars(suffix, self_ty_vars)) } /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past -- cgit v1.2.3