1//! The bulk of the logic for implementing `-Zassumptions-on-binders`
23use derive_where::derive_where;
4use indexmap::IndexSet;
5#[cfg(feature = "nightly")]
6use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
7#[cfg(feature = "nightly")]
8use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder};
9use tracing::{debug, instrument};
1011// Workaround for TransitiveRelation being in rustc_data_structures which isn't accessible on stable
12#[cfg(not(feature = "nightly"))]
13#[derive(Default, Clone, Debug)]
14pub struct TransitiveRelation<T>(T);
15#[cfg(not(feature = "nightly"))]
16impl<T> TransitiveRelation<T> {
17pub fn reachable_from(&self, _data: T) -> Vec<T> {
18unreachable!("-Zassumptions-on-binders is not supported for r-a")
19 }
2021pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> {
22unreachable!("-Zassumptions-on-binders is not supported for r-a");
2324#[allow(unreachable_code)]
25[].into_iter()
26 }
27}
28#[derive(Clone, Debug)]
29#[cfg(not(feature = "nightly"))]
30pub struct TransitiveRelationBuilder<T>(T);
31#[cfg(not(feature = "nightly"))]
32impl<T> TransitiveRelationBuilder<T> {
33pub fn freeze(self) -> TransitiveRelation<T> {
34unreachable!("-Zassumptions-on-binders is not supported for r-a")
35 }
3637pub fn add(&mut self, _: T, _: T) {
38unreachable!("-Zassumptions-on-binders is not supported for r-a")
39 }
40}
41#[cfg(not(feature = "nightly"))]
42impl<T> Default for TransitiveRelationBuilder<T> {
43fn default() -> Self {
44unreachable!("-Zassumptions-on-binders is not supported for r-a")
45 }
46}
4748use crate::data_structures::IndexMap;
49use crate::fold::TypeSuperFoldable;
50use crate::inherent::*;
51use crate::relate::{Relate, RelateResult, TypeRelation, VarianceDiagInfo};
52use crate::{
53AliasTy, Binder, BoundRegion, BoundVar, BoundVariableKind, DebruijnIndex, FallibleTypeFolder,
54GenericTypeVisitable, InferCtxtLike, Interner, IsRigid, OutlivesClause, Region, RegionKind,
55TyKind, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, TypingMode, UniverseIndex,
56Variance, VisitorResult, max_universe, set_aliases_to_non_rigid, try_visit,
57walk_visitable_list,
58};
5960#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for Assumptions<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
Assumptions {
type_outlives: ref __field_type_outlives,
region_outlives: ref __field_region_outlives,
inverse_region_outlives: ref __field_inverse_region_outlives }
=> {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "Assumptions");
::core::fmt::DebugStruct::field(&mut __builder,
"type_outlives", __field_type_outlives);
::core::fmt::DebugStruct::field(&mut __builder,
"region_outlives", __field_region_outlives);
::core::fmt::DebugStruct::field(&mut __builder,
"inverse_region_outlives", __field_inverse_region_outlives);
::core::fmt::DebugStruct::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Debug; I: Interner)]61pub struct Assumptions<I: Interner> {
62pub type_outlives: Vec<Binder<I, OutlivesClause<I, I::Ty>>>,
63pub region_outlives: TransitiveRelation<Region<I>>,
64pub inverse_region_outlives: TransitiveRelation<Region<I>>,
65}
6667impl<I: Interner> Assumptions<I> {
68pub fn empty() -> Self {
69Self {
70 type_outlives: Vec::new(),
71 region_outlives: TransitiveRelationBuilder::default().freeze(),
72 inverse_region_outlives: TransitiveRelationBuilder::default().freeze(),
73 }
74 }
7576pub fn new(
77 type_outlives: Vec<Binder<I, OutlivesClause<I, I::Ty>>>,
78 region_outlives: TransitiveRelation<Region<I>>,
79 ) -> Self {
80Self {
81 inverse_region_outlives: {
82let mut builder = TransitiveRelationBuilder::default();
83for (r1, r2) in region_outlives.base_edges() {
84 builder.add(r2, r1);
85 }
86builder.freeze()
87 },
88type_outlives,
89region_outlives,
90 }
91 }
92}
9394#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for RegionConstraint<I> where I: Interner
{
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
RegionConstraint::Ambiguity =>
::core::fmt::Formatter::write_str(__f, "Ambiguity"),
RegionConstraint::RegionOutlives(ref __field_0, ref __field_1) =>
{
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "RegionOutlives");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
::core::fmt::DebugTuple::finish(&mut __builder)
}
RegionConstraint::AliasTyOutlivesViaEnv(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"AliasTyOutlivesViaEnv");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
RegionConstraint::PlaceholderTyOutlives(ref __field_0,
ref __field_1) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"PlaceholderTyOutlives");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
::core::fmt::DebugTuple::finish(&mut __builder)
}
RegionConstraint::And(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "And");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
RegionConstraint::Or(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Or");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner)]95#[derive(GenericTypeVisitable)]
96pub enum RegionConstraint<I: Interner> {
97 Ambiguity,
98 RegionOutlives(Region<I>, Region<I>),
99/// Requirement that a (potentially higher ranked) alias outlives some (potentially higher ranked)
100 /// region due to an assumption in the environment. This cannot be satisfied via component outlives
101 /// or item bounds.
102 ///
103 /// We cannot eagerly look at assumptions as we are usually working with an incomplete set of assumptions
104 /// and there may wind up being assumptions we can use to prove this when we're in a smaller universe.
105 ///
106 /// We eagerly destructure alias outlives requirements into region outlives requirements corresponding to
107 /// component outlives & item bound outlives rules, leaving only param env candidates.
108AliasTyOutlivesViaEnv(Binder<I, (AliasTy<I>, Region<I>)>),
109/// This is an `I::Ty` for two reasons:
110 /// 1. We need the type visitable impl to be able to `visit_ty` on this so canonicalization
111 /// knows about the placeholder
112 /// 2. When exiting the trait solver there may be placeholder outlives corresponding to params
113 /// from the root universe. These need to be changed from a `Placeholder` to the original
114 /// `Param`.
115 ///
116 /// We cannot eagerly look at assumptions as we are usually working with an incomplete set of assumptions
117 /// and there may wind up being assumptions we can use to prove this when we're in a smaller universe.
118PlaceholderTyOutlives(I::Ty, Region<I>),
119120 And(Box<[RegionConstraint<I>]>),
121 Or(Box<[RegionConstraint<I>]>),
122}
123124// This is not a derived impl because a perfect derive leads to inductive
125// cycle causing the trait to never actually be implemented.
126#[cfg(feature = "nightly")]
127impl<I: Interner> StableHashfor RegionConstraint<I>
128where
129Region<I>: StableHash,
130 I::Ty: StableHash,
131 I::GenericArgs: StableHash,
132 I::TraitAssocTyId: StableHash,
133 I::InherentAssocTyId: StableHash,
134 I::OpaqueTyId: StableHash,
135 I::FreeTyAliasId: StableHash,
136 I::BoundVarKinds: StableHash,
137{
138#[inline]
139fn stable_hash<CTX: StableHashCtxt>(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
140use RegionConstraint::*;
141142 std::mem::discriminant(self).stable_hash(hcx, hasher);
143match self {
144Ambiguity => (),
145RegionOutlives(a, b) => {
146a.stable_hash(hcx, hasher);
147b.stable_hash(hcx, hasher);
148 }
149AliasTyOutlivesViaEnv(outlives) => {
150outlives.stable_hash(hcx, hasher);
151 }
152PlaceholderTyOutlives(a, b) => {
153a.stable_hash(hcx, hasher);
154b.stable_hash(hcx, hasher);
155 }
156And(and) => {
157for a in and.iter() {
158 a.stable_hash(hcx, hasher);
159 }
160 }
161Or(or) => {
162for a in or.iter() {
163 a.stable_hash(hcx, hasher);
164 }
165 }
166 }
167 }
168}
169170impl<I: Interner> TypeFoldable<I> for RegionConstraint<I> {
171fn try_fold_with<F: FallibleTypeFolder<I>>(self, f: &mut F) -> Result<Self, F::Error> {
172use RegionConstraint::*;
173Ok(match self {
174Ambiguity => self,
175RegionOutlives(a, b) => RegionOutlives(a.try_fold_with(f)?, b.try_fold_with(f)?),
176AliasTyOutlivesViaEnv(outlives) => AliasTyOutlivesViaEnv(outlives.try_fold_with(f)?),
177PlaceholderTyOutlives(a, b) => {
178PlaceholderTyOutlives(a.try_fold_with(f)?, b.try_fold_with(f)?)
179 }
180And(and) => {
181let mut new_and = Vec::new();
182for a in and {
183 new_and.push(a.try_fold_with(f)?);
184 }
185And(new_and.into_boxed_slice())
186 }
187Or(or) => {
188let mut new_or = Vec::new();
189for a in or {
190 new_or.push(a.try_fold_with(f)?);
191 }
192Or(new_or.into_boxed_slice())
193 }
194 })
195 }
196197fn fold_with<F: TypeFolder<I>>(self, f: &mut F) -> Self {
198use RegionConstraint::*;
199match self {
200Ambiguity => self,
201RegionOutlives(a, b) => RegionOutlives(a.fold_with(f), b.fold_with(f)),
202AliasTyOutlivesViaEnv(outlives) => AliasTyOutlivesViaEnv(outlives.fold_with(f)),
203PlaceholderTyOutlives(a, b) => PlaceholderTyOutlives(a.fold_with(f), b.fold_with(f)),
204And(and) => {
205let mut new_and = Vec::new();
206for a in and {
207 new_and.push(a.fold_with(f));
208 }
209And(new_and.into_boxed_slice())
210 }
211Or(or) => {
212let mut new_or = Vec::new();
213for a in or {
214 new_or.push(a.fold_with(f));
215 }
216Or(new_or.into_boxed_slice())
217 }
218 }
219 }
220}
221222impl<I: Interner> TypeVisitable<I> for RegionConstraint<I> {
223fn visit_with<F: TypeVisitor<I>>(&self, f: &mut F) -> F::Result {
224use RegionConstraint::*;
225226match self {
227Ambiguity => (),
228RegionOutlives(a, b) => {
229match ::rustc_ast_ir::visit::VisitorResult::branch(a.visit_with(f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(a.visit_with(f));
230match ::rustc_ast_ir::visit::VisitorResult::branch(b.visit_with(f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(b.visit_with(f));
231 }
232AliasTyOutlivesViaEnv(outlives) => {
233match ::rustc_ast_ir::visit::VisitorResult::branch(outlives.visit_with(f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(outlives.visit_with(f));
234 }
235PlaceholderTyOutlives(a, b) => {
236match ::rustc_ast_ir::visit::VisitorResult::branch(a.visit_with(f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(a.visit_with(f));
237match ::rustc_ast_ir::visit::VisitorResult::branch(b.visit_with(f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(b.visit_with(f));
238 }
239And(and) => {
240for elem in and {
match ::rustc_ast_ir::visit::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(elem,
f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_visitable_list!(f, and);
241 }
242Or(or) => {
243for elem in or {
match ::rustc_ast_ir::visit::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(elem,
f)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_visitable_list!(f, or);
244 }
245 };
246247 F::Result::output()
248 }
249}
250251impl<I: Interner> Defaultfor RegionConstraint<I> {
252fn default() -> Self {
253Self::new_true()
254 }
255}
256257impl<I: Interner> RegionConstraint<I> {
258pub fn new_true() -> Self {
259 RegionConstraint::And(Box::new([]))
260 }
261262pub fn is_true(&self) -> bool {
263match self {
264Self::And(and) => and.is_empty(),
265_ => false,
266 }
267 }
268269pub fn new_false() -> Self {
270 RegionConstraint::Or(Box::new([]))
271 }
272273pub fn is_false(&self) -> bool {
274match self {
275Self::Or(or) => or.is_empty(),
276_ => false,
277 }
278 }
279280pub fn is_or(&self) -> bool {
281#[allow(non_exhaustive_omitted_patterns)] match self {
Self::Or(_) => true,
_ => false,
}matches!(self, Self::Or(_))282 }
283284pub fn unwrap_or(self) -> Box<[RegionConstraint<I>]> {
285match self {
286Self::Or(ors) => ors,
287_ => {
::core::panicking::panic_fmt(format_args!("`unwrap_or` on non-Or: {0:?}",
self));
}panic!("`unwrap_or` on non-Or: {self:?}"),
288 }
289 }
290291pub fn unwrap_and(self) -> Box<[RegionConstraint<I>]> {
292match self {
293Self::And(ands) => ands,
294_ => {
::core::panicking::panic_fmt(format_args!("`unwrap_and` on non-And: {0:?}",
self));
}panic!("`unwrap_and` on non-And: {self:?}"),
295 }
296 }
297298pub fn is_and(&self) -> bool {
299#[allow(non_exhaustive_omitted_patterns)] match self {
Self::And(_) => true,
_ => false,
}matches!(self, Self::And(_))300 }
301302pub fn is_ambig(&self) -> bool {
303#[allow(non_exhaustive_omitted_patterns)] match self {
Self::Ambiguity => true,
_ => false,
}matches!(self, Self::Ambiguity)304 }
305306pub fn and(self, other: RegionConstraint<I>) -> RegionConstraint<I> {
307use RegionConstraint::*;
308309match (self, other) {
310 (And(a_ands), And(b_ands)) => And(a_ands311 .into_iter()
312 .chain(b_ands.into_iter())
313 .collect::<Vec<_>>()
314 .into_boxed_slice()),
315 (And(ands), other) | (other, And(ands)) => {
316And(ands.into_iter().chain([other]).collect::<Vec<_>>().into_boxed_slice())
317 }
318 (this, other) => And(Box::new([this, other])),
319 }
320 }
321322/// Converts the region constraint into an ORs of ANDs of "leaf" constraints. Where
323 /// a leaf constraint is a non-or/and constraint.
324x;#[instrument(level = "debug", ret)]325pub fn canonical_form(self) -> Self {
326use RegionConstraint::*;
327328fn permutations<I: Interner>(
329 ors: &[Vec<RegionConstraint<I>>],
330 ) -> Vec<Vec<RegionConstraint<I>>> {
331match ors {
332 [] => vec![vec![]],
333 [or1] => {
334let mut choices = vec![];
335for choice in or1 {
336 choices.push(vec![choice.clone()]);
337 }
338 choices
339 }
340 [or1, rest_ors @ ..] => {
341let mut choices = vec![];
342for choice in or1 {
343 choices.extend(
344 permutations(rest_ors)
345 .into_iter()
346 .map(|and| std::iter::once(choice.clone()).chain(and).collect()),
347 );
348 }
349 choices
350 }
351 }
352 }
353354let canonical = match self {
355 And(ands) => {
356// AND of OR of AND of LEAFs
357 //
358 // We can turn `AND of OR of X` into `OR of AND of X` by enumerating every set of choices
359 // for the list of ORs. For example if we have `AND ( OR(A, B), OR(C, D) )` we can convert this into
360 // `OR ( AND (A, C), AND (A, D), AND (B, C), AND (B, D ))`
361 //
362 // if A/B/C/D are all in canonical forms then we wind up with an `OR of AND of AND of LEAFs` which
363 // is trivially canonicalizeable by flattening the multiple layers of AND into one.
364let ors = ands
365 .into_iter()
366 .map(|c| c.canonical_form().unwrap_or().to_vec())
367 .collect::<Vec<_>>();
368debug!(?ors);
369let or_permutations = permutations(&ors);
370debug!(?or_permutations);
371372 Or(or_permutations
373 .into_iter()
374 .map(|c| {
375 And(c
376 .into_iter()
377 .flat_map(|c2| c2.unwrap_and().into_iter())
378 .collect::<Vec<_>>()
379 .into_boxed_slice())
380 })
381 .collect::<Vec<_>>()
382 .into_boxed_slice())
383 }
384 Or(ors) => {
385// OR of OR of AND of LEAFs
386 //
387 // trivially canonicalizeable by concatenating all of the ORs into one big OR
388Or(ors
389 .into_iter()
390 .flat_map(|c| c.canonical_form().unwrap_or().into_iter())
391 .collect::<Vec<_>>()
392 .into_boxed_slice())
393 }
394_ => Or(Box::new([And(Box::new([self]))])),
395 };
396397assert!(
398 canonical.is_canonical_form(),
399"non canonical form region constraint: {:?}",
400 canonical
401 );
402 canonical
403 }
404405fn is_leaf_constraint(&self) -> bool {
406use RegionConstraint::*;
407match self {
408Ambiguity409 | RegionOutlives(..)
410 | AliasTyOutlivesViaEnv(..)
411 | PlaceholderTyOutlives(..) => true,
412And(..) | Or(..) => false,
413 }
414 }
415416fn is_canonical_and(&self) -> bool {
417if let Self::And(ands) = self { ands.iter().all(|c| c.is_leaf_constraint()) } else { false }
418 }
419420pub fn is_canonical_form(&self) -> bool {
421if let Self::Or(ors) = self { ors.iter().all(|c| c.is_canonical_and()) } else { false }
422 }
423}
424425/// Takes any constraints involving placeholders from the current universe and eagerly checks them.
426/// This can be done a few ways:
427/// - There's an assumption on the binder introducing the placeholder which means the constraint is satisfied (true)
428/// - There's assumptions on the binder introducing the placeholder which allow us to rewrite the constraint in
429/// terms of lower universe variables. For example given `for<'a> where('b: 'a) { prove(T: '!a_u1) }` we can
430/// convert this constraint to `T: 'b` which no longer references anything from `u1`.
431/// - There are no relevant assumptions so we can neither rewrite the constraint nor consider it satisfied (false)
432/// - We failed to compute the full set of assumptions when entering the binder corresponding to `u`. (ambiguity)
433///
434/// After handling all of the region constraints in `u` we then evaluate the entire constraint as much as possible,
435/// propagating true/false/ambiguity as close to the root of the constraint as we can. The returned constraint should
436/// be checked for whether it is true/false/ambiguous as that should affect the result of whatever operation required
437/// entering the binder corresponding to `u`.
438x;#[instrument(level = "debug", skip(infcx), ret)]439pub fn eagerly_handle_placeholders_in_universe<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
440 infcx: &Infcx,
441 constraint: RegionConstraint<I>,
442 u: UniverseIndex,
443) -> RegionConstraint<I> {
444use RegionConstraint::*;
445446let assumptions = infcx.get_placeholder_assumptions(u);
447448// 1. rewrite type outlives constraints involving things from `u` into either region constraints
449 // involving things from `u` or type outlives constraints not involving things from `u`
450 //
451 // IOW, we only want to encounter things from `u` as part of region out lives constraints.
452let constraint = rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling(
453 infcx,
454 constraint,
455 u,
456&assumptions,
457 );
458459// 2. rewrite the constraint into a canonical ORs of ANDs form
460let constraint = constraint.canonical_form();
461462// 3. compute transitive region outlives and get a new set of region outlives constraints by
463 // looking for every region which either a placeholder_u flows into it, or it flows into
464 // the placeholder.
465 //
466 // do this for each element in the top level OR
467let constraint = Or(constraint
468 .unwrap_or()
469 .into_iter()
470 .map(|c| {
471let and =
472 And(compute_new_region_constraints(infcx, &c.unwrap_and(), u).into_boxed_slice());
473474// 4. rewrite region outlives constraints (potentially to false/true)
475pull_region_outlives_constraints_out_of_universe(infcx, and, u, &assumptions)
476 })
477 .collect::<Vec<_>>()
478 .into_boxed_slice());
479480// 5. actually evaluate the constraint to eagerly error on false
481evaluate_solver_constraint(&constraint)
482}
483484/// Filter our region constraints to not include constraints between region variables from `u` and
485/// other regions as those are always satisfied. This requires some care to handle correctly for example:
486/// `'!a_u1: '?x_u1: '!b_u1` should result in us requiring `'!a_u1: '!b_u1` rather than dropping the two
487/// constraints entirely.
488///
489/// The only constraints involving things from `u` should be region outlives constraints at this point. Type
490/// outlives constraints should have been handled already either by destructuring into region outlives or by
491/// being rewritten in terms of smaller universe variables.
492x;#[instrument(level = "debug", skip(infcx), ret)]493fn compute_new_region_constraints<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
494 infcx: &Infcx,
495 constraints: &[RegionConstraint<I>],
496 u: UniverseIndex,
497) -> Vec<RegionConstraint<I>> {
498use RegionConstraint::*;
499500let mut new_constraints = vec![];
501502let mut region_flows_builder = TransitiveRelationBuilder::default();
503let mut regions = IndexSet::new();
504for c in constraints {
505match c {
506 And(..) | Or(..) => unreachable!(),
507 Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
508 new_constraints.push(c.clone())
509 }
510 RegionOutlives(r1, r2) => {
511 regions.insert(r1);
512 regions.insert(r2);
513 region_flows_builder.add(r2, r1);
514 }
515 }
516 }
517518let region_flow = region_flows_builder.freeze();
519for r in regions.into_iter() {
520for ub in region_flow.reachable_from(r) {
521// we want to retain any region constraints between two "placeholder-likes" where for our
522 // purposes a placeholder-like is either a placeholder or variable in a lower universe
523let is_placeholder_like = |r: Region<I>| match r.kind() {
524 RegionKind::ReLateParam(..)
525 | RegionKind::ReEarlyParam(..)
526 | RegionKind::RePlaceholder(..)
527 | RegionKind::ReStatic => true,
528 RegionKind::ReVar(..) => max_universe(infcx, r) < u,
529 RegionKind::ReError(..) => false,
530 RegionKind::ReErased | RegionKind::ReBound(..) => unreachable!(),
531 };
532533if is_placeholder_like(*r) && is_placeholder_like(*ub) {
534 new_constraints.push(RegionOutlives(*ub, *r));
535 }
536 }
537 }
538539 new_constraints
540}
541542/// Evaluate ANDs and ORs to true/false/ambiguous based on whether their arguments are true/false/ambiguous
543x;#[instrument(level = "debug", ret)]544pub fn evaluate_solver_constraint<I: Interner>(
545 constraint: &RegionConstraint<I>,
546) -> RegionConstraint<I> {
547use RegionConstraint::*;
548match constraint {
549 Ambiguity | RegionOutlives(..) | AliasTyOutlivesViaEnv(..) | PlaceholderTyOutlives(..) => {
550 constraint.clone()
551 }
552 And(and) => {
553let mut and_constraints = Vec::new();
554let mut is_ambiguous_constraint = false;
555for c in and.iter() {
556let evaluated_constraint = evaluate_solver_constraint(c);
557if evaluated_constraint.is_true() {
558// - do nothing
559} else if evaluated_constraint.is_false() {
560return RegionConstraint::new_false();
561 } else if evaluated_constraint.is_ambig() {
562 is_ambiguous_constraint = true;
563 } else {
564 and_constraints.push(evaluated_constraint);
565 }
566 }
567568if is_ambiguous_constraint {
569 RegionConstraint::Ambiguity
570 } else {
571 RegionConstraint::And(and_constraints.into_boxed_slice())
572 }
573 }
574 Or(or) => {
575let mut or_constraints = Vec::new();
576let mut is_ambiguous_constraint = false;
577for c in or.iter() {
578let evaluated_constraint = evaluate_solver_constraint(c);
579if evaluated_constraint.is_false() {
580// do nothing
581} else if evaluated_constraint.is_true() {
582return RegionConstraint::new_true();
583 } else if evaluated_constraint.is_ambig() {
584 is_ambiguous_constraint = true;
585 } else {
586 or_constraints.push(evaluated_constraint);
587 }
588 }
589590if is_ambiguous_constraint {
591 RegionConstraint::Ambiguity
592 } else {
593 RegionConstraint::Or(or_constraints.into_boxed_slice())
594 }
595 }
596 }
597}
598599/// Handles converting region outlives constraints involving placeholders from `u` into OR constraints
600/// involving regions from smaller universes with known relationships to the placeholder. For example:
601/// ```ignore (not rust)
602/// for<'a, 'b> where(
603/// 'c: 'b, 'd: 'b,
604/// 'a: 'e, 'a: 'f,
605/// ) {
606/// 'a_u1: 'b_u1
607/// }
608/// ```
609/// will get converted to:
610/// ```ignore (not rust)
611/// OR(
612/// 'e: 'c,
613/// 'e: 'd,
614/// 'f: 'c,
615/// 'f: 'd,
616/// )
617/// ```
618/// if we are handling constraints in `u1`.
619x;#[instrument(level = "debug", skip(infcx), ret)]620fn pull_region_outlives_constraints_out_of_universe<
621 Infcx: InferCtxtLike<Interner = I>,
622 I: Interner,
623>(
624 infcx: &Infcx,
625 constraint: RegionConstraint<I>,
626 u: UniverseIndex,
627 assumptions: &Option<Assumptions<I>>,
628) -> RegionConstraint<I> {
629assert!(max_universe(infcx, constraint.clone()) <= u);
630631// FIXME(-Zassumptions-on-binders): we don't lower universes of region variables when exiting `u`
632 // this seems dubious/potentially wrong? we can't just blindly do this though as if we had something
633 // like `!T_u -> ?x_u -> !U_u` then lowering `?x` to `u-1` when exiting `u` would be wrong.
634 //
635 // I'm not even sure this would be necessary given we filter out region constraints involving regions#
636 // from the current universe and only retain those between placeholders.
637638use RegionConstraint::*;
639match constraint {
640 Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
641assert!(max_universe(infcx, constraint.clone()) < u);
642 constraint
643 }
644 RegionOutlives(region_1, region_2) => {
645let region_1_u = max_universe(infcx, region_1);
646let region_2_u = max_universe(infcx, region_2);
647648if region_1_u != u && region_2_u != u {
649return constraint;
650 }
651652let assumptions = match assumptions {
653Some(assumptions) => assumptions,
654None => return RegionConstraint::Ambiguity,
655 };
656657let mut candidates = vec![];
658for ub in
659regions_outlived_by(region_1, assumptions).filter(|r| max_universe(infcx, *r) < u)
660 {
661// FIXME(-Zassumptions-on-binders): if `region_2` is in a smaller universe there'll be both
662 // `'region_2` and `'static` as lower bounds which seems... unfortunate and may cause us to
663 // add a bunch of duplicate `'ub: 'static` candidates the more binders we leave.
664for lb in regions_outliving(region_2, assumptions, infcx.cx())
665 .filter(|r| max_universe(infcx, *r) < u)
666 {
667// As long as any region outlived by `region_1` outlives any region region which
668 // `region_2` outlives, we know that `region_1: region_2` holds. In other words,
669 // there exists some set of 4 regions for which `'r1: 'i1` `'i1: 'i2` `'i2: 'r2`
670candidates.push(RegionOutlives(ub, lb));
671 }
672 }
673674 RegionConstraint::Or(candidates.into_boxed_slice())
675 }
676 And(constraints) => And(constraints
677 .into_iter()
678 .map(|constraint| {
679 pull_region_outlives_constraints_out_of_universe(infcx, constraint, u, assumptions)
680 })
681 .collect()),
682 Or(_) => unreachable!(),
683 }
684}
685686/// Converts type outlives constraints into region outlives constraints. This assumes the *complete* set of
687/// assumptions are known. This should not be called until the end of type checking.
688///
689/// The returned region constraint will not have *any* PlaceholderTyOutlives or AliasTyOutlivesViaEnv constraints.
690pub fn destructure_type_outlives_constraints_in_root<
691 Infcx: InferCtxtLike<Interner = I>,
692 I: Interner,
693>(
694 infcx: &Infcx,
695 constraint: RegionConstraint<I>,
696 assumptions: &Assumptions<I>,
697) -> RegionConstraint<I> {
698use RegionConstraint::*;
699700match constraint {
701Ambiguity | RegionOutlives(..) => constraint,
702PlaceholderTyOutlives(ty, r) => {
703Or(regions_outlived_by_placeholder(ty, assumptions, infcx.cx())
704 .map(move |assumption_r| RegionOutlives(assumption_r, r))
705 .collect::<Vec<_>>()
706 .into_boxed_slice())
707 }
708AliasTyOutlivesViaEnv(bound_outlives) => {
709alias_outlives_candidates_from_assumptions(infcx, bound_outlives, assumptions)
710 }
711And(constraints) => And(constraints712 .into_iter()
713 .map(|constraint| {
714destructure_type_outlives_constraints_in_root(infcx, constraint, assumptions)
715 })
716 .collect()),
717Or(constraints) => Or(constraints718 .into_iter()
719 .map(|constraint| {
720destructure_type_outlives_constraints_in_root(infcx, constraint, assumptions)
721 })
722 .collect()),
723 }
724}
725726/// Converts type outlives constraints into either region outlives constraints, or type outlives
727/// constraints which do not contain anything from `u`.
728///
729/// This only works off assumptions associated with the binder corresponding to `u` both for
730/// perf reasons and because the full set of region assumptions is not known during type checking
731/// due to closure signature inference.
732///
733/// This only really causes problems for higher-ranked outlives assumptions, for example if we have
734/// `where for<'a> <T as Trait<'a>>::Assoc: 'b` then we can't use that to prove `<T as Trait<'!c>>::Assoc: 'b`
735/// until we are in the root context. See comments inside this function for more detail.
736x;#[instrument(level = "debug", skip(infcx), ret)]737fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<
738 Infcx: InferCtxtLike<Interner = I>,
739 I: Interner,
740>(
741 infcx: &Infcx,
742 constraint: RegionConstraint<I>,
743 u: UniverseIndex,
744 assumptions: &Option<Assumptions<I>>,
745) -> RegionConstraint<I> {
746assert!(
747 max_universe(infcx, constraint.clone()) <= u,
748"constraint {:?} contains terms from a larger universe than {:?}",
749 constraint.clone(),
750 u
751 );
752753use RegionConstraint::*;
754match constraint {
755 Ambiguity | RegionOutlives(..) => constraint,
756 PlaceholderTyOutlives(ty, region) => {
757let ty_u = max_universe(infcx, ty);
758let region_u = max_universe(infcx, region);
759760if region_u != u && ty_u != u {
761return constraint;
762 }
763764let assumptions = match assumptions {
765Some(assumptions) => assumptions,
766None => return Ambiguity,
767 };
768769let mut candidates = vec![];
770771// There could be `!T: 'region` assumptions in the env even if `!T` is in a
772 // smaller universe
773candidates.extend(
774 regions_outlived_by_placeholder(ty, assumptions, infcx.cx())
775 .map(move |assumption_r| RegionOutlives(assumption_r, region)),
776 );
777778// We can express `!T: 'region` as `!T: 'r` where `'r: 'region`. This is only necessary
779 // if the placeholder type is in a smaller universe as otherwise we know all regions which
780 // the placeholder outlives and can just destructure into an OR of RegionOutlives.
781if region_u == u && ty_u < u {
782 candidates.extend(
783 regions_outliving::<I>(region, assumptions, infcx.cx())
784 .filter(|r| max_universe(infcx, *r) < u)
785 .map(|r| PlaceholderTyOutlives(ty, r)),
786 );
787 }
788789 Or(candidates.into_boxed_slice())
790 }
791 AliasTyOutlivesViaEnv(bound_outlives) => {
792let mut candidates = Vec::new();
793794// given there can be higher ranked assumptions, e.g. `for<'a> <T as Trait<'a>>::Assoc: 'c`, that
795 // means that it's actually *always* possible for an alias outlive to be satisfied in the root universe
796 // which means there should *always* be atleast two candidates when destructuring alias outlives. The
797 // two candidates being component outlives and then a higher ranked alias outlives.
798 //
799 // we dont care about this for region outlives as `for<'a> 'a: 'b` can't exist as we don't elaborate
800 // higher ranked type outlives assumptions into higher ranked region outlives assumptions. similarly,
801 // we don't care about `for<'a> Foo<'a>: 'b` as we always destructure adts into their components and if
802 // we dont equivalently elaborate the assumption into assumptions on the adt's components we just drop the
803 // assumptions
804 //
805 // so actually only `for<'a, 'b> Alias<'a>: 'b` and `for<'a> T: 'a` are assumptions we actually need to
806 // handle.
807 //
808 // we don't care about this when rewriting in the root universe as we know the complete set of assumptions
809if max_universe(infcx, bound_outlives) == u {
810let mut replacer = PlaceholderReplacer {
811 cx: infcx.cx(),
812 existing_var_count: bound_outlives.bound_vars().len(),
813 bound_vars: IndexMap::default(),
814 universe: u,
815 current_index: DebruijnIndex::ZERO,
816 };
817let escaping_outlives = bound_outlives.skip_binder().fold_with(&mut replacer);
818let bound_vars = bound_outlives.bound_vars().iter().chain(
819 core::mem::take(&mut replacer.bound_vars)
820 .into_iter()
821 .map(|(_, bound_region)| BoundVariableKind::Region(bound_region.kind)),
822 );
823let bound_outlives = Binder::bind_with_vars(
824 escaping_outlives,
825 I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
826 );
827let candidate = RegionConstraint::AliasTyOutlivesViaEnv(bound_outlives);
828if max_universe(infcx, candidate.clone()) < u {
829 candidates.push(candidate);
830 } else {
831// `PlaceholderReplacer` only folds regions. A non-lifetime binder can leave
832 // a placeholder type in `u`, so this type-outlives constraint cannot be
833 // handled by the region-outlives-only eager placeholder machinery.
834candidates.push(Ambiguity);
835 }
836 }
837838let assumptions = match assumptions {
839Some(assumptions) => assumptions,
840None => {
841 candidates.push(Ambiguity);
842return Or(candidates.into_boxed_slice());
843 }
844 };
845846// Actually look at the assumptions and matching our higher ranked alias outlives goal
847 // against potentially higher ranked type outlives assumptions.
848candidates.push(alias_outlives_candidates_from_assumptions(
849 infcx,
850 bound_outlives,
851 assumptions,
852 ));
853854// we can rewrite `Alias_u1: 'u2` into `Or(Alias_u1: 'u1)`
855 // given a list of regions which outlive `'u2`
856 //
857 // we don't care about this when rewriting in the root universe as we know the complete set of assumptions
858let (escaping_alias, escaping_r) = bound_outlives.skip_binder();
859if max_universe(infcx, escaping_r) == u {
860let mut replacer = PlaceholderReplacer {
861 cx: infcx.cx(),
862 existing_var_count: bound_outlives.bound_vars().len(),
863 bound_vars: IndexMap::default(),
864 universe: u,
865 current_index: DebruijnIndex::ZERO,
866 };
867let escaping_alias = escaping_alias.fold_with(&mut replacer);
868let bound_vars = bound_outlives.bound_vars().iter().chain(
869 core::mem::take(&mut replacer.bound_vars)
870 .into_iter()
871 .map(|(_, bound_region)| BoundVariableKind::Region(bound_region.kind)),
872 );
873let bound_alias = Binder::bind_with_vars(
874 escaping_alias,
875 I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
876 );
877878// while we did skip the binder, bound vars aren't in any universe so
879 // this can't be an escaping bound var
880for r2 in regions_outliving(escaping_r, assumptions, infcx.cx())
881 .filter(|r2| max_universe(infcx, *r2) < u)
882 {
883let candidate =
884 AliasTyOutlivesViaEnv(bound_alias.map_bound(|alias| (alias, r2)));
885if max_universe(infcx, candidate.clone()) < u {
886 candidates.push(candidate);
887 } else {
888 candidates.push(Ambiguity);
889 }
890 }
891 }
892893// I'm not convinced our handling here is *complete* so for now
894 // let's be conservative and not let alias outlives' cause NoSolution
895 // in coherence
896match infcx.typing_mode_raw() {
897 TypingMode::Coherence => candidates.push(RegionConstraint::Ambiguity),
898 TypingMode::Typeck { .. }
899 | TypingMode::ErasedNotCoherence { .. }
900 | TypingMode::PostTypeckUntilBorrowck { .. }
901 | TypingMode::PostBorrowck { .. }
902 | TypingMode::Reflection
903 | TypingMode::PostAnalysis
904 | TypingMode::Codegen => (),
905 };
906907 RegionConstraint::Or(candidates.into_boxed_slice())
908 }
909 And(constraints) => And(constraints
910 .into_iter()
911 .map(|constraint| {
912 rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling(
913 infcx,
914 constraint,
915 u,
916 assumptions,
917 )
918 })
919 .collect()),
920 Or(constraints) => Or(constraints
921 .into_iter()
922 .map(|constraint| {
923 rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling(
924 infcx,
925 constraint,
926 u,
927 assumptions,
928 )
929 })
930 .collect()),
931 }
932}
933934/// Returns all regions `r2` for which `r: r2` is known to hold in
935/// the universe associated with `assumptions`
936pub fn regions_outlived_by<I: Interner>(
937 r: Region<I>,
938 assumptions: &Assumptions<I>,
939) -> impl Iterator<Item = Region<I>> {
940// FIXME(-Zassumptions-on-binders): do we need to be adding the reflexive edge here?
941assumptions.region_outlives.reachable_from(r).into_iter().chain([r])
942}
943944/// Returns all regions `r2` for which `r2: r` is known to hold in
945/// the universe associated with `assumptions`
946pub fn regions_outliving<I: Interner>(
947 r: Region<I>,
948 assumptions: &Assumptions<I>,
949 cx: I,
950) -> impl Iterator<Item = Region<I>> {
951assumptions952 .inverse_region_outlives
953 .reachable_from(r)
954 .into_iter()
955// FIXME(-Zassumptions-on-binders): 'static may have been an input region canonicalized to something else is that important?
956 // FIXME(-Zassumptions-on-binders): do we need to adding the reflexive edge here?
957.chain([r, Region::new_static(cx)])
958}
959960/// Returns all regions `r` for which `!t: r` is known to hold in
961/// the universe associated with `assumptions`
962pub fn regions_outlived_by_placeholder<I: Interner>(
963 t: I::Ty,
964 assumptions: &Assumptions<I>,
965 cx: I,
966) -> impl Iterator<Item = Region<I>> {
967match t.kind() {
968 TyKind::Placeholder(..) | TyKind::Param(..) => (),
969_ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("non-placeholder in `regions_outlived_by_placeholder`: {0:?}",
t)));
}unreachable!("non-placeholder in `regions_outlived_by_placeholder`: {t:?}"),
970 }
971972assumptions.type_outlives.iter().flat_map(move |binder| match binder.no_bound_vars() {
973Some(OutlivesClause(ty, r)) => (ty == t).then_some(r),
974None => Some(Region::new_static(cx)),
975 })
976}
977978pub struct PlaceholderReplacer<I: Interner> {
979 cx: I,
980 existing_var_count: usize,
981 bound_vars: IndexMap<BoundVar, BoundRegion<I>>,
982 universe: UniverseIndex,
983 current_index: DebruijnIndex,
984}
985986impl<I: Interner> TypeFolder<I> for PlaceholderReplacer<I> {
987fn cx(&self) -> I {
988self.cx
989 }
990991fn fold_region(&mut self, r: Region<I>) -> Region<I> {
992match r.kind() {
993 RegionKind::RePlaceholder(p) if p.universe == self.universe => {
994let bound_vars_len = self.bound_vars.len();
995let mapped_var = self.bound_vars.entry(p.bound.var).or_insert(BoundRegion {
996 var: BoundVar::from_usize(self.existing_var_count + bound_vars_len),
997 kind: p.bound.kind,
998 });
999Region::new_bound(self.cx, self.current_index, *mapped_var)
1000 }
1001// FIXME(-Zassumptions-on-binders): We should be handling region variables here somehow
1002_ => r,
1003 }
1004 }
10051006fn fold_binder<T: TypeFoldable<I>>(&mut self, b: Binder<I, T>) -> Binder<I, T> {
1007self.current_index.shift_in(1);
1008let b = b.super_fold_with(self);
1009self.current_index.shift_out(1);
1010b1011 }
1012}
10131014/// Converts an `AliasTyOutlivesViaEnv` constraint into an OR of region outlives constraints by
1015/// matching the alias against any `Alias: 'a` assumptions. This is somewhat tricky as we have a
1016/// potentially higher ranked alias being equated with a potentially higher ranked assumption and
1017/// we don't handle it correctly right now (though it is a somewhat reasonable halfway step).
1018x;#[instrument(level = "debug", skip(infcx), ret)]1019fn alias_outlives_candidates_from_assumptions<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
1020 infcx: &Infcx,
1021 bound_outlives: Binder<I, (AliasTy<I>, Region<I>)>,
1022 assumptions: &Assumptions<I>,
1023) -> RegionConstraint<I> {
1024let mut candidates = Vec::new();
10251026let prev_universe = infcx.universe();
10271028 infcx.enter_forall_with_empty_assumptions(bound_outlives, |(alias, r)| {
1029for bound_type_outlives in assumptions.type_outlives.iter() {
1030let OutlivesClause(alias2, r2) =
1031 infcx.instantiate_binder_with_infer(*bound_type_outlives);
10321033let mut relation = HigherRankedAliasMatcher {
1034 infcx,
1035 region_constraints: vec![RegionConstraint::RegionOutlives(r2, r)],
1036 };
10371038// FIXME(#155345): Both sides should be rigid in the future.
1039 // Currently we can't guarantee that.
1040if let Ok(_) = relation.relate(
1041 alias.to_ty(infcx.cx(), IsRigid::No),
1042 set_aliases_to_non_rigid(infcx.cx(), alias2).skip_norm_wip(),
1043 ) {
1044 candidates
1045 .push(RegionConstraint::And(relation.region_constraints.into_boxed_slice()));
1046 }
1047 }
1048 });
10491050let constraint = RegionConstraint::Or(candidates.into_boxed_slice());
10511052let largest_universe = infcx.universe();
1053debug!(?prev_universe, ?largest_universe);
10541055 ((prev_universe.index() + 1)..=largest_universe.index())
1056 .map(|u| UniverseIndex::from_usize(u))
1057 .rev()
1058 .fold(constraint, |constraint, u| {
1059 eagerly_handle_placeholders_in_universe(infcx, constraint, u)
1060 })
1061}
10621063struct HigherRankedAliasMatcher<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> {
1064 infcx: &'a Infcx,
1065 region_constraints: Vec<RegionConstraint<I>>,
1066}
10671068impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeRelation<I>
1069for HigherRankedAliasMatcher<'a, Infcx, I>
1070{
1071fn cx(&self) -> I {
1072self.infcx.cx()
1073 }
10741075fn relate_ty_args(
1076&mut self,
1077 a_ty: I::Ty,
1078 _b_ty: I::Ty,
1079 _ty_def_id: I::DefId,
1080 a_args: I::GenericArgs,
1081 b_args: I::GenericArgs,
1082 _mk: impl FnOnce(I::GenericArgs) -> I::Ty,
1083 ) -> RelateResult<I, I::Ty> {
1084 rustc_type_ir::relate::relate_args_invariantly(self, a_args, b_args)?;
1085Ok(a_ty)
1086 }
10871088fn relate_with_variance<T: Relate<I>>(
1089&mut self,
1090 _variance: Variance,
1091 _info: VarianceDiagInfo<I>,
1092 a: T,
1093 b: T,
1094 ) -> RelateResult<I, T> {
1095// FIXME(-Zassumptions-on-binders): bivariance is important for opaque type args so
1096 // we should actually handle variance in some way here.
1097self.relate(a, b)
1098 }
10991100fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult<I, I::Ty> {
1101 rustc_type_ir::relate::structurally_relate_tys(self, a, b)
1102 }
11031104fn regions(&mut self, a: Region<I>, b: Region<I>) -> RelateResult<I, Region<I>> {
1105if a != b {
1106self.region_constraints.push(RegionConstraint::RegionOutlives(a, b));
1107self.region_constraints.push(RegionConstraint::RegionOutlives(b, a));
1108 }
1109Ok(a)
1110 }
11111112fn consts(&mut self, a: I::Const, b: I::Const) -> RelateResult<I, I::Const> {
1113 rustc_type_ir::relate::structurally_relate_consts(self, a, b)
1114 }
11151116fn binders<T>(&mut self, a: Binder<I, T>, b: Binder<I, T>) -> RelateResult<I, Binder<I, T>>
1117where
1118T: Relate<I>,
1119 {
1120self.infcx.enter_forall_with_empty_assumptions(a, |a| {
1121let u = self.infcx.universe();
1122self.infcx.insert_placeholder_assumptions(u, Some(Assumptions::empty()));
1123let b = self.infcx.instantiate_binder_with_infer(b);
1124self.relate(a, b)
1125 })?;
11261127self.infcx.enter_forall_with_empty_assumptions(b, |b| {
1128let u = self.infcx.universe();
1129self.infcx.insert_placeholder_assumptions(u, Some(Assumptions::empty()));
1130let a = self.infcx.instantiate_binder_with_infer(a);
1131self.relate(a, b)
1132 })?;
11331134Ok(a)
1135 }
1136}