rustc_infer/infer/canonical/query_response.rs
1//! This module contains the code to instantiate a "query result", and
2//! in particular to extract out the resulting region obligations and
3//! encode them therein.
4//!
5//! For an overview of what canonicalization is and how it fits into
6//! rustc, check out the [chapter in the rustc dev guide][c].
7//!
8//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
9
10use std::fmt::Debug;
11use std::iter;
12
13use rustc_index::{Idx, IndexVec};
14use rustc_middle::arena::ArenaAllocatable;
15use rustc_middle::bug;
16use rustc_middle::mir::ConstraintCategory;
17use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable};
18use tracing::{debug, instrument};
19
20use crate::infer::canonical::instantiate::{CanonicalExt, instantiate_value};
21use crate::infer::canonical::{
22 Canonical, CanonicalQueryResponse, CanonicalVarValues, Certainty, OriginalQueryValues,
23 QueryRegionConstraints, QueryResponse,
24};
25use crate::infer::region_constraints::{Constraint, RegionConstraintData};
26use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult, SubregionOrigin};
27use crate::traits::query::NoSolution;
28use crate::traits::{ObligationCause, PredicateObligations, ScrubbedTraitError, TraitEngine};
29
30impl<'tcx> InferCtxt<'tcx> {
31 /// This method is meant to be invoked as the final step of a canonical query
32 /// implementation. It is given:
33 ///
34 /// - the instantiated variables `inference_vars` created from the query key
35 /// - the result `answer` of the query
36 /// - a fulfillment context `fulfill_cx` that may contain various obligations which
37 /// have yet to be proven.
38 ///
39 /// Given this, the function will process the obligations pending
40 /// in `fulfill_cx`:
41 ///
42 /// - If all the obligations can be proven successfully, it will
43 /// package up any resulting region obligations (extracted from
44 /// `infcx`) along with the fully resolved value `answer` into a
45 /// query result (which is then itself canonicalized).
46 /// - If some obligations can be neither proven nor disproven, then
47 /// the same thing happens, but the resulting query is marked as ambiguous.
48 /// - Finally, if any of the obligations result in a hard error,
49 /// then `Err(NoSolution)` is returned.
50 #[instrument(skip(self, inference_vars, answer, fulfill_cx), level = "trace")]
51 pub fn make_canonicalized_query_response<T>(
52 &self,
53 inference_vars: CanonicalVarValues<'tcx>,
54 answer: T,
55 fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
56 ) -> Result<CanonicalQueryResponse<'tcx, T>, NoSolution>
57 where
58 T: Debug + TypeFoldable<TyCtxt<'tcx>>,
59 Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
60 {
61 let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
62 debug!("query_response = {:#?}", query_response);
63 let canonical_result = self.canonicalize_response(query_response);
64 debug!("canonical_result = {:#?}", canonical_result);
65
66 Ok(self.tcx.arena.alloc(canonical_result))
67 }
68
69 /// A version of `make_canonicalized_query_response` that does
70 /// not pack in obligations, for contexts that want to drop
71 /// pending obligations instead of treating them as an ambiguity (e.g.
72 /// typeck "probing" contexts).
73 ///
74 /// If you DO want to keep track of pending obligations (which
75 /// include all region obligations, so this includes all cases
76 /// that care about regions) with this function, you have to
77 /// do it yourself, by e.g., having them be a part of the answer.
78 pub fn make_query_response_ignoring_pending_obligations<T>(
79 &self,
80 inference_vars: CanonicalVarValues<'tcx>,
81 answer: T,
82 ) -> Canonical<'tcx, QueryResponse<'tcx, T>>
83 where
84 T: Debug + TypeFoldable<TyCtxt<'tcx>>,
85 {
86 self.canonicalize_response(QueryResponse {
87 var_values: inference_vars,
88 region_constraints: QueryRegionConstraints::default(),
89 certainty: Certainty::Proven, // Ambiguities are OK!
90 opaque_types: vec![],
91 value: answer,
92 })
93 }
94
95 /// Helper for `make_canonicalized_query_response` that does
96 /// everything up until the final canonicalization.
97 #[instrument(skip(self, fulfill_cx), level = "debug")]
98 fn make_query_response<T>(
99 &self,
100 inference_vars: CanonicalVarValues<'tcx>,
101 answer: T,
102 fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
103 ) -> Result<QueryResponse<'tcx, T>, NoSolution>
104 where
105 T: Debug + TypeFoldable<TyCtxt<'tcx>>,
106 {
107 let tcx = self.tcx;
108
109 // Select everything, returning errors.
110 let errors = fulfill_cx.select_all_or_error(self);
111
112 // True error!
113 if errors.iter().any(|e| e.is_true_error()) {
114 return Err(NoSolution);
115 }
116
117 let region_obligations = self.take_registered_region_obligations();
118 debug!(?region_obligations);
119 let region_constraints = self.with_region_constraints(|region_constraints| {
120 make_query_region_constraints(
121 tcx,
122 region_obligations
123 .iter()
124 .map(|r_o| (r_o.sup_type, r_o.sub_region, r_o.origin.to_constraint_category())),
125 region_constraints,
126 )
127 });
128 debug!(?region_constraints);
129
130 let certainty = if errors.is_empty() { Certainty::Proven } else { Certainty::Ambiguous };
131
132 let opaque_types = self
133 .inner
134 .borrow_mut()
135 .opaque_type_storage
136 .take_opaque_types()
137 .map(|(k, v)| (k, v.ty))
138 .collect();
139
140 Ok(QueryResponse {
141 var_values: inference_vars,
142 region_constraints,
143 certainty,
144 value: answer,
145 opaque_types,
146 })
147 }
148
149 /// Given the (canonicalized) result to a canonical query,
150 /// instantiates the result so it can be used, plugging in the
151 /// values from the canonical query. (Note that the result may
152 /// have been ambiguous; you should check the certainty level of
153 /// the query before applying this function.)
154 ///
155 /// To get a good understanding of what is happening here, check
156 /// out the [chapter in the rustc dev guide][c].
157 ///
158 /// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#processing-the-canonicalized-query-result
159 pub fn instantiate_query_response_and_region_obligations<R>(
160 &self,
161 cause: &ObligationCause<'tcx>,
162 param_env: ty::ParamEnv<'tcx>,
163 original_values: &OriginalQueryValues<'tcx>,
164 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
165 ) -> InferResult<'tcx, R>
166 where
167 R: Debug + TypeFoldable<TyCtxt<'tcx>>,
168 {
169 let InferOk { value: result_args, obligations } =
170 self.query_response_instantiation(cause, param_env, original_values, query_response)?;
171
172 for (predicate, _category) in &query_response.value.region_constraints.outlives {
173 let predicate = instantiate_value(self.tcx, &result_args, *predicate);
174 self.register_outlives_constraint(predicate, cause);
175 }
176
177 let user_result: R =
178 query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());
179
180 Ok(InferOk { value: user_result, obligations })
181 }
182
183 /// An alternative to
184 /// `instantiate_query_response_and_region_obligations` that is more
185 /// efficient for NLL. NLL is a bit more advanced in the
186 /// "transition to chalk" than the rest of the compiler. During
187 /// the NLL type check, all of the "processing" of types and
188 /// things happens in queries -- the NLL checker itself is only
189 /// interested in the region obligations (`'a: 'b` or `T: 'b`)
190 /// that come out of these queries, which it wants to convert into
191 /// MIR-based constraints and solve. Therefore, it is most
192 /// convenient for the NLL Type Checker to **directly consume**
193 /// the `QueryOutlivesConstraint` values that arise from doing a
194 /// query. This is contrast to other parts of the compiler, which
195 /// would prefer for those `QueryOutlivesConstraint` to be converted
196 /// into the older infcx-style constraints (e.g., calls to
197 /// `sub_regions` or `register_region_obligation`).
198 ///
199 /// Therefore, `instantiate_nll_query_response_and_region_obligations` performs the same
200 /// basic operations as `instantiate_query_response_and_region_obligations` but
201 /// it returns its result differently:
202 ///
203 /// - It creates an instantiation `S` that maps from the original
204 /// query variables to the values computed in the query
205 /// result. If any errors arise, they are propagated back as an
206 /// `Err` result.
207 /// - In the case of a successful instantiation, we will append
208 /// `QueryOutlivesConstraint` values onto the
209 /// `output_query_region_constraints` vector for the solver to
210 /// use (if an error arises, some values may also be pushed, but
211 /// they should be ignored).
212 /// - It **can happen** (though it rarely does currently) that
213 /// equating types and things will give rise to subobligations
214 /// that must be processed. In this case, those subobligations
215 /// are propagated back in the return value.
216 /// - Finally, the query result (of type `R`) is propagated back,
217 /// after applying the instantiation `S`.
218 pub fn instantiate_nll_query_response_and_region_obligations<R>(
219 &self,
220 cause: &ObligationCause<'tcx>,
221 param_env: ty::ParamEnv<'tcx>,
222 original_values: &OriginalQueryValues<'tcx>,
223 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
224 output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
225 ) -> InferResult<'tcx, R>
226 where
227 R: Debug + TypeFoldable<TyCtxt<'tcx>>,
228 {
229 let InferOk { value: result_args, mut obligations } = self
230 .query_response_instantiation_guess(
231 cause,
232 param_env,
233 original_values,
234 query_response,
235 )?;
236
237 // Compute `QueryOutlivesConstraint` values that unify each of
238 // the original values `v_o` that was canonicalized into a
239 // variable...
240
241 let constraint_category = cause.to_constraint_category();
242
243 for (index, original_value) in original_values.var_values.iter().enumerate() {
244 // ...with the value `v_r` of that variable from the query.
245 let result_value = query_response.instantiate_projected(self.tcx, &result_args, |v| {
246 v.var_values[BoundVar::new(index)]
247 });
248 match (original_value.kind(), result_value.kind()) {
249 (GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
250 if re1.is_erased() && re2.is_erased() =>
251 {
252 // No action needed.
253 }
254
255 (GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
256 // To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
257 if v_o != v_r {
258 output_query_region_constraints
259 .outlives
260 .push((ty::OutlivesPredicate(v_o.into(), v_r), constraint_category));
261 output_query_region_constraints
262 .outlives
263 .push((ty::OutlivesPredicate(v_r.into(), v_o), constraint_category));
264 }
265 }
266
267 (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
268 obligations.extend(
269 self.at(&cause, param_env)
270 .eq(DefineOpaqueTypes::Yes, v1, v2)?
271 .into_obligations(),
272 );
273 }
274
275 (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
276 obligations.extend(
277 self.at(&cause, param_env)
278 .eq(DefineOpaqueTypes::Yes, v1, v2)?
279 .into_obligations(),
280 );
281 }
282
283 _ => {
284 bug!("kind mismatch, cannot unify {:?} and {:?}", original_value, result_value);
285 }
286 }
287 }
288
289 // ...also include the other query region constraints from the query.
290 output_query_region_constraints.outlives.extend(
291 query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| {
292 let r_c = instantiate_value(self.tcx, &result_args, r_c);
293
294 // Screen out `'a: 'a` cases.
295 let ty::OutlivesPredicate(k1, r2) = r_c.0;
296 if k1 != r2.into() { Some(r_c) } else { None }
297 }),
298 );
299
300 let user_result: R =
301 query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());
302
303 Ok(InferOk { value: user_result, obligations })
304 }
305
306 /// Given the original values and the (canonicalized) result from
307 /// computing a query, returns an instantiation that can be applied
308 /// to the query result to convert the result back into the
309 /// original namespace.
310 ///
311 /// The instantiation also comes accompanied with subobligations
312 /// that arose from unification; these might occur if (for
313 /// example) we are doing lazy normalization and the value
314 /// assigned to a type variable is unified with an unnormalized
315 /// projection.
316 fn query_response_instantiation<R>(
317 &self,
318 cause: &ObligationCause<'tcx>,
319 param_env: ty::ParamEnv<'tcx>,
320 original_values: &OriginalQueryValues<'tcx>,
321 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
322 ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
323 where
324 R: Debug + TypeFoldable<TyCtxt<'tcx>>,
325 {
326 debug!(
327 "query_response_instantiation(original_values={:#?}, query_response={:#?})",
328 original_values, query_response,
329 );
330
331 let mut value = self.query_response_instantiation_guess(
332 cause,
333 param_env,
334 original_values,
335 query_response,
336 )?;
337
338 value.obligations.extend(
339 self.unify_query_response_instantiation_guess(
340 cause,
341 param_env,
342 original_values,
343 &value.value,
344 query_response,
345 )?
346 .into_obligations(),
347 );
348
349 Ok(value)
350 }
351
352 /// Given the original values and the (canonicalized) result from
353 /// computing a query, returns a **guess** at an instantiation that
354 /// can be applied to the query result to convert the result back
355 /// into the original namespace. This is called a **guess**
356 /// because it uses a quick heuristic to find the values for each
357 /// canonical variable; if that quick heuristic fails, then we
358 /// will instantiate fresh inference variables for each canonical
359 /// variable instead. Therefore, the result of this method must be
360 /// properly unified
361 #[instrument(level = "debug", skip(self, param_env))]
362 fn query_response_instantiation_guess<R>(
363 &self,
364 cause: &ObligationCause<'tcx>,
365 param_env: ty::ParamEnv<'tcx>,
366 original_values: &OriginalQueryValues<'tcx>,
367 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
368 ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
369 where
370 R: Debug + TypeFoldable<TyCtxt<'tcx>>,
371 {
372 // For each new universe created in the query result that did
373 // not appear in the original query, create a local
374 // superuniverse.
375 let mut universe_map = original_values.universe_map.clone();
376 let num_universes_in_query = original_values.universe_map.len();
377 let num_universes_in_response = query_response.max_universe.as_usize() + 1;
378 for _ in num_universes_in_query..num_universes_in_response {
379 universe_map.push(self.create_next_universe());
380 }
381 assert!(!universe_map.is_empty()); // always have the root universe
382 assert_eq!(universe_map[ty::UniverseIndex::ROOT.as_usize()], ty::UniverseIndex::ROOT);
383
384 // Every canonical query result includes values for each of
385 // the inputs to the query. Therefore, we begin by unifying
386 // these values with the original inputs that were
387 // canonicalized.
388 let result_values = &query_response.value.var_values;
389 assert_eq!(original_values.var_values.len(), result_values.len());
390
391 // Quickly try to find initial values for the canonical
392 // variables in the result in terms of the query. We do this
393 // by iterating down the values that the query gave to each of
394 // the canonical inputs. If we find that one of those values
395 // is directly equal to one of the canonical variables in the
396 // result, then we can type the corresponding value from the
397 // input. See the example above.
398 let mut opt_values: IndexVec<BoundVar, Option<GenericArg<'tcx>>> =
399 IndexVec::from_elem_n(None, query_response.variables.len());
400
401 // In terms of our example above, we are iterating over pairs like:
402 // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
403 for (original_value, result_value) in iter::zip(&original_values.var_values, result_values)
404 {
405 match result_value.kind() {
406 GenericArgKind::Type(result_value) => {
407 // e.g., here `result_value` might be `?0` in the example above...
408 if let ty::Bound(debruijn, b) = *result_value.kind() {
409 // ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
410
411 // We only allow a `ty::INNERMOST` index in generic parameters.
412 assert_eq!(debruijn, ty::INNERMOST);
413 opt_values[b.var] = Some(*original_value);
414 }
415 }
416 GenericArgKind::Lifetime(result_value) => {
417 // e.g., here `result_value` might be `'?1` in the example above...
418 if let ty::ReBound(debruijn, br) = result_value.kind() {
419 // ... in which case we would set `canonical_vars[0]` to `Some('static)`.
420
421 // We only allow a `ty::INNERMOST` index in generic parameters.
422 assert_eq!(debruijn, ty::INNERMOST);
423 opt_values[br.var] = Some(*original_value);
424 }
425 }
426 GenericArgKind::Const(result_value) => {
427 if let ty::ConstKind::Bound(debruijn, b) = result_value.kind() {
428 // ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
429
430 // We only allow a `ty::INNERMOST` index in generic parameters.
431 assert_eq!(debruijn, ty::INNERMOST);
432 opt_values[b] = Some(*original_value);
433 }
434 }
435 }
436 }
437
438 // Create result arguments: if we found a value for a
439 // given variable in the loop above, use that. Otherwise, use
440 // a fresh inference variable.
441 let result_args = CanonicalVarValues {
442 var_values: self.tcx.mk_args_from_iter(
443 query_response.variables.iter().enumerate().map(|(index, var_kind)| {
444 if var_kind.universe() != ty::UniverseIndex::ROOT {
445 // A variable from inside a binder of the query. While ideally these shouldn't
446 // exist at all, we have to deal with them for now.
447 self.instantiate_canonical_var(cause.span, var_kind, |u| {
448 universe_map[u.as_usize()]
449 })
450 } else if var_kind.is_existential() {
451 match opt_values[BoundVar::new(index)] {
452 Some(k) => k,
453 None => self.instantiate_canonical_var(cause.span, var_kind, |u| {
454 universe_map[u.as_usize()]
455 }),
456 }
457 } else {
458 // For placeholders which were already part of the input, we simply map this
459 // universal bound variable back the placeholder of the input.
460 opt_values[BoundVar::new(index)].expect(
461 "expected placeholder to be unified with itself during response",
462 )
463 }
464 }),
465 ),
466 };
467
468 let mut obligations = PredicateObligations::new();
469
470 // Carry all newly resolved opaque types to the caller's scope
471 for &(a, b) in &query_response.value.opaque_types {
472 let a = instantiate_value(self.tcx, &result_args, a);
473 let b = instantiate_value(self.tcx, &result_args, b);
474 debug!(?a, ?b, "constrain opaque type");
475 // We use equate here instead of, for example, just registering the
476 // opaque type's hidden value directly, because the hidden type may have been an inference
477 // variable that got constrained to the opaque type itself. In that case we want to equate
478 // the generic args of the opaque with the generic params of its hidden type version.
479 obligations.extend(
480 self.at(cause, param_env)
481 .eq(
482 DefineOpaqueTypes::Yes,
483 Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.args),
484 b,
485 )?
486 .obligations,
487 );
488 }
489
490 Ok(InferOk { value: result_args, obligations })
491 }
492
493 /// Given a "guess" at the values for the canonical variables in
494 /// the input, try to unify with the *actual* values found in the
495 /// query result. Often, but not always, this is a no-op, because
496 /// we already found the mapping in the "guessing" step.
497 ///
498 /// See also: [`Self::query_response_instantiation_guess`]
499 fn unify_query_response_instantiation_guess<R>(
500 &self,
501 cause: &ObligationCause<'tcx>,
502 param_env: ty::ParamEnv<'tcx>,
503 original_values: &OriginalQueryValues<'tcx>,
504 result_args: &CanonicalVarValues<'tcx>,
505 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
506 ) -> InferResult<'tcx, ()>
507 where
508 R: Debug + TypeFoldable<TyCtxt<'tcx>>,
509 {
510 // A closure that yields the result value for the given
511 // canonical variable; this is taken from
512 // `query_response.var_values` after applying the instantiation
513 // by `result_args`.
514 let instantiated_query_response = |index: BoundVar| -> GenericArg<'tcx> {
515 query_response.instantiate_projected(self.tcx, result_args, |v| v.var_values[index])
516 };
517
518 // Unify the original value for each variable with the value
519 // taken from `query_response` (after applying `result_args`).
520 self.unify_canonical_vars(cause, param_env, original_values, instantiated_query_response)
521 }
522
523 /// Given two sets of values for the same set of canonical variables, unify them.
524 /// The second set is produced lazily by supplying indices from the first set.
525 fn unify_canonical_vars(
526 &self,
527 cause: &ObligationCause<'tcx>,
528 param_env: ty::ParamEnv<'tcx>,
529 variables1: &OriginalQueryValues<'tcx>,
530 variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
531 ) -> InferResult<'tcx, ()> {
532 let mut obligations = PredicateObligations::new();
533 for (index, value1) in variables1.var_values.iter().enumerate() {
534 let value2 = variables2(BoundVar::new(index));
535
536 match (value1.kind(), value2.kind()) {
537 (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
538 obligations.extend(
539 self.at(cause, param_env)
540 .eq(DefineOpaqueTypes::Yes, v1, v2)?
541 .into_obligations(),
542 );
543 }
544 (GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
545 if re1.is_erased() && re2.is_erased() =>
546 {
547 // no action needed
548 }
549 (GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
550 self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
551 SubregionOrigin::RelateRegionParamBound(cause.span, None),
552 v1,
553 v2,
554 );
555 }
556 (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
557 let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
558 obligations.extend(ok.into_obligations());
559 }
560 _ => {
561 bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
562 }
563 }
564 }
565 Ok(InferOk { value: (), obligations })
566 }
567}
568
569/// Given the region obligations and constraints scraped from the infcx,
570/// creates query region constraints.
571pub fn make_query_region_constraints<'tcx>(
572 tcx: TyCtxt<'tcx>,
573 outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>, ConstraintCategory<'tcx>)>,
574 region_constraints: &RegionConstraintData<'tcx>,
575) -> QueryRegionConstraints<'tcx> {
576 let RegionConstraintData { constraints, verifys } = region_constraints;
577
578 assert!(verifys.is_empty());
579
580 debug!(?constraints);
581
582 let outlives: Vec<_> = constraints
583 .iter()
584 .map(|(k, origin)| {
585 let constraint = match *k {
586 // Swap regions because we are going from sub (<=) to outlives
587 // (>=).
588 Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
589 ty::Region::new_var(tcx, v2).into(),
590 ty::Region::new_var(tcx, v1),
591 ),
592 Constraint::VarSubReg(v1, r2) => {
593 ty::OutlivesPredicate(r2.into(), ty::Region::new_var(tcx, v1))
594 }
595 Constraint::RegSubVar(r1, v2) => {
596 ty::OutlivesPredicate(ty::Region::new_var(tcx, v2).into(), r1)
597 }
598 Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
599 };
600 (constraint, origin.to_constraint_category())
601 })
602 .chain(outlives_obligations.map(|(ty, r, constraint_category)| {
603 (ty::OutlivesPredicate(ty.into(), r), constraint_category)
604 }))
605 .collect();
606
607 QueryRegionConstraints { outlives }
608}