Skip to content

Commit 2a83645

Browse files
committed
Get rid of Substitution::suffix
1 parent b443e53 commit 2a83645

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

crates/hir_ty/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ impl Substitution {
7979
pub fn prefix(&self, n: usize) -> Substitution {
8080
Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
8181
}
82-
83-
pub fn suffix(&self, n: usize) -> Substitution {
84-
Substitution::intern(
85-
self.interned()[self.len(&Interner) - std::cmp::min(self.len(&Interner), n)..].into(),
86-
)
87-
}
8882
}
8983

9084
/// Return an index of a parameter in the generic type parameter list by it's id.

crates/hir_ty/src/method_resolution.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,9 @@ pub(crate) fn inherent_impl_substs(
709709
) -> Option<Substitution> {
710710
// we create a var for each type parameter of the impl; we need to keep in
711711
// mind here that `self_ty` might have vars of its own
712+
let self_ty_vars = self_ty.binders.len(&Interner);
712713
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)
714715
.build();
715716
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&Interner, &vars);
716717
let mut kinds = self_ty.binders.interned().to_vec();
@@ -725,14 +726,15 @@ pub(crate) fn inherent_impl_substs(
725726
binders: CanonicalVarKinds::from_iter(&Interner, kinds),
726727
value: (self_ty_with_vars, self_ty.value.clone()),
727728
};
728-
let substs = super::infer::unify(&tys);
729+
let substs = super::infer::unify(&tys)?;
729730
// We only want the substs for the vars we added, not the ones from self_ty.
730731
// Also, if any of the vars we added are still in there, we replace them by
731732
// Unknown. I think this can only really happen if self_ty contained
732733
// Unknown, and in that case we want the result to contain Unknown in those
733734
// places again.
734-
substs
735-
.map(|s| fallback_bound_vars(s.suffix(vars.len(&Interner)), self_ty.binders.len(&Interner)))
735+
let suffix =
736+
Substitution::from_iter(&Interner, substs.iter(&Interner).cloned().skip(self_ty_vars));
737+
Some(fallback_bound_vars(suffix, self_ty_vars))
736738
}
737739

738740
/// This replaces any 'free' Bound vars in `s` (i.e. those with indices past

0 commit comments

Comments
 (0)