Skip to content

Commit f8f8a50

Browse files
committed
Move push_region_constraints calls to right after add_implied_bounds calls
1 parent 27ab794 commit f8f8a50

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-49
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
260260
// We add implied bounds from both the unnormalized and normalized ty.
261261
// See issue #87748
262262
let constraints_unnorm = self.add_implied_bounds(ty);
263+
constraints_unnorm.map(|c| self.push_region_constraints(c));
263264
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } = self
264265
.param_env
265266
.and(type_op::normalize::Normalize::new(ty))
@@ -275,6 +276,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
275276
error_info: None,
276277
}
277278
});
279+
constraints_normalize.map(|c| self.push_region_constraints(c));
278280

279281
// Note: we need this in examples like
280282
// ```
@@ -289,55 +291,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
289291
// ```
290292
// Both &Self::Bar and &() are WF
291293
let constraints_norm = self.add_implied_bounds(norm_ty);
292-
293-
// Okay, I should explain why these are all the way down here. Turns
294-
// out, it's actually a bit subtle. I'll use the test `issue-52057`
295-
// as an example (well, because it's the only test that failed
296-
// putting these calls immediately after the `add_implied_bounds`
297-
// calls.)
298-
//
299-
// So, the key bit is this impl:
300-
// ```rust,ignore (example)
301-
// impl<'a, I, P: ?Sized> Parser for &'a mut P
302-
// where P: Parser<Input = I>,
303-
// {
304-
// type Input = I;
305-
// fn parse_first<'x>(_: &'x mut Self::Input) {}
306-
// }
307-
//
308-
// As part of querying the implied bounds for `&mut Self::Input`
309-
// (note the unnormalized form), we query the obligations to prove
310-
// that it is WF. This turns out to be
311-
// [
312-
// <&'_#0r mut P as Parser>::Input: '_#1r,
313-
// Self: Parser,
314-
// P: '_#0r,
315-
// ]
316-
//
317-
// The wf code normalizes these obligations, so we actually end up with
318-
// [
319-
// _#0t: '_#1r,
320-
// &'_#0r mut P as Parser>::Input == _#0t,
321-
// Self: Parser,
322-
// P: '_#0r,
323-
// ]
324-
//
325-
// The implied bounds code then registers both the first two
326-
// predicates to be solved, since they contain type variables. Then
327-
// the implied bounds code goes through each of these obligations to
328-
// check if they should be registered as implied bounds. For
329-
// `_#0t: '_#1r`, there is an unresolved type variable, so it gets
330-
// skipped. The next two predicates never would registered. The last
331-
// predicate gets registered.
332-
//
333-
// At the end of this, for the unnormalized type
334-
// `&'x mut Self::Input`, `P: '_#0r' ends up as a implied bound and
335-
// `I: '_#1r` ends up as a constraint.
336-
//
337-
// Later, for the normalized type (`&'x mut I`), we don't do any
338-
// normalization, so we only end up with the implied bound `I: 'x`.
339-
constraints_unnorm.map(|c| self.push_region_constraints(c));
340-
constraints_normalize.map(|c| self.push_region_constraints(c));
341294
constraints_norm.map(|c| self.push_region_constraints(c));
342295

343296
normalized_inputs_and_output.push(norm_ty);

0 commit comments

Comments
 (0)