@@ -407,6 +407,7 @@ where
407
407
match * t. kind ( ) {
408
408
ty:: Bound ( debruijn, bound_ty) if debruijn == self . current_index => {
409
409
let ty = self . delegate . replace_ty ( bound_ty) ;
410
+ debug_assert ! ( !ty. has_vars_bound_above( ty:: INNERMOST ) ) ;
410
411
ty:: fold:: shift_vars ( self . tcx , ty, self . current_index . as_u32 ( ) )
411
412
}
412
413
_ if t. has_vars_bound_at_or_above ( self . current_index ) => t. super_fold_with ( self ) ,
@@ -437,6 +438,7 @@ where
437
438
match ct. kind ( ) {
438
439
ty:: ConstKind :: Bound ( debruijn, bound_const) if debruijn == self . current_index => {
439
440
let ct = self . delegate . replace_const ( bound_const, ct. ty ( ) ) ;
441
+ debug_assert ! ( !ct. has_vars_bound_above( ty:: INNERMOST ) ) ;
440
442
ty:: fold:: shift_vars ( self . tcx , ct, self . current_index . as_u32 ( ) )
441
443
}
442
444
_ => ct. super_fold_with ( self ) ,
@@ -697,46 +699,41 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
697
699
698
700
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
699
701
match * r {
700
- ty:: ReLateBound ( debruijn, br) => {
701
- if self . amount == 0 || debruijn < self . current_index {
702
- r
703
- } else {
704
- let debruijn = debruijn. shifted_in ( self . amount ) ;
705
- let shifted = ty:: ReLateBound ( debruijn, br) ;
706
- self . tcx . mk_region ( shifted)
707
- }
702
+ ty:: ReLateBound ( debruijn, br) if debruijn >= self . current_index => {
703
+ let debruijn = debruijn. shifted_in ( self . amount ) ;
704
+ let shifted = ty:: ReLateBound ( debruijn, br) ;
705
+ self . tcx . mk_region ( shifted)
708
706
}
709
707
_ => r,
710
708
}
711
709
}
712
710
713
711
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
714
712
match * ty. kind ( ) {
715
- ty:: Bound ( debruijn, bound_ty) => {
716
- if self . amount == 0 || debruijn < self . current_index {
717
- ty
718
- } else {
719
- let debruijn = debruijn. shifted_in ( self . amount ) ;
720
- self . tcx . mk_ty ( ty:: Bound ( debruijn, bound_ty) )
721
- }
713
+ ty:: Bound ( debruijn, bound_ty) if debruijn >= self . current_index => {
714
+ let debruijn = debruijn. shifted_in ( self . amount ) ;
715
+ self . tcx . mk_ty ( ty:: Bound ( debruijn, bound_ty) )
722
716
}
723
717
724
- _ => ty. super_fold_with ( self ) ,
718
+ _ if ty. has_vars_bound_at_or_above ( self . current_index ) => ty. super_fold_with ( self ) ,
719
+ _ => ty,
725
720
}
726
721
}
727
722
728
723
fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
729
- if let ty:: ConstKind :: Bound ( debruijn, bound_ct) = ct. kind ( ) {
730
- if self . amount == 0 || debruijn < self . current_index {
731
- ct
732
- } else {
733
- let debruijn = debruijn. shifted_in ( self . amount ) ;
734
- self . tcx . mk_const ( ty:: ConstKind :: Bound ( debruijn, bound_ct) , ct. ty ( ) )
735
- }
724
+ if let ty:: ConstKind :: Bound ( debruijn, bound_ct) = ct. kind ( )
725
+ && debruijn >= self . current_index
726
+ {
727
+ let debruijn = debruijn. shifted_in ( self . amount ) ;
728
+ self . tcx . mk_const ( ty:: ConstKind :: Bound ( debruijn, bound_ct) , ct. ty ( ) )
736
729
} else {
737
730
ct. super_fold_with ( self )
738
731
}
739
732
}
733
+
734
+ fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
735
+ if p. has_vars_bound_at_or_above ( self . current_index ) { p. super_fold_with ( self ) } else { p }
736
+ }
740
737
}
741
738
742
739
pub fn shift_region < ' tcx > (
@@ -758,5 +755,9 @@ where
758
755
{
759
756
debug ! ( "shift_vars(value={:?}, amount={})" , value, amount) ;
760
757
758
+ if amount == 0 || !value. has_escaping_bound_vars ( ) {
759
+ return value;
760
+ }
761
+
761
762
value. fold_with ( & mut Shifter :: new ( tcx, amount) )
762
763
}
0 commit comments