Skip to content

Commit 6dba4ed

Browse files
committed
Auto merge of rust-lang#99056 - lcnr:higher_ranked_sub, r=oli-obk
don't use `commit_if_ok` during `higher_ranked_sub` This snapshot doesn't really do anything useful for us, especially once we deal with placeholder outlive bounds during trait solving. I guess that currently the idea is that `higher_ranked_sub` could cause a later `leak_check` to fail even if the combine operation isn't actually relevant. But really, using combine outside of snapshot and ignoring its result is wrong anyways, as it can constrain inference variables. r? rust-lang/types
2 parents f893495 + aea2d7e commit 6dba4ed

File tree

1 file changed

+17
-21
lines changed
  • compiler/rustc_infer/src/infer/higher_ranked

1 file changed

+17
-21
lines changed

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,27 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
3434
T: Relate<'tcx>,
3535
{
3636
let span = self.trace.cause.span;
37+
// First, we instantiate each bound region in the supertype with a
38+
// fresh placeholder region. Note that this automatically creates
39+
// a new universe if needed.
40+
let sup_prime = self.infcx.replace_bound_vars_with_placeholders(sup);
3741

38-
self.infcx.commit_if_ok(|_| {
39-
// First, we instantiate each bound region in the supertype with a
40-
// fresh placeholder region. Note that this automatically creates
41-
// a new universe if needed.
42-
let sup_prime = self.infcx.replace_bound_vars_with_placeholders(sup);
42+
// Next, we instantiate each bound region in the subtype
43+
// with a fresh region variable. These region variables --
44+
// but no other pre-existing region variables -- can name
45+
// the placeholders.
46+
let sub_prime = self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, sub);
4347

44-
// Next, we instantiate each bound region in the subtype
45-
// with a fresh region variable. These region variables --
46-
// but no other pre-existing region variables -- can name
47-
// the placeholders.
48-
let sub_prime =
49-
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, sub);
48+
debug!("a_prime={:?}", sub_prime);
49+
debug!("b_prime={:?}", sup_prime);
5050

51-
debug!("a_prime={:?}", sub_prime);
52-
debug!("b_prime={:?}", sup_prime);
51+
// Compare types now that bound regions have been replaced.
52+
let result = self.sub(sub_is_expected).relate(sub_prime, sup_prime)?;
5353

54-
// Compare types now that bound regions have been replaced.
55-
let result = self.sub(sub_is_expected).relate(sub_prime, sup_prime)?;
56-
57-
debug!("higher_ranked_sub: OK result={result:?}");
58-
// NOTE: returning the result here would be dangerous as it contains
59-
// placeholders which **must not** be named afterwards.
60-
Ok(())
61-
})
54+
debug!("OK result={result:?}");
55+
// NOTE: returning the result here would be dangerous as it contains
56+
// placeholders which **must not** be named afterwards.
57+
Ok(())
6258
}
6359
}
6460

0 commit comments

Comments
 (0)