+ }
+}
+
+impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Shifter<'a, 'gcx, 'tcx> {
+ fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
+
+ fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
+ self.current_index.shift_in(1);
+ let t = t.super_fold_with(self);
+ self.current_index.shift_out(1);
+ t
+ }
+
+ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
+ match *r {
+ ty::ReLateBound(debruijn, br) => {
+ if self.amount == 0 || debruijn < self.current_index {
+ r
+ } else {
+ let shifted = ty::ReLateBound(debruijn.shifted_in(self.amount), br);
+ self.tcx.mk_region(shifted)
+ }
+ }
+ _ => r
+ }
+ }
+
+ fn fold_ty(&mut self, ty: ty::Ty<'tcx>) -> ty::Ty<'tcx> {
+ match ty.sty {
+ ty::Bound(bound_ty) => {
+ if self.amount == 0 || bound_ty.level < self.current_index {
+ ty
+ } else {
+ let shifted = ty::BoundTy {
+ level: bound_ty.level.shifted_in(self.amount),
+ var: bound_ty.var,
+ kind: bound_ty.kind,
+ };
+ self.tcx.mk_ty(ty::Bound(shifted))
+ }
+ }
+
+ _ => ty.super_fold_with(self),