aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 0f49dd39b..69265286f 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -538,12 +538,6 @@ impl<T: TypeWalk> Binders<T> {
538 assert_eq!(subst.len(), self.num_binders); 538 assert_eq!(subst.len(), self.num_binders);
539 self.value.subst_bound_vars(subst) 539 self.value.subst_bound_vars(subst)
540 } 540 }
541
542 /// Substitutes just a prefix of the variables (shifting the rest).
543 pub fn subst_prefix(self, subst: &Substitution) -> Binders<T> {
544 assert!(subst.len() < self.num_binders);
545 Binders::new(self.num_binders - subst.len(), self.value.subst_bound_vars(subst))
546 }
547} 541}
548 542
549impl<T: TypeWalk> TypeWalk for Binders<T> { 543impl<T: TypeWalk> TypeWalk for Binders<T> {
@@ -698,7 +692,15 @@ impl CallableSig {
698 692
699 pub fn from_fn_ptr(fn_ptr: &FnPointer) -> CallableSig { 693 pub fn from_fn_ptr(fn_ptr: &FnPointer) -> CallableSig {
700 CallableSig { 694 CallableSig {
701 params_and_return: fn_ptr.substs.interned(&Interner).iter().cloned().collect(), 695 // FIXME: what to do about lifetime params?
696 params_and_return: fn_ptr
697 .substs
698 .clone()
699 .shift_bound_vars_out(DebruijnIndex::ONE)
700 .interned(&Interner)
701 .iter()
702 .cloned()
703 .collect(),
702 is_varargs: fn_ptr.sig.variadic, 704 is_varargs: fn_ptr.sig.variadic,
703 } 705 }
704 } 706 }
@@ -1131,6 +1133,23 @@ pub trait TypeWalk {
1131 DebruijnIndex::INNERMOST, 1133 DebruijnIndex::INNERMOST,
1132 ) 1134 )
1133 } 1135 }
1136
1137 /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`.
1138 fn shift_bound_vars_out(self, n: DebruijnIndex) -> Self
1139 where
1140 Self: Sized + std::fmt::Debug,
1141 {
1142 self.fold_binders(
1143 &mut |ty, binders| match ty.interned(&Interner) {
1144 TyKind::BoundVar(bound) if bound.debruijn >= binders => {
1145 TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone()))
1146 .intern(&Interner)
1147 }
1148 _ => ty,
1149 },
1150 DebruijnIndex::INNERMOST,
1151 )
1152 }
1134} 1153}
1135 1154
1136impl TypeWalk for Ty { 1155impl TypeWalk for Ty {