@@ -520,22 +520,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
520520 pub fn replace_late_bound_regions < T , F > (
521521 self ,
522522 value : & Binder < T > ,
523- mut fld_r : F
523+ fld_r : F
524524 ) -> ( T , BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > )
525525 where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
526526 T : TypeFoldable < ' tcx >
527527 {
528- let mut map = BTreeMap :: new ( ) ;
529- let mut real_fldr = |br| {
530- * map. entry ( br) . or_insert_with ( || fld_r ( br) )
531- } ;
532-
533528 // identity for bound types
534- let mut fld_t = |bound_ty| self . mk_ty ( ty:: Bound ( bound_ty) ) ;
535-
536- let mut replacer = BoundVarReplacer :: new ( self , & mut real_fldr, & mut fld_t) ;
537- let result = value. skip_binder ( ) . fold_with ( & mut replacer) ;
538- ( result, map)
529+ let fld_t = |bound_ty| self . mk_ty ( ty:: Bound ( bound_ty) ) ;
530+ self . replace_escaping_bound_vars ( value. skip_binder ( ) , fld_r, fld_t)
539531 }
540532
541533 /// Replace all escaping bound vars. The `fld_r` closure replaces escaping
@@ -545,17 +537,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
545537 value : & T ,
546538 mut fld_r : F ,
547539 mut fld_t : G
548- ) -> T
540+ ) -> ( T , BTreeMap < ty :: BoundRegion , ty :: Region < ' tcx > > )
549541 where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
550542 G : FnMut ( ty:: BoundTy ) -> ty:: Ty < ' tcx > ,
551543 T : TypeFoldable < ' tcx >
552544 {
545+ let mut map = BTreeMap :: new ( ) ;
546+
553547 if !value. has_escaping_bound_vars ( ) {
554- value. clone ( )
548+ ( value. clone ( ) , map )
555549 } else {
556- let mut replacer = BoundVarReplacer :: new ( self , & mut fld_r, & mut fld_t) ;
550+ let mut real_fld_r = |br| {
551+ * map. entry ( br) . or_insert_with ( || fld_r ( br) )
552+ } ;
553+
554+ let mut replacer = BoundVarReplacer :: new ( self , & mut real_fld_r, & mut fld_t) ;
557555 let result = value. fold_with ( & mut replacer) ;
558- result
556+ ( result, map )
559557 }
560558 }
561559
@@ -567,7 +565,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
567565 value : & Binder < T > ,
568566 fld_r : F ,
569567 fld_t : G
570- ) -> T
568+ ) -> ( T , BTreeMap < ty :: BoundRegion , ty :: Region < ' tcx > > )
571569 where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
572570 G : FnMut ( ty:: BoundTy ) -> ty:: Ty < ' tcx > ,
573571 T : TypeFoldable < ' tcx >
0 commit comments