@@ -520,22 +520,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
520
520
pub fn replace_late_bound_regions < T , F > (
521
521
self ,
522
522
value : & Binder < T > ,
523
- mut fld_r : F
523
+ fld_r : F
524
524
) -> ( T , BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > )
525
525
where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
526
526
T : TypeFoldable < ' tcx >
527
527
{
528
- let mut map = BTreeMap :: new ( ) ;
529
- let mut real_fldr = |br| {
530
- * map. entry ( br) . or_insert_with ( || fld_r ( br) )
531
- } ;
532
-
533
528
// 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)
539
531
}
540
532
541
533
/// Replace all escaping bound vars. The `fld_r` closure replaces escaping
@@ -545,17 +537,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
545
537
value : & T ,
546
538
mut fld_r : F ,
547
539
mut fld_t : G
548
- ) -> T
540
+ ) -> ( T , BTreeMap < ty :: BoundRegion , ty :: Region < ' tcx > > )
549
541
where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
550
542
G : FnMut ( ty:: BoundTy ) -> ty:: Ty < ' tcx > ,
551
543
T : TypeFoldable < ' tcx >
552
544
{
545
+ let mut map = BTreeMap :: new ( ) ;
546
+
553
547
if !value. has_escaping_bound_vars ( ) {
554
- value. clone ( )
548
+ ( value. clone ( ) , map )
555
549
} 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) ;
557
555
let result = value. fold_with ( & mut replacer) ;
558
- result
556
+ ( result, map )
559
557
}
560
558
}
561
559
@@ -567,7 +565,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
567
565
value : & Binder < T > ,
568
566
fld_r : F ,
569
567
fld_t : G
570
- ) -> T
568
+ ) -> ( T , BTreeMap < ty :: BoundRegion , ty :: Region < ' tcx > > )
571
569
where F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
572
570
G : FnMut ( ty:: BoundTy ) -> ty:: Ty < ' tcx > ,
573
571
T : TypeFoldable < ' tcx >
0 commit comments