@@ -753,19 +753,29 @@ impl<'tcx> TyCtxt<'tcx> {
753
753
T : TypeFoldable < ' tcx > ,
754
754
{
755
755
let mut region_map = BTreeMap :: new ( ) ;
756
- let mut real_fld_r =
757
- |br : ty:: BoundRegion | * region_map. entry ( br) . or_insert_with ( || fld_r ( br) ) ;
756
+ let real_fld_r = |br : ty:: BoundRegion | * region_map. entry ( br) . or_insert_with ( || fld_r ( br) ) ;
757
+ let value = self . replace_late_bound_regions_uncached ( value, real_fld_r) ;
758
+ ( value, region_map)
759
+ }
760
+
761
+ pub fn replace_late_bound_regions_uncached < T , F > (
762
+ self ,
763
+ value : Binder < ' tcx , T > ,
764
+ mut fld_r : F ,
765
+ ) -> T
766
+ where
767
+ F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
768
+ T : TypeFoldable < ' tcx > ,
769
+ {
758
770
let mut fld_t = |b| bug ! ( "unexpected bound ty in binder: {b:?}" ) ;
759
771
let mut fld_c = |b, ty| bug ! ( "unexpected bound ct in binder: {b:?} {ty}" ) ;
760
-
761
772
let value = value. skip_binder ( ) ;
762
- let value = if !value. has_escaping_bound_vars ( ) {
773
+ if !value. has_escaping_bound_vars ( ) {
763
774
value
764
775
} else {
765
- let mut replacer = BoundVarReplacer :: new ( self , & mut real_fld_r , & mut fld_t, & mut fld_c) ;
776
+ let mut replacer = BoundVarReplacer :: new ( self , & mut fld_r , & mut fld_t, & mut fld_c) ;
766
777
value. fold_with ( & mut replacer)
767
- } ;
768
- ( value, region_map)
778
+ }
769
779
}
770
780
771
781
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
@@ -821,13 +831,12 @@ impl<'tcx> TyCtxt<'tcx> {
821
831
where
822
832
T : TypeFoldable < ' tcx > ,
823
833
{
824
- self . replace_late_bound_regions ( value, |br| {
834
+ self . replace_late_bound_regions_uncached ( value, |br| {
825
835
self . mk_region ( ty:: ReFree ( ty:: FreeRegion {
826
836
scope : all_outlive_scope,
827
837
bound_region : br. kind ,
828
838
} ) )
829
839
} )
830
- . 0
831
840
}
832
841
833
842
pub fn shift_bound_var_indices < T > ( self , bound_vars : usize , value : T ) -> T
0 commit comments