Skip to content

Commit 1b24602

Browse files
committed
Extract leak check into a distinct subroutine.
1 parent 885f7ee commit 1b24602

File tree

1 file changed

+32
-18
lines changed
  • src/librustc/middle/infer/higher_ranked

1 file changed

+32
-18
lines changed

src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,17 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
8484

8585
// Presuming type comparison succeeds, we need to check
8686
// 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)) => {
10390
if self.a_is_expected() {
10491
debug!("Not as polymorphic!");
10592
return Err(ty::terr_regions_insufficiently_polymorphic(skol_br,
106-
*tainted_region));
93+
tainted_region));
10794
} else {
10895
debug!("Overly polymorphic!");
10996
return Err(ty::terr_regions_overly_polymorphic(skol_br,
110-
*tainted_region));
97+
tainted_region));
11198
}
11299
}
113100
}
@@ -548,3 +535,30 @@ fn skolemize_regions<'a,'tcx,HR>(infcx: &InferCtxt<'a,'tcx>,
548535
skol
549536
})
550537
}
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

Comments
 (0)