Skip to content

Commit f2cf994

Browse files
committed
rewrite leak check to be based on universes
In the new leak check, instead of getting a list of placeholders to track, we look for any placeholder that is part of a universe which was created during the snapshot. We are looking for the following error patterns: * P1: P2, where P1 != P2 * P1: R, where R is in some universe that cannot name P1 This new leak check is more precise than before, in that it accepts this patterns: * R: P1, even if R cannot name P1, because R = 'static is a valid sol'n * R: P1, R: P2, as above Note that this leak check, when running during subtyping, is less efficient than before in some sense because it is going to check and re-check all the universes created since the snapshot. We're going to move when the leak check runs to try and correct that.
1 parent 4199b3a commit f2cf994

29 files changed

+571
-319
lines changed

src/librustc_infer/infer/higher_ranked/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
3333
self.infcx.commit_if_ok(|snapshot| {
3434
// First, we instantiate each bound region in the supertype with a
3535
// fresh placeholder region.
36-
let (b_prime, placeholder_map) = self.infcx.replace_bound_vars_with_placeholders(b);
36+
let (b_prime, _) = self.infcx.replace_bound_vars_with_placeholders(b);
3737

3838
// Next, we instantiate each bound region in the subtype
3939
// with a fresh region variable. These region variables --
@@ -48,7 +48,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
4848
// Compare types now that bound regions have been replaced.
4949
let result = self.sub(a_is_expected).relate(&a_prime, &b_prime)?;
5050

51-
self.infcx.leak_check(!a_is_expected, &placeholder_map, snapshot)?;
51+
self.infcx.leak_check(!a_is_expected, snapshot)?;
5252

5353
debug!("higher_ranked_sub: OK result={:?}", result);
5454

@@ -119,7 +119,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
119119
pub fn leak_check(
120120
&self,
121121
overly_polymorphic: bool,
122-
placeholder_map: &PlaceholderMap<'tcx>,
123122
snapshot: &CombinedSnapshot<'_, 'tcx>,
124123
) -> RelateResult<'tcx, ()> {
125124
// If the user gave `-Zno-leak-check`, or we have been
@@ -135,7 +134,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
135134
self.inner.borrow_mut().unwrap_region_constraints().leak_check(
136135
self.tcx,
137136
overly_polymorphic,
138-
placeholder_map,
137+
self.universe(),
139138
snapshot,
140139
)
141140
}

src/librustc_infer/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,12 +992,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
992992
}
993993

994994
Some(self.commit_if_ok(|snapshot| {
995-
let (ty::SubtypePredicate { a_is_expected, a, b }, placeholder_map) =
995+
let (ty::SubtypePredicate { a_is_expected, a, b }, _) =
996996
self.replace_bound_vars_with_placeholders(&predicate);
997997

998998
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
999999

1000-
self.leak_check(false, &placeholder_map, snapshot)?;
1000+
self.leak_check(false, snapshot)?;
10011001

10021002
Ok(ok.unit())
10031003
}))
@@ -1009,13 +1009,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10091009
predicate: ty::PolyRegionOutlivesPredicate<'tcx>,
10101010
) -> UnitResult<'tcx> {
10111011
self.commit_if_ok(|snapshot| {
1012-
let (ty::OutlivesPredicate(r_a, r_b), placeholder_map) =
1012+
let (ty::OutlivesPredicate(r_a, r_b), _) =
10131013
self.replace_bound_vars_with_placeholders(&predicate);
10141014
let origin = SubregionOrigin::from_obligation_cause(cause, || {
10151015
RelateRegionParamBound(cause.span)
10161016
});
10171017
self.sub_regions(origin, r_b, r_a); // `b : a` ==> `a <= b`
1018-
self.leak_check(false, &placeholder_map, snapshot)?;
1018+
self.leak_check(false, snapshot)?;
10191019
Ok(())
10201020
})
10211021
}

0 commit comments

Comments
 (0)