@@ -84,30 +84,17 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
84
84
85
85
// Presuming type comparison succeeds, we need to check
86
86
// that the skolemized regions do not "leak".
87
- let new_vars = self . infcx ( ) . region_vars_confined_to_snapshot ( snapshot) ;
88
- for ( & skol_br, & skol) in skol_map. iter ( ) {
89
- let tainted = self . infcx ( ) . tainted_regions ( snapshot, skol) ;
90
- for tainted_region in tainted. iter ( ) {
91
- // Each skolemized should only be relatable to itself
92
- // or new variables:
93
- match * tainted_region {
94
- ty:: ReInfer ( ty:: ReVar ( ref vid) ) => {
95
- if new_vars. iter ( ) . any ( |x| x == vid) { continue ; }
96
- }
97
- _ => {
98
- if * tainted_region == skol { continue ; }
99
- }
100
- } ;
101
-
102
- // A is not as polymorphic as B:
87
+ match leak_check ( self . infcx ( ) , & skol_map, snapshot) {
88
+ Ok ( ( ) ) => { }
89
+ Err ( ( skol_br, tainted_region) ) => {
103
90
if self . a_is_expected ( ) {
104
91
debug ! ( "Not as polymorphic!" ) ;
105
92
return Err ( ty:: terr_regions_insufficiently_polymorphic ( skol_br,
106
- * tainted_region) ) ;
93
+ tainted_region) ) ;
107
94
} else {
108
95
debug ! ( "Overly polymorphic!" ) ;
109
96
return Err ( ty:: terr_regions_overly_polymorphic ( skol_br,
110
- * tainted_region) ) ;
97
+ tainted_region) ) ;
111
98
}
112
99
}
113
100
}
@@ -548,3 +535,30 @@ fn skolemize_regions<'a,'tcx,HR>(infcx: &InferCtxt<'a,'tcx>,
548
535
skol
549
536
} )
550
537
}
538
+
539
+ fn leak_check < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
540
+ skol_map : & FnvHashMap < ty:: BoundRegion , ty:: Region > ,
541
+ snapshot : & CombinedSnapshot )
542
+ -> Result < ( ) , ( ty:: BoundRegion , ty:: Region ) >
543
+ {
544
+ let new_vars = infcx. region_vars_confined_to_snapshot ( snapshot) ;
545
+ for ( & skol_br, & skol) in skol_map. iter ( ) {
546
+ let tainted = infcx. tainted_regions ( snapshot, skol) ;
547
+ for & tainted_region in tainted. iter ( ) {
548
+ // Each skolemized should only be relatable to itself
549
+ // or new variables:
550
+ match tainted_region {
551
+ ty:: ReInfer ( ty:: ReVar ( vid) ) => {
552
+ if new_vars. iter ( ) . any ( |& x| x == vid) { continue ; }
553
+ }
554
+ _ => {
555
+ if tainted_region == skol { continue ; }
556
+ }
557
+ } ;
558
+
559
+ // A is not as polymorphic as B:
560
+ return Err ( ( skol_br, tainted_region) ) ;
561
+ }
562
+ }
563
+ Ok ( ( ) )
564
+ }
0 commit comments