aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-05 20:49:27 +0100
committerFlorian Diebold <[email protected]>2021-04-05 20:58:03 +0100
commit2a83645e1bb01578c4bbe5f71418d354108dfd77 (patch)
tree89d0dcb3b3b3eb511fe717c2d0aeb268095b5221 /crates
parentb443e5304ec43ae2049c72b694ff62baf4314cbb (diff)
Get rid of Substitution::suffix
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/lib.rs6
-rw-r--r--crates/hir_ty/src/method_resolution.rs10
2 files changed, 6 insertions, 10 deletions
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 {
79 pub fn prefix(&self, n: usize) -> Substitution { 79 pub fn prefix(&self, n: usize) -> Substitution {
80 Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into()) 80 Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
81 } 81 }
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 }
88} 82}
89 83
90/// Return an index of a parameter in the generic type parameter list by it's id. 84/// 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(
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