@@ -753,19 +753,29 @@ impl<'tcx> TyCtxt<'tcx> {
753753 T : TypeFoldable < ' tcx > ,
754754 {
755755 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+ {
758770 let mut fld_t = |b| bug ! ( "unexpected bound ty in binder: {b:?}" ) ;
759771 let mut fld_c = |b, ty| bug ! ( "unexpected bound ct in binder: {b:?} {ty}" ) ;
760-
761772 let value = value. skip_binder ( ) ;
762- let value = if !value. has_escaping_bound_vars ( ) {
773+ if !value. has_escaping_bound_vars ( ) {
763774 value
764775 } 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) ;
766777 value. fold_with ( & mut replacer)
767- } ;
768- ( value, region_map)
778+ }
769779 }
770780
771781 /// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
@@ -821,13 +831,12 @@ impl<'tcx> TyCtxt<'tcx> {
821831 where
822832 T : TypeFoldable < ' tcx > ,
823833 {
824- self . replace_late_bound_regions ( value, |br| {
834+ self . replace_late_bound_regions_uncached ( value, |br| {
825835 self . mk_region ( ty:: ReFree ( ty:: FreeRegion {
826836 scope : all_outlive_scope,
827837 bound_region : br. kind ,
828838 } ) )
829839 } )
830- . 0
831840 }
832841
833842 pub fn shift_bound_var_indices < T > ( self , bound_vars : usize , value : T ) -> T
0 commit comments