@@ -534,8 +534,8 @@ impl<'tcx> TyCtxt<'tcx> {
534
534
/// results returned by the closure; the closure is expected to
535
535
/// return a free region (relative to this binder), and hence the
536
536
/// binder is removed in the return type. The closure is invoked
537
- /// once for each unique `BoundRegion `; multiple references to the
538
- /// same `BoundRegion ` will reuse the previous result. A map is
537
+ /// once for each unique `BoundRegionKind `; multiple references to the
538
+ /// same `BoundRegionKind ` will reuse the previous result. A map is
539
539
/// returned at the end with each bound region and the free region
540
540
/// that replaced it.
541
541
///
@@ -544,7 +544,7 @@ impl<'tcx> TyCtxt<'tcx> {
544
544
pub fn replace_late_bound_regions < T , F > (
545
545
self ,
546
546
value : Binder < T > ,
547
- fld_r : F ,
547
+ mut fld_r : F ,
548
548
) -> ( T , BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > )
549
549
where
550
550
F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
@@ -555,7 +555,10 @@ impl<'tcx> TyCtxt<'tcx> {
555
555
let fld_c = |bound_ct, ty| {
556
556
self . mk_const ( ty:: Const { val : ty:: ConstKind :: Bound ( ty:: INNERMOST , bound_ct) , ty } )
557
557
} ;
558
- self . replace_escaping_bound_vars ( value. skip_binder ( ) , fld_r, fld_t, fld_c)
558
+ let mut region_map = BTreeMap :: new ( ) ;
559
+ let real_fld_r = |br : ty:: BoundRegion | * region_map. entry ( br) . or_insert_with ( || fld_r ( br) ) ;
560
+ let value = self . replace_escaping_bound_vars ( value. skip_binder ( ) , real_fld_r, fld_t, fld_c) ;
561
+ ( value, region_map)
559
562
}
560
563
561
564
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
@@ -567,34 +570,18 @@ impl<'tcx> TyCtxt<'tcx> {
567
570
mut fld_r : F ,
568
571
mut fld_t : G ,
569
572
mut fld_c : H ,
570
- ) -> ( T , BTreeMap < ty :: BoundRegion , ty :: Region < ' tcx > > )
573
+ ) -> T
571
574
where
572
575
F : FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
573
576
G : FnMut ( ty:: BoundTy ) -> Ty < ' tcx > ,
574
577
H : FnMut ( ty:: BoundVar , Ty < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > ,
575
578
T : TypeFoldable < ' tcx > ,
576
579
{
577
- use rustc_data_structures:: fx:: FxHashMap ;
578
-
579
- let mut region_map = BTreeMap :: new ( ) ;
580
- let mut type_map = FxHashMap :: default ( ) ;
581
- let mut const_map = FxHashMap :: default ( ) ;
582
-
583
580
if !value. has_escaping_bound_vars ( ) {
584
- ( value, region_map )
581
+ value
585
582
} else {
586
- let mut real_fld_r = |br| * region_map. entry ( br) . or_insert_with ( || fld_r ( br) ) ;
587
-
588
- let mut real_fld_t =
589
- |bound_ty| * type_map. entry ( bound_ty) . or_insert_with ( || fld_t ( bound_ty) ) ;
590
-
591
- let mut real_fld_c =
592
- |bound_ct, ty| * const_map. entry ( bound_ct) . or_insert_with ( || fld_c ( bound_ct, ty) ) ;
593
-
594
- let mut replacer =
595
- BoundVarReplacer :: new ( self , & mut real_fld_r, & mut real_fld_t, & mut real_fld_c) ;
596
- let result = value. fold_with ( & mut replacer) ;
597
- ( result, region_map)
583
+ let mut replacer = BoundVarReplacer :: new ( self , & mut fld_r, & mut fld_t, & mut fld_c) ;
584
+ value. fold_with ( & mut replacer)
598
585
}
599
586
}
600
587
@@ -604,7 +591,7 @@ impl<'tcx> TyCtxt<'tcx> {
604
591
pub fn replace_bound_vars < T , F , G , H > (
605
592
self ,
606
593
value : Binder < T > ,
607
- fld_r : F ,
594
+ mut fld_r : F ,
608
595
fld_t : G ,
609
596
fld_c : H ,
610
597
) -> ( T , BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > )
@@ -614,7 +601,10 @@ impl<'tcx> TyCtxt<'tcx> {
614
601
H : FnMut ( ty:: BoundVar , Ty < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > ,
615
602
T : TypeFoldable < ' tcx > ,
616
603
{
617
- self . replace_escaping_bound_vars ( value. skip_binder ( ) , fld_r, fld_t, fld_c)
604
+ let mut region_map = BTreeMap :: new ( ) ;
605
+ let real_fld_r = |br : ty:: BoundRegion | * region_map. entry ( br) . or_insert_with ( || fld_r ( br) ) ;
606
+ let value = self . replace_escaping_bound_vars ( value. skip_binder ( ) , real_fld_r, fld_t, fld_c) ;
607
+ ( value, region_map)
618
608
}
619
609
620
610
/// Replaces any late-bound regions bound in `value` with
@@ -626,7 +616,7 @@ impl<'tcx> TyCtxt<'tcx> {
626
616
self . replace_late_bound_regions ( value, |br| {
627
617
self . mk_region ( ty:: ReFree ( ty:: FreeRegion {
628
618
scope : all_outlive_scope,
629
- bound_region : br,
619
+ bound_region : br. kind ,
630
620
} ) )
631
621
} )
632
622
. 0
@@ -639,7 +629,7 @@ impl<'tcx> TyCtxt<'tcx> {
639
629
pub fn collect_constrained_late_bound_regions < T > (
640
630
self ,
641
631
value : & Binder < T > ,
642
- ) -> FxHashSet < ty:: BoundRegion >
632
+ ) -> FxHashSet < ty:: BoundRegionKind >
643
633
where
644
634
T : TypeFoldable < ' tcx > ,
645
635
{
@@ -650,7 +640,7 @@ impl<'tcx> TyCtxt<'tcx> {
650
640
pub fn collect_referenced_late_bound_regions < T > (
651
641
self ,
652
642
value : & Binder < T > ,
653
- ) -> FxHashSet < ty:: BoundRegion >
643
+ ) -> FxHashSet < ty:: BoundRegionKind >
654
644
where
655
645
T : TypeFoldable < ' tcx > ,
656
646
{
@@ -661,7 +651,7 @@ impl<'tcx> TyCtxt<'tcx> {
661
651
self ,
662
652
value : & Binder < T > ,
663
653
just_constraint : bool ,
664
- ) -> FxHashSet < ty:: BoundRegion >
654
+ ) -> FxHashSet < ty:: BoundRegionKind >
665
655
where
666
656
T : TypeFoldable < ' tcx > ,
667
657
{
@@ -695,7 +685,8 @@ impl<'tcx> TyCtxt<'tcx> {
695
685
let mut counter = 0 ;
696
686
Binder :: bind (
697
687
self . replace_late_bound_regions ( sig, |_| {
698
- let r = self . mk_region ( ty:: ReLateBound ( ty:: INNERMOST , ty:: BrAnon ( counter) ) ) ;
688
+ let br = ty:: BoundRegion { kind : ty:: BrAnon ( counter) } ;
689
+ let r = self . mk_region ( ty:: ReLateBound ( ty:: INNERMOST , br) ) ;
699
690
counter += 1 ;
700
691
r
701
692
} )
@@ -955,7 +946,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
955
946
/// into a hash set.
956
947
struct LateBoundRegionsCollector {
957
948
current_index : ty:: DebruijnIndex ,
958
- regions : FxHashSet < ty:: BoundRegion > ,
949
+ regions : FxHashSet < ty:: BoundRegionKind > ,
959
950
960
951
/// `true` if we only want regions that are known to be
961
952
/// "constrained" when you equate this type with another type. In
@@ -1014,7 +1005,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
1014
1005
fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
1015
1006
if let ty:: ReLateBound ( debruijn, br) = * r {
1016
1007
if debruijn == self . current_index {
1017
- self . regions . insert ( br) ;
1008
+ self . regions . insert ( br. kind ) ;
1018
1009
}
1019
1010
}
1020
1011
ControlFlow :: CONTINUE
0 commit comments