Skip to main content

rustc_type_ir/
region_constraint.rs

1//! The bulk of the logic for implementing `-Zassumptions-on-binders`
2use std::ops::Deref;
3
4use derive_where::derive_where;
5use indexmap::IndexSet;
6#[cfg(feature = "nightly")]
7use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder};
8#[cfg(feature = "nightly")]
9use rustc_macros::StableHash_NoContext;
10use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
11use tracing::{debug, instrument};
12
13use crate::Const;
14
15// Workaround for TransitiveRelation being in rustc_data_structures which isn't accessible on stable
16#[cfg(not(feature = "nightly"))]
17#[derive(Default, Clone, Debug)]
18pub struct TransitiveRelation<T>(T);
19#[cfg(not(feature = "nightly"))]
20impl<T> TransitiveRelation<T> {
21    pub fn reachable_from(&self, _data: T) -> Vec<T> {
22        unreachable!("-Zassumptions-on-binders is not supported for r-a")
23    }
24
25    pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> {
26        unreachable!("-Zassumptions-on-binders is not supported for r-a");
27
28        #[allow(unreachable_code)]
29        [].into_iter()
30    }
31}
32#[derive(Clone, Debug)]
33#[cfg(not(feature = "nightly"))]
34pub struct TransitiveRelationBuilder<T>(T);
35#[cfg(not(feature = "nightly"))]
36impl<T> TransitiveRelationBuilder<T> {
37    pub fn freeze(self) -> TransitiveRelation<T> {
38        unreachable!("-Zassumptions-on-binders is not supported for r-a")
39    }
40
41    pub fn add(&mut self, _: T, _: T) {
42        unreachable!("-Zassumptions-on-binders is not supported for r-a")
43    }
44}
45#[cfg(not(feature = "nightly"))]
46impl<T> Default for TransitiveRelationBuilder<T> {
47    fn default() -> Self {
48        unreachable!("-Zassumptions-on-binders is not supported for r-a")
49    }
50}
51
52use smallvec::SmallVec;
53
54use crate::data_structures::IndexMap;
55use crate::fold::TypeSuperFoldable;
56use crate::inherent::*;
57use crate::relate::{Relate, RelateResult, TypeRelation, VarianceDiagInfo};
58use crate::visit::TypeVisitableExt;
59use crate::{
60    AliasTy, Binder, BoundRegion, BoundRegionKind, BoundVar, BoundVariableKind, ClauseKind,
61    DebruijnIndex, InferCtxtLike, Interner, IsRigid, OutlivesClause, Region, RegionKind, TyKind,
62    TypeFoldable, TypeFolder, TypingMode, UniverseIndex, Variance, elaborate, max_universe,
63    set_aliases_to_non_rigid,
64};
65
66#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for Assumptions<I> where I: Interner {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Assumptions {
                type_outlives: ref __field_type_outlives,
                region_outlives: ref __field_region_outlives,
                inverse_region_outlives: ref __field_inverse_region_outlives }
                =>
                Assumptions {
                    type_outlives: ::core::clone::Clone::clone(__field_type_outlives),
                    region_outlives: ::core::clone::Clone::clone(__field_region_outlives),
                    inverse_region_outlives: ::core::clone::Clone::clone(__field_inverse_region_outlives),
                },
        }
    }
}#[derive_where(Clone; I: Interner)]
67pub struct Assumptions<I: Interner> {
68    pub type_outlives: Vec<Binder<I, OutlivesClause<I, I::Ty>>>,
69    /// Known `'a: 'b` assumptions, stored as an edge from the outliving region to the
70    /// outlived one, i.e. an edge `('a, 'b)` means `'a: 'b`. Constructors expect a relation
71    /// with this direction, see [`regions_outlived_by`] and [`regions_outliving`] for how it
72    /// is consumed.
73    pub region_outlives: TransitiveRelation<Region<I>>,
74    pub inverse_region_outlives: TransitiveRelation<Region<I>>,
75}
76
77impl<I: Interner> std::fmt::Debug for Assumptions<I> {
78    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
79        f.debug_struct("Assumptions")
80            .field("type_outlives", &self.type_outlives)
81            .field("region_graph", &"elided")
82            .finish()
83    }
84}
85
86impl<I: Interner> Assumptions<I> {
87    pub fn empty() -> Self {
88        Self {
89            type_outlives: Vec::new(),
90            region_outlives: TransitiveRelationBuilder::default().freeze(),
91            inverse_region_outlives: TransitiveRelationBuilder::default().freeze(),
92        }
93    }
94
95    /// Builds assumptions from `clauses`, elaborating them and keeping the outlives ones.
96    ///
97    /// Callers hand us their clauses straight from the environment, so we have to elaborate
98    /// here to get at the implied outlives bounds:
99    /// - a `Ty: 'a` clause tells us that every region component of `Ty` outlives `'a`, e.g.
100    ///   `&'b u8: 'a` implies `'b: 'a`. Without it we'd fail to prove `'b: 'a` when leaving
101    ///   the binder these assumptions belong to.
102    /// - it also gives us the components as type outlives, e.g. `Vec<T>: 'a` implies `T: 'a`,
103    ///   which we need for placeholder and alias outlives.
104    /// - trait clauses imply their supertraits, so `T: Bound<'a>` where `trait Bound<'c>: 'c`
105    ///   gives us `T: 'a`. This is why we take clauses rather than just the outlives ones:
106    ///   filtering down to outlives before elaborating would throw those away.
107    ///
108    /// Only the clauses whose max universe is exactly `universe` are kept, which is what the
109    /// solver wants when computing the assumptions of a single binder. This happens after
110    /// elaboration on purpose, so a clause whose regions live in more than one universe still
111    /// contributes its implied bounds to each of them: `(&'b u8, &'c u8): 'a` gives us
112    /// `'c: 'a` in `'c`s universe even though the clause itself is in `'b`s.
113    ///
114    /// Use [`Assumptions::new_unelaborated`] when the caller needs the assumptions to be
115    /// exactly the clauses it passed in.
116    pub fn new(
117        infcx: &impl InferCtxtLike<Interner = I>,
118        clauses: impl IntoIterator<Item = I::Clause>,
119        region_outlives: TransitiveRelation<Region<I>>,
120        universe: UniverseIndex,
121    ) -> Self {
122        let mut type_outlives = ::alloc::vec::Vec::new()vec![];
123        let mut region_outlives_builder = TransitiveRelationBuilder::default();
124        for (r1, r2) in region_outlives.base_edges() {
125            region_outlives_builder.add(r1, r2);
126        }
127
128        let clauses = elaborate::elaborate(infcx.cx(), clauses)
129            .filter(|clause| max_universe(infcx, *clause) == universe);
130        for clause in clauses {
131            match clause.kind().skip_binder() {
132                // The type outlives assumptions are kept around as they are required for
133                // proving placeholder and alias outlives.
134                ClauseKind::TypeOutlives(_) => {
135                    type_outlives.push(clause.as_type_outlives_clause().unwrap());
136                }
137                ClauseKind::RegionOutlives(OutlivesClause(r1, r2)) => {
138                    // `elaborate` drops the components which are bound inside of the type and
139                    // bails on `for<'a> Ty: 'a`, so both regions here are free even though the
140                    // clause itself may still be under a binder.
141                    if true {
    if !(!r1.is_bound() && !r2.is_bound()) {
        ::core::panicking::panic("assertion failed: !r1.is_bound() && !r2.is_bound()")
    };
};debug_assert!(!r1.is_bound() && !r2.is_bound());
142                    region_outlives_builder.add(r1, r2);
143                }
144                // Anything else can't be used as an outlives assumption.
145                _ => (),
146            }
147        }
148
149        Self::new_unelaborated(type_outlives, region_outlives_builder.freeze())
150    }
151
152    /// Builds assumptions from exactly the given clauses, see [`Assumptions::new`] for when
153    /// the clauses should get elaborated instead.
154    pub fn new_unelaborated(
155        type_outlives: Vec<Binder<I, OutlivesClause<I, I::Ty>>>,
156        region_outlives: TransitiveRelation<Region<I>>,
157    ) -> Self {
158        Self {
159            inverse_region_outlives: {
160                let mut builder = TransitiveRelationBuilder::default();
161                for (r1, r2) in region_outlives.base_edges() {
162                    builder.add(r2, r1);
163                }
164                builder.freeze()
165            },
166            type_outlives,
167            region_outlives,
168        }
169    }
170}
171
172/// The span stored in a [`RegionConstraint`] and friends.
173///
174/// Constraints are created with spans during type checking, but are also stored
175/// without any span, e.g. in query responses, in which case [`NoSpan`] is used.
176/// This trait exists so that code which is generic over the span only needs a
177/// single bound instead of repeating all of the supertrait bounds.
178pub trait ConstraintSpan: Clone + std::fmt::Debug + Eq + std::hash::Hash {}
179
180/// Placeholder for constraints which do not carry a span, see [`ConstraintSpan`].
181#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for NoSpan {
}
#[automatically_derived]impl ::core::clone::Clone for NoSpan {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for NoSpan { }Copy, #[automatically_derived]impl ::core::fmt::Debug for NoSpan {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "NoSpan")
    }
}Debug, #[automatically_derived]impl ::core::default::Default for NoSpan {
    #[inline]
    fn default() -> Self { NoSpan {} }
}Default, #[automatically_derived]impl ::core::hash::Hash for NoSpan {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]impl ::core::marker::StructuralPartialEq for NoSpan {
}
#[automatically_derived]impl ::core::cmp::PartialEq for NoSpan {
    #[inline]
    fn eq(&self, other: &Self) -> bool { true }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for NoSpan { }Eq)]
182#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for NoSpan {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self { NoSpan => {} }
            }
        }
    };StableHash_NoContext))]
183pub struct NoSpan;
184
185impl ConstraintSpan for NoSpan {}
186
187#[cfg(feature = "nightly")]
188impl ConstraintSpan for rustc_span::Span {}
189
190#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for LeafRegionConstraint<I> where
    I: Interner {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            LeafRegionConstraint::Ambiguity =>
                LeafRegionConstraint::Ambiguity,
            LeafRegionConstraint::RegionOutlives(ref __field_0, ref __field_1)
                =>
                LeafRegionConstraint::RegionOutlives {
                    0: ::core::clone::Clone::clone(__field_0),
                    1: ::core::clone::Clone::clone(__field_1),
                },
            LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __field_0) =>
                LeafRegionConstraint::AliasTyOutlivesViaEnv {
                    0: ::core::clone::Clone::clone(__field_0),
                },
            LeafRegionConstraint::PlaceholderTyOutlives(ref __field_0,
                ref __field_1) =>
                LeafRegionConstraint::PlaceholderTyOutlives {
                    0: ::core::clone::Clone::clone(__field_0),
                    1: ::core::clone::Clone::clone(__field_1),
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for LeafRegionConstraint<I> where
    I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            LeafRegionConstraint::Ambiguity => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
            }
            LeafRegionConstraint::RegionOutlives(ref __field_0, ref __field_1)
                => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
                ::core::hash::Hash::hash(__field_1, __state);
            }
            LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
            LeafRegionConstraint::PlaceholderTyOutlives(ref __field_0,
                ref __field_1) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
                ::core::hash::Hash::hash(__field_1, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for LeafRegionConstraint<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (LeafRegionConstraint::RegionOutlives(ref __field_0,
                    ref __field_1),
                    LeafRegionConstraint::RegionOutlives(ref __other_field_0,
                    ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __field_0),
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __other_field_0))
                    =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (LeafRegionConstraint::PlaceholderTyOutlives(ref __field_0,
                    ref __field_1),
                    LeafRegionConstraint::PlaceholderTyOutlives(ref __other_field_0,
                    ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                _ => true,
            }
        } else { false }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for LeafRegionConstraint<I>
            where I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<Region<I>>;
                let _: __AssertEq<Region<I>>;
                let _: __AssertEq<Binder<I, (AliasTy<I>, Region<I>)>>;
                let _: __AssertEq<I::Ty>;
                let _: __AssertEq<Region<I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for LeafRegionConstraint<I> where
    I: Interner {
}#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
191#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            LeafRegionConstraint<I> where I: Interner,
            Region<I>: ::rustc_type_ir::TypeVisitable<I>,
            Binder<I,
            (AliasTy<I>, Region<I>)>: ::rustc_type_ir::TypeVisitable<I>,
            I::Ty: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    LeafRegionConstraint::Ambiguity => {}
                    LeafRegionConstraint::RegionOutlives(ref __binding_0,
                        ref __binding_1) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __binding_0)
                        => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    LeafRegionConstraint::PlaceholderTyOutlives(ref __binding_0,
                        ref __binding_1) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for
            LeafRegionConstraint<I> where
            Region<I>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            Region<I>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            Binder<I,
            (AliasTy<I>,
            Region<I>)>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            I::Ty: ::rustc_type_ir::GenericTypeVisitable<__V>,
            Region<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    LeafRegionConstraint::Ambiguity => {}
                    LeafRegionConstraint::RegionOutlives(ref __binding_0,
                        ref __binding_1) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __binding_0)
                        => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    LeafRegionConstraint::PlaceholderTyOutlives(ref __binding_0,
                        ref __binding_1) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            LeafRegionConstraint<I> where I: Interner,
            Region<I>: ::rustc_type_ir::TypeFoldable<I>,
            Binder<I,
            (AliasTy<I>, Region<I>)>: ::rustc_type_ir::TypeFoldable<I>,
            I::Ty: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        LeafRegionConstraint::Ambiguity => {
                            LeafRegionConstraint::Ambiguity
                        }
                        LeafRegionConstraint::RegionOutlives(__binding_0,
                            __binding_1) => {
                            LeafRegionConstraint::RegionOutlives(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        LeafRegionConstraint::AliasTyOutlivesViaEnv(__binding_0) =>
                            {
                            LeafRegionConstraint::AliasTyOutlivesViaEnv(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        LeafRegionConstraint::PlaceholderTyOutlives(__binding_0,
                            __binding_1) => {
                            LeafRegionConstraint::PlaceholderTyOutlives(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    LeafRegionConstraint::Ambiguity => {
                        LeafRegionConstraint::Ambiguity
                    }
                    LeafRegionConstraint::RegionOutlives(__binding_0,
                        __binding_1) => {
                        LeafRegionConstraint::RegionOutlives(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(__binding_0) =>
                        {
                        LeafRegionConstraint::AliasTyOutlivesViaEnv(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    LeafRegionConstraint::PlaceholderTyOutlives(__binding_0,
                        __binding_1) => {
                        LeafRegionConstraint::PlaceholderTyOutlives(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
192#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            LeafRegionConstraint<I> where
            Region<I>: ::rustc_data_structures::stable_hash::StableHash,
            Binder<I,
            (AliasTy<I>,
            Region<I>)>: ::rustc_data_structures::stable_hash::StableHash,
            I::Ty: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    LeafRegionConstraint::Ambiguity =>
                        0u8.stable_hash(__hcx, __hasher),
                    LeafRegionConstraint::RegionOutlives(ref __binding_0,
                        ref __binding_1) => 1u8.stable_hash(__hcx, __hasher),
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __binding_0)
                        => 2u8.stable_hash(__hcx, __hasher),
                    LeafRegionConstraint::PlaceholderTyOutlives(ref __binding_0,
                        ref __binding_1) => 3u8.stable_hash(__hcx, __hasher),
                }
                match *self {
                    LeafRegionConstraint::Ambiguity => {}
                    LeafRegionConstraint::RegionOutlives(ref __binding_0,
                        ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    LeafRegionConstraint::AliasTyOutlivesViaEnv(ref __binding_0)
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    LeafRegionConstraint::PlaceholderTyOutlives(ref __binding_0,
                        ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext))]
193pub enum LeafRegionConstraint<I: Interner> {
194    Ambiguity,
195    RegionOutlives(Region<I>, Region<I>),
196    /// Requirement that a (potentially higher ranked) alias outlives some (potentially higher ranked)
197    /// region due to an assumption in the environment. This cannot be satisfied via component outlives
198    /// or item bounds.
199    ///
200    /// We cannot eagerly look at assumptions as we are usually working with an incomplete set of assumptions
201    /// and there may wind up being assumptions we can use to prove this when we're in a smaller universe.
202    ///
203    /// We eagerly destructure alias outlives requirements into region outlives requirements corresponding to
204    /// component outlives & item bound outlives rules, leaving only param env candidates.
205    AliasTyOutlivesViaEnv(Binder<I, (AliasTy<I>, Region<I>)>),
206    /// This is an `I::Ty` for two reasons:
207    /// 1. We need the type visitable impl to be able to `visit_ty` on this so canonicalization
208    ///    knows about the placeholder
209    /// 2. When exiting the trait solver there may be placeholder outlives corresponding to params
210    ///    from the root universe. These need to be changed from a `Placeholder` to the original
211    ///    `Param`.
212    ///
213    /// We cannot eagerly look at assumptions as we are usually working with an incomplete set of assumptions
214    /// and there may wind up being assumptions we can use to prove this when we're in a smaller universe.
215    PlaceholderTyOutlives(I::Ty, Region<I>),
216}
217
218impl<I: Interner> std::fmt::Debug for LeafRegionConstraint<I> {
219    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
220        match self {
221            Self::Ambiguity => f.write_str("ambiguity"),
222            Self::RegionOutlives(r1, r2) => {
223                r1.fmt(f)?;
224                f.write_str(": ")?;
225                r2.fmt(f)
226            }
227            Self::AliasTyOutlivesViaEnv(bound_outlives) => {
228                f.write_str("for<")?;
229                bound_outlives.bound_vars().fmt(f)?;
230                f.write_str(">")?;
231                let (ty, r) = bound_outlives.skip_binder();
232                ty.fmt(f)?;
233                f.write_str(": ")?;
234                r.fmt(f)
235            }
236            Self::PlaceholderTyOutlives(ty, r) => {
237                ty.fmt(f)?;
238                f.write_str(": ")?;
239                r.fmt(f)
240            }
241        }
242    }
243}
244
245#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::clone::Clone for
    Or<I, S> where I: Interner, S: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Or(ref __field_0) =>
                Or { 0: ::core::clone::Clone::clone(__field_0) },
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::hash::Hash for Or<I, S>
    where I: Interner, S: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            Or(ref __field_0) => {
                ::core::hash::Hash::hash(__field_0, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::cmp::PartialEq for
    Or<I, S> where I: Interner, S: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (Or(ref __field_0), Or(ref __other_field_0)) =>
                true &&
                    ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner, S: Clone + std::fmt::Debug> DeriveWhereAssertEq for
            Or<I, S> where I: Interner, S: ::core::cmp::Eq {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<SmallVec<[And<I, S>; 1]>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::cmp::Eq for Or<I, S>
    where I: Interner, S: ::core::cmp::Eq {
}#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner, S)]
246#[derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeVisitable<I> for Or<I, S> where I: Interner,
            SmallVec<[And<I, S>; 1]>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    Or(ref __binding_0) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, const _: () =
    {
        unsafe impl<I: Interner, S: Clone + std::fmt::Debug, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for Or<I, S> where
            SmallVec<[And<I,
            S>; 1]>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    Or(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeFoldable<I> for Or<I, S> where I: Interner,
            S: ::rustc_type_ir::TypeFoldable<I>,
            SmallVec<[And<I, S>; 1]>: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        Or(__binding_0) => {
                            Or(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    Or(__binding_0) => {
                        Or(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
247#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_data_structures::stable_hash::StableHash for Or<I, S>
            where
            SmallVec<[And<I,
            S>; 1]>: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    Or(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext))]
248/// An OR of AND of LEAF constraints. Always in "canonical form" meaning:
249/// - No AND is a superset of another AND
250/// - All ANDs are in canonical form
251/// - If any AND is empty, i.e. trivially true, it is the only AND
252// FIXME(-Zassumptions-on-binders): move to a separate module to avoid accidental
253// mutation in this module?
254pub struct Or<I: Interner, S: Clone + std::fmt::Debug = NoSpan>(SmallVec<[And<I, S>; 1]>);
255impl<I: Interner> Or<I> {
256    pub fn with_spans<S: ConstraintSpan>(self, span: S) -> Or<I, S> {
257        Or(self.0.into_iter().map(|and| and.with_spans(span.clone())).collect())
258    }
259}
260enum AndRelation {
261    /// example:
262    /// existed: OR(AND('a: 'b))
263    /// new: AND('a: 'b, 'b: 'c)
264    Subset,
265
266    /// example:
267    /// existed: OR(AND('a: 'b, 'b: 'c))
268    /// new: AND('a: 'b)
269    Superset,
270
271    /// example:
272    /// existed: OR(AND('a: 'b))
273    /// new: AND('a: 'c)
274    Incomparable,
275}
276
277impl<I: Interner, S: ConstraintSpan> Or<I, S> {
278    pub fn new_true() -> Self {
279        Self(SmallVec::from_buf([And::new_true()]))
280    }
281
282    pub fn is_true(&self) -> bool {
283        // OR([AND([])])
284        if let [and] = &*self.0
285            && and.0.is_empty()
286        {
287            true
288        } else {
289            false
290        }
291    }
292
293    pub fn new_false() -> Self {
294        Self(SmallVec::new())
295    }
296
297    pub fn is_false(&self) -> bool {
298        // OR([])
299        self.0.is_empty()
300    }
301
302    pub fn new(i: impl IntoIterator<Item = And<I, S>>) -> Self {
303        let mut new_ands: SmallVec<[And<I, S>; _]> = SmallVec::new();
304
305        for and in i {
306            // An empty AND is trivially true, which makes the whole OR true no matter what the
307            // other candidates are. `And::new` discards leaf constraints which are trivially
308            // true, so this is how e.g. a reflexive `'a: 'a` candidate discharges an OR.
309            if and.0.is_empty() {
310                return Self::new_true();
311            }
312
313            // Currently, this is a more general canonical form:
314            // comparing the existing `new_ands` with a new `and`,
315            // we always keep the and with fewer constraints in new_ands.
316            // In particular, the equivalent case is also classified under the subset branch, and no push operation is performed.
317            let mut is_subset_new = false;
318            new_ands.retain(|c| {
319                let relation = c.compare_and_relation(&and);
320                match relation {
321                    AndRelation::Superset => false,
322                    AndRelation::Subset => {
323                        is_subset_new = true;
324                        return true;
325                    }
326                    AndRelation::Incomparable => true,
327                }
328            });
329            if is_subset_new {
330                continue;
331            }
332            new_ands.push(and);
333        }
334
335        Self(new_ands)
336    }
337
338    pub fn new_ambig(s: S) -> Self {
339        Or::new_leaf(LeafRegionConstraint::Ambiguity, s)
340    }
341
342    pub fn new_leaf(l: LeafRegionConstraint<I>, s: S) -> Self {
343        Or::new([And::new([(l, s)])])
344    }
345
346    pub fn build_and(a: Or<I, S>, b: Or<I, S>) -> Self {
347        // FIXME(-Zassumptions-on-binders): probably bad for perf, doing a lot of reallocating
348        // and whatnot here :3
349
350        // Important: keeps `ands` empty if either `b_and` or `a_and` is empty
351        let mut ands = Vec::new();
352        for b_and in b.0 {
353            for a_and in a.0.clone().into_iter() {
354                ands.push(And::new(a_and.0.into_iter().chain(b_and.0.clone())))
355            }
356        }
357
358        Or::new(ands)
359    }
360
361    pub fn build_or(a: Or<I, S>, b: Or<I, S>) -> Self {
362        Or::new(a.0.into_iter().chain(b.0))
363    }
364
365    pub fn without_spans(self) -> Or<I> {
366        Or(self.0.into_iter().map(|and| and.without_spans()).collect())
367    }
368}
369
370impl<I: Interner, S: Clone + std::fmt::Debug> std::fmt::Debug for Or<I, S> {
371    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
372        if self.0.is_empty() {
373            f.write_str("false")
374        } else if let [single] = &*self.0 {
375            single.fmt(f)
376        } else {
377            f.write_str("or ")?;
378            f.debug_set().entries(&self.0).finish()
379        }
380    }
381}
382
383impl<I: Interner, S: Clone + std::fmt::Debug> IntoIterator for Or<I, S> {
384    type Item = And<I, S>;
385    type IntoIter = <SmallVec<[And<I, S>; 1]> as IntoIterator>::IntoIter;
386
387    fn into_iter(self) -> Self::IntoIter {
388        self.0.into_iter()
389    }
390}
391
392impl<'a, I: Interner, S: Clone + std::fmt::Debug> IntoIterator for &'a Or<I, S> {
393    type Item = &'a And<I, S>;
394    type IntoIter = <&'a SmallVec<[And<I, S>; 1]> as IntoIterator>::IntoIter;
395
396    fn into_iter(self) -> Self::IntoIter {
397        (&self.0).into_iter()
398    }
399}
400
401impl<I: Interner, S: Clone + std::fmt::Debug> Deref for Or<I, S> {
402    type Target = SmallVec<[And<I, S>; 1]>;
403
404    fn deref(&self) -> &Self::Target {
405        &self.0
406    }
407}
408
409#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::clone::Clone for
    And<I, S> where I: Interner, S: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            And(ref __field_0) =>
                And { 0: ::core::clone::Clone::clone(__field_0) },
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::hash::Hash for And<I, S>
    where I: Interner, S: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            And(ref __field_0) => {
                ::core::hash::Hash::hash(__field_0, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::cmp::PartialEq for
    And<I, S> where I: Interner, S: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (And(ref __field_0), And(ref __other_field_0)) =>
                true &&
                    ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner, S: Clone + std::fmt::Debug> DeriveWhereAssertEq for
            And<I, S> where I: Interner, S: ::core::cmp::Eq {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _:
                        __AssertEq<SmallVec<[(LeafRegionConstraint<I>, S); 1]>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::cmp::Eq for And<I, S>
    where I: Interner, S: ::core::cmp::Eq {
}#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner, S)]
410#[derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeVisitable<I> for And<I, S> where I: Interner,
            SmallVec<[(LeafRegionConstraint<I>,
            S); 1]>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    And(ref __binding_0) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, const _: () =
    {
        unsafe impl<I: Interner, S: Clone + std::fmt::Debug, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for And<I, S> where
            SmallVec<[(LeafRegionConstraint<I>,
            S); 1]>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    And(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeFoldable<I> for And<I, S> where I: Interner,
            S: ::rustc_type_ir::TypeFoldable<I>,
            SmallVec<[(LeafRegionConstraint<I>,
            S); 1]>: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        And(__binding_0) => {
                            And(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    And(__binding_0) => {
                        And(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
411#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_data_structures::stable_hash::StableHash for And<I, S>
            where
            SmallVec<[(LeafRegionConstraint<I>,
            S); 1]>: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    And(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext))]
412/// An AND of leaf constraints. Always in "canonical form", meaning:
413/// - No leaf constraints are present twice in this AND
414/// - No leaf constraint is trivially true, i.e. a reflexive `'a: 'a`
415// FIXME(-Zassumptions-on-binders): move to a separate module to avoid accidental
416// mutation in this module?
417pub struct And<I: Interner, S: Clone + std::fmt::Debug = NoSpan>(
418    SmallVec<[(LeafRegionConstraint<I>, S); 1]>,
419);
420impl<I: Interner> And<I> {
421    pub fn with_spans<S: ConstraintSpan>(self, span: S) -> And<I, S> {
422        And(self.0.into_iter().map(|(leaf, _)| (leaf, span.clone())).collect())
423    }
424}
425impl<I: Interner, S: ConstraintSpan> And<I, S> {
426    pub fn new_true() -> Self {
427        Self(SmallVec::new())
428    }
429
430    pub fn new(i: impl IntoIterator<Item = (LeafRegionConstraint<I>, S)>) -> Self {
431        let mut seen = IndexSet::new();
432        And(i
433            .into_iter()
434            .filter(|(leaf, _)| {
435                // Outlives is reflexive so a `'a: 'a` leaf is always true and carries no
436                // information. Dropping it here keeps the rest of the code from having to special
437                // case it, and is what lets an OR with a reflexive candidate be recognized as true.
438                if let LeafRegionConstraint::RegionOutlives(r1, r2) = leaf
439                    && r1 == r2
440                {
441                    return false;
442                }
443
444                if seen.contains(leaf) {
445                    false
446                } else {
447                    seen.insert(leaf.clone());
448                    true
449                }
450            })
451            .collect())
452    }
453
454    /// Return the index of the added leaf.
455    /// It's not necessarily the last entry since we have deduplication.
456    pub fn add(&mut self, leaf: LeafRegionConstraint<I>, span: S) -> Option<usize> {
457        if let LeafRegionConstraint::RegionOutlives(r1, r2) = leaf
458            && r1 == r2
459        {
460            return None;
461        }
462        self.0.iter().position(|(x, _)| x == &leaf).or_else(|| {
463            self.0.push((leaf, span));
464            Some(self.0.len() - 1)
465        })
466    }
467
468    pub fn pop(&mut self) -> Option<(LeafRegionConstraint<I>, S)> {
469        self.0.pop()
470    }
471
472    fn compare_and_relation(&self, other: &And<I, S>) -> AndRelation {
473        let this = self.clone().0;
474        let other = other.clone().0;
475
476        // if newcome is superset
477        // In particular, the equivalent case is also classified under the subset branch
478        if this.iter().all(|(c1, _)| other.iter().any(|(c2, _)| c1 == c2)) {
479            return AndRelation::Subset;
480        }
481
482        // if newcome is subset
483        if other.iter().all(|(c2, _)| this.iter().any(|(c1, _)| c1 == c2)) {
484            return AndRelation::Superset;
485        }
486        return AndRelation::Incomparable;
487    }
488
489    pub fn without_spans(self) -> And<I> {
490        And(self.0.into_iter().map(|(leaf, _)| (leaf, NoSpan)).collect())
491    }
492}
493
494impl<I: Interner, S: Clone + std::fmt::Debug> std::fmt::Debug for And<I, S> {
495    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
496        if self.0.is_empty() {
497            f.write_str("true")
498        } else if let [(single, _span)] = &*self.0 {
499            single.fmt(f)
500        } else {
501            f.write_str("and ")?;
502            f.debug_set().entries(self.iter().map(|(l, _)| l)).finish()
503        }
504    }
505}
506
507impl<I: Interner, S: Clone + std::fmt::Debug> IntoIterator for And<I, S> {
508    type Item = (LeafRegionConstraint<I>, S);
509    type IntoIter = <SmallVec<[(LeafRegionConstraint<I>, S); 1]> as IntoIterator>::IntoIter;
510
511    fn into_iter(self) -> Self::IntoIter {
512        self.0.into_iter()
513    }
514}
515
516impl<'a, I: Interner, S: Clone + std::fmt::Debug> IntoIterator for &'a And<I, S> {
517    type Item = &'a (LeafRegionConstraint<I>, S);
518    type IntoIter = <&'a SmallVec<[(LeafRegionConstraint<I>, S); 1]> as IntoIterator>::IntoIter;
519
520    fn into_iter(self) -> Self::IntoIter {
521        (&self.0).into_iter()
522    }
523}
524
525impl<I: Interner, S: Clone + std::fmt::Debug> Deref for And<I, S> {
526    type Target = SmallVec<[(LeafRegionConstraint<I>, S); 1]>;
527
528    fn deref(&self) -> &Self::Target {
529        &self.0
530    }
531}
532
533#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::clone::Clone for
    RegionConstraint<I, S> where I: Interner, S: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            RegionConstraint {
                and_constraint: ref __field_and_constraint,
                or_constraint: ref __field_or_constraint } =>
                RegionConstraint {
                    and_constraint: ::core::clone::Clone::clone(__field_and_constraint),
                    or_constraint: ::core::clone::Clone::clone(__field_or_constraint),
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::hash::Hash for
    RegionConstraint<I, S> where I: Interner, S: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            RegionConstraint {
                and_constraint: ref __field_and_constraint,
                or_constraint: ref __field_or_constraint } => {
                ::core::hash::Hash::hash(__field_and_constraint, __state);
                ::core::hash::Hash::hash(__field_or_constraint, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::cmp::PartialEq for
    RegionConstraint<I, S> where I: Interner, S: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (RegionConstraint {
                and_constraint: ref __field_and_constraint,
                or_constraint: ref __field_or_constraint }, RegionConstraint {
                and_constraint: ref __other_field_and_constraint,
                or_constraint: ref __other_field_or_constraint }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_and_constraint,
                            __other_field_and_constraint) &&
                    ::core::cmp::PartialEq::eq(__field_or_constraint,
                        __other_field_or_constraint),
        }
    }
}#[derive_where(Clone, Hash, PartialEq; I: Interner, S)]
534#[derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeVisitable<I> for RegionConstraint<I, S> where
            I: Interner, And<I, S>: ::rustc_type_ir::TypeVisitable<I>,
            Or<I, S>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    RegionConstraint {
                        and_constraint: ref __binding_0,
                        or_constraint: ref __binding_1 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, const _: () =
    {
        unsafe impl<I: Interner, S: Clone + std::fmt::Debug, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for
            RegionConstraint<I, S> where
            And<I, S>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            Or<I, S>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    RegionConstraint {
                        and_constraint: ref __binding_0,
                        or_constraint: ref __binding_1 } => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_type_ir::TypeFoldable<I> for RegionConstraint<I, S> where
            I: Interner, S: ::rustc_type_ir::TypeFoldable<I>,
            And<I, S>: ::rustc_type_ir::TypeFoldable<I>,
            Or<I, S>: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        RegionConstraint {
                            and_constraint: __binding_0, or_constraint: __binding_1 } =>
                            {
                            RegionConstraint {
                                and_constraint: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                or_constraint: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    RegionConstraint {
                        and_constraint: __binding_0, or_constraint: __binding_1 } =>
                        {
                        RegionConstraint {
                            and_constraint: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            or_constraint: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
535#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner, S: Clone + std::fmt::Debug>
            ::rustc_data_structures::stable_hash::StableHash for
            RegionConstraint<I, S> where
            And<I, S>: ::rustc_data_structures::stable_hash::StableHash,
            Or<I, S>: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    RegionConstraint {
                        and_constraint: ref __binding_0,
                        or_constraint: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext))]
536/// An `And` and an `Or` constraint both in canonical forms, with two additional constraints:
537/// - If the `or_constraint` is false then the `and_constraint` is empty
538/// - The `or_constraint` does not have any constraints present in all of its inner `And`s
539///    - i.e. `OR ( AND ('a: 'b, 'b: 'c), AND ('a: 'b, 'b: 'd))` is not a thing
540/// - The OR constraint is in canonical form
541/// - The AND constraint is in canonical form
542///
543/// This should be thought of as an AND consisting of a set of LEAF constraints as well
544/// as a single OR constraint.
545pub struct RegionConstraint<I: Interner, S: Clone + std::fmt::Debug = NoSpan> {
546    pub and_constraint: And<I, S>,
547    pub or_constraint: Or<I, S>,
548}
549
550impl<I: Interner> RegionConstraint<I> {
551    pub fn with_spans<S: ConstraintSpan>(self, span: S) -> RegionConstraint<I, S> {
552        RegionConstraint {
553            and_constraint: self.and_constraint.with_spans(span.clone()),
554            or_constraint: self.or_constraint.with_spans(span.clone()),
555        }
556    }
557}
558impl<I: Interner, S: ConstraintSpan> RegionConstraint<I, S> {
559    pub fn new_from_or(or: Or<I, S>) -> Self {
560        let Some(fst) = or.0.get(0).clone() else {
561            return RegionConstraint::new_false();
562        };
563        let mut and_constraint = fst.0.to_vec();
564
565        for and in or.0.split_first().unwrap().1 {
566            and_constraint.retain(|(c, _)| and.0.iter().any(|(c2, _)| c == c2));
567        }
568        let and_constraint = And::new(and_constraint);
569
570        let or_constraint = Or::new(or.0.into_iter().map(|and| {
571            And::new(
572                and.0.into_iter().filter(|(c, _)| and_constraint.0.iter().all(|(s_c, _)| c != s_c)),
573            )
574        }));
575
576        Self {
577            and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint },
578            or_constraint,
579        }
580    }
581
582    pub fn splatted_and_constraints(&self) -> Or<I, S> {
583        Or::new(self.or_constraint.0.iter().map(|and| {
584            And::new(and.0.iter().cloned().chain(self.and_constraint.0.iter().cloned()))
585        }))
586    }
587
588    pub fn build_and(a: RegionConstraint<I, S>, b: RegionConstraint<I, S>) -> Self {
589        let and_constraint = And::new(a.and_constraint.0.into_iter().chain(b.and_constraint.0));
590        let or_constraint = Or::build_and(a.or_constraint, b.or_constraint);
591
592        Self {
593            and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint },
594            or_constraint,
595        }
596    }
597
598    pub fn build_or(a: RegionConstraint<I, S>, b: RegionConstraint<I, S>) -> Self {
599        Self::new_from_or(Or::build_or(a.splatted_and_constraints(), b.splatted_and_constraints()))
600    }
601
602    pub fn new_true() -> Self {
603        Self { and_constraint: And::new_true(), or_constraint: Or::new_true() }
604    }
605
606    pub fn is_true(&self) -> bool {
607        self.and_constraint.0.is_empty() && self.or_constraint.is_true()
608    }
609
610    pub fn new_false() -> Self {
611        Self { and_constraint: And::new_true(), or_constraint: Or::new_false() }
612    }
613
614    pub fn is_false(&self) -> bool {
615        self.or_constraint.is_false()
616    }
617
618    pub fn new_ambig(span: S) -> Self {
619        Self {
620            and_constraint: And::new([(LeafRegionConstraint::Ambiguity, span)]),
621            or_constraint: Or::new_true(),
622        }
623    }
624
625    pub fn is_ambig(&self) -> bool {
626        if let [(c, _)] = &*self.and_constraint.0
627            && c.is_ambig()
628            && self.or_constraint.is_true()
629        {
630            true
631        } else {
632            false
633        }
634    }
635
636    pub fn without_spans(self) -> RegionConstraint<I> {
637        RegionConstraint {
638            and_constraint: self.and_constraint.without_spans(),
639            or_constraint: self.or_constraint.without_spans(),
640        }
641    }
642
643    pub fn new_leaf(l: LeafRegionConstraint<I>, s: S) -> Self {
644        RegionConstraint { and_constraint: And::new([(l, s)]), or_constraint: Or::new_true() }
645    }
646}
647
648impl<I: Interner, S: Clone + std::fmt::Debug> std::fmt::Debug for RegionConstraint<I, S> {
649    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
650        if let [single_or] = &*self.or_constraint.0
651            && single_or.0.is_empty()
652        {
653            self.and_constraint.fmt(f)
654        } else if self.and_constraint.0.is_empty() {
655            self.or_constraint.fmt(f)
656        } else {
657            f.write_str("and ")?;
658            f.debug_set().entries(&self.and_constraint.0).entry(&self.or_constraint).finish()
659        }
660    }
661}
662
663impl<I: Interner> LeafRegionConstraint<I> {
664    pub fn is_ambig(&self) -> bool {
665        #[allow(non_exhaustive_omitted_patterns)] match self {
    Self::Ambiguity => true,
    _ => false,
}matches!(self, Self::Ambiguity)
666    }
667}
668
669/// Takes any constraints involving placeholders from the current universe and eagerly checks them.
670/// This can be done a few ways:
671/// - There's an assumption on the binder introducing the placeholder which means the constraint is satisfied (true)
672/// - There's assumptions on the binder introducing the placeholder which allow us to rewrite the constraint in
673///    terms of lower universe variables. For example given `for<'a> where('b: 'a) { prove(T: '!a_u1) }` we can
674///    convert this constraint to `T: 'b` which no longer references anything from `u1`.
675/// - There are no relevant assumptions so we can neither rewrite the constraint nor consider it satisfied (false)
676/// - We failed to compute the full set of assumptions when entering the binder corresponding to `u`. (ambiguity)
677///
678/// After handling all of the region constraints in `u` we then evaluate the entire constraint as much as possible,
679/// propagating true/false/ambiguity as close to the root of the constraint as we can. The returned constraint should
680/// be checked for whether it is true/false/ambiguous as that should affect the result of whatever operation required
681/// entering the binder corresponding to `u`.
682{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("eagerly_handle_placeholders_in_universe",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(682u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("constraint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("constraint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: RegionConstraint<I> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if !(u > UniverseIndex::ROOT) {
                            {
                                ::core::panicking::panic_fmt(format_args!("eagerly handle placeholders called for root universe"));
                            }
                        };
                        let constraint =
                            infcx.deeply_resolve_via_unification_table(constraint);
                        let assumptions = infcx.get_placeholder_assumptions(u);
                        let constraint =
                            rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx,
                                constraint, u, &assumptions);
                        let constraint =
                            compute_new_region_constraints(infcx, constraint, u);
                        let constraint =
                            pull_region_outlives_constraints_out_of_universe(infcx,
                                constraint, u, &assumptions);
                        constraint
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:682",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(682u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
683pub fn eagerly_handle_placeholders_in_universe<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
684    infcx: &Infcx,
685    constraint: RegionConstraint<I>,
686    u: UniverseIndex,
687) -> RegionConstraint<I> {
688    assert!(u > UniverseIndex::ROOT, "eagerly handle placeholders called for root universe");
689
690    let constraint = infcx.deeply_resolve_via_unification_table(constraint);
691    let assumptions = infcx.get_placeholder_assumptions(u);
692
693    // 1. rewrite type outlives constraints involving things from `u` into either region constraints
694    //     involving things from `u` or type outlives constraints not involving things from `u`
695    //
696    //    IOW, we only want to encounter things from `u` as part of region out lives constraints.
697    let constraint = rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling(
698        infcx,
699        constraint,
700        u,
701        &assumptions,
702    );
703
704    // 2. compute transitive region outlives and get a new set of region outlives constraints by
705    //     looking for every region which either a placeholder_u flows into it, or it flows into
706    //     the placeholder.
707    let constraint = compute_new_region_constraints(infcx, constraint, u);
708
709    // 3. rewrite region outlives constraints (potentially to false/true)
710    let constraint =
711        pull_region_outlives_constraints_out_of_universe(infcx, constraint, u, &assumptions);
712
713    constraint
714}
715
716/// Filter our region constraints to not include constraints between region variables from `u` and
717/// other regions as those are always satisfied. This requires some care to handle correctly for example:
718/// `'!a_u1: '?x_u1: '!b_u1` should result in us requiring `'!a_u1: '!b_u1` rather than dropping the two
719/// constraints entirely.
720///
721/// The only constraints involving things from `u` should be region outlives constraints at this point. Type
722/// outlives constraints should have been handled already either by destructuring into region outlives or by
723/// being rewritten in terms of smaller universe variables.
724{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("compute_new_region_constraints",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(724u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("constraint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("constraint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: RegionConstraint<I> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use LeafRegionConstraint::*;
                        let extend_from_and =
                            |builder: &mut TransitiveRelationBuilder<_>,
                                regions: &mut IndexSet<_>, constraints: &mut Vec<_>,
                                and: &And<I>|
                                {
                                    for (c, NoSpan) in &and.0 {
                                        match c {
                                            Ambiguity | PlaceholderTyOutlives(..) |
                                                AliasTyOutlivesViaEnv(..) => {
                                                constraints.push((c.clone(), NoSpan))
                                            }
                                            RegionOutlives(r1, r2) => {
                                                regions.insert(*r1);
                                                regions.insert(*r2);
                                                builder.add(*r2, *r1);
                                            }
                                        }
                                    }
                                };
                        let mut base_region_flows_builder =
                            TransitiveRelationBuilder::default();
                        let mut base_regions = IndexSet::new();
                        let mut base_constraints = Vec::new();
                        extend_from_and(&mut base_region_flows_builder,
                            &mut base_regions, &mut base_constraints,
                            &constraint.and_constraint);
                        let mut new_ands = Vec::new();
                        for and in &constraint.or_constraint.0 {
                            let mut region_flows_builder =
                                base_region_flows_builder.clone();
                            let mut regions = base_regions.clone();
                            let mut constraints = base_constraints.clone();
                            extend_from_and(&mut region_flows_builder, &mut regions,
                                &mut constraints, and);
                            let region_flow = region_flows_builder.freeze();
                            for r in regions.into_iter() {
                                for ub in region_flow.reachable_from(r) {
                                    let is_placeholder_like =
                                        |r: Region<I>|
                                            match r.kind() {
                                                RegionKind::ReLateParam(..) | RegionKind::ReEarlyParam(..) |
                                                    RegionKind::RePlaceholder(..) | RegionKind::ReStatic =>
                                                    true,
                                                RegionKind::ReVar(..) => max_universe(infcx, r) < u,
                                                RegionKind::ReError(..) => false,
                                                RegionKind::ReErased | RegionKind::ReBound(..) =>
                                                    ::core::panicking::unreachable_default_msg(),
                                            };
                                    if is_placeholder_like(r) && is_placeholder_like(ub) {
                                        constraints.push((RegionOutlives(ub, r), NoSpan));
                                    }
                                }
                            }
                            new_ands.push(Or::new([And::new(constraints)]))
                        }
                        RegionConstraint::new_from_or(new_ands.into_iter().fold(Or::new_false(),
                                |acc, c| Or::build_or(acc, c)))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:724",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(724u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
725fn compute_new_region_constraints<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
726    infcx: &Infcx,
727    constraint: RegionConstraint<I>,
728    u: UniverseIndex,
729) -> RegionConstraint<I> {
730    use LeafRegionConstraint::*;
731
732    let extend_from_and = |builder: &mut TransitiveRelationBuilder<_>,
733                           regions: &mut IndexSet<_>,
734                           constraints: &mut Vec<_>,
735                           and: &And<I>| {
736        for (c, NoSpan) in &and.0 {
737            match c {
738                Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
739                    constraints.push((c.clone(), NoSpan))
740                }
741                RegionOutlives(r1, r2) => {
742                    regions.insert(*r1);
743                    regions.insert(*r2);
744                    builder.add(*r2, *r1);
745                }
746            }
747        }
748    };
749
750    let mut base_region_flows_builder = TransitiveRelationBuilder::default();
751    let mut base_regions = IndexSet::new();
752    let mut base_constraints = Vec::new();
753    extend_from_and(
754        &mut base_region_flows_builder,
755        &mut base_regions,
756        &mut base_constraints,
757        &constraint.and_constraint,
758    );
759
760    let mut new_ands = Vec::new();
761    for and in &constraint.or_constraint.0 {
762        let mut region_flows_builder = base_region_flows_builder.clone();
763        let mut regions = base_regions.clone();
764        let mut constraints = base_constraints.clone();
765        extend_from_and(&mut region_flows_builder, &mut regions, &mut constraints, and);
766
767        let region_flow = region_flows_builder.freeze();
768        for r in regions.into_iter() {
769            for ub in region_flow.reachable_from(r) {
770                // we want to retain any region constraints between two "placeholder-likes" where for our
771                // purposes a placeholder-like is either a placeholder or variable in a lower universe
772                let is_placeholder_like = |r: Region<I>| match r.kind() {
773                    RegionKind::ReLateParam(..)
774                    | RegionKind::ReEarlyParam(..)
775                    | RegionKind::RePlaceholder(..)
776                    | RegionKind::ReStatic => true,
777                    RegionKind::ReVar(..) => max_universe(infcx, r) < u,
778                    RegionKind::ReError(..) => false,
779                    RegionKind::ReErased | RegionKind::ReBound(..) => unreachable!(),
780                };
781
782                if is_placeholder_like(r) && is_placeholder_like(ub) {
783                    constraints.push((RegionOutlives(ub, r), NoSpan));
784                }
785            }
786        }
787
788        new_ands.push(Or::new([And::new(constraints)]))
789    }
790
791    // FIXME(-Zassumptions-on-binders): probably bad for perf!
792    RegionConstraint::new_from_or(
793        new_ands.into_iter().fold(Or::new_false(), |acc, c| Or::build_or(acc, c)),
794    )
795}
796
797/// Handles converting region outlives constraints involving placeholders from `u` into OR constraints
798/// involving regions from smaller universes with known relationships to the placeholder. For example:
799/// ```ignore (not rust)
800/// for<'a, 'b> where(
801///     'c: 'b, 'd: 'b,
802///     'a: 'e, 'a: 'f,
803/// ) {
804///     'a_u1: 'b_u1
805/// }
806/// ```
807/// will get converted to:
808/// ```ignore (not rust)
809/// OR(
810///     'e: 'c,
811///     'e: 'd,
812///     'f: 'c,
813///     'f: 'd,
814/// )
815/// ```
816/// if we are handling constraints in `u1`.
817{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("pull_region_outlives_constraints_out_of_universe",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(817u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("constraint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("constraint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: RegionConstraint<I> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if !(max_universe(infcx, constraint.clone()) <= u) {
                            ::core::panicking::panic("assertion failed: max_universe(infcx, constraint.clone()) <= u")
                        };
                        use LeafRegionConstraint::*;
                        let pull_and =
                            |and: And<I>|
                                {
                                    let mut pulled_constraints = Vec::new();
                                    for (c, span) in and.0 {
                                        match c {
                                            Ambiguity | PlaceholderTyOutlives(..) |
                                                AliasTyOutlivesViaEnv(..) => {
                                                if !(max_universe(infcx, c.clone()) < u) {
                                                    ::core::panicking::panic("assertion failed: max_universe(infcx, c.clone()) < u")
                                                };
                                                pulled_constraints.push(Or::new_leaf(c, span));
                                            }
                                            RegionOutlives(region_1, region_2) => {
                                                let region_1_u = max_universe(infcx, region_1);
                                                let region_2_u = max_universe(infcx, region_2);
                                                if region_1_u != u && region_2_u != u {
                                                    pulled_constraints.push(Or::new_leaf(c, span));
                                                    continue;
                                                }
                                                if regions_outlived_by(region_1,
                                                            assumptions).any(|r| r == region_2) {
                                                    continue;
                                                }
                                                let mut candidates = ::alloc::vec::Vec::new();
                                                for ub in
                                                    regions_outlived_by(region_1,
                                                            assumptions).filter(|r| max_universe(infcx, *r) < u) {
                                                    for lb in
                                                        regions_outliving(region_2, assumptions,
                                                                infcx.cx()).filter(|r| max_universe(infcx, *r) < u) {
                                                        candidates.push((RegionOutlives(ub, lb), NoSpan));
                                                    }
                                                }
                                                pulled_constraints.push(Or::new(candidates.into_iter().map(|c|
                                                                And::new([c]))));
                                            }
                                        };
                                    }
                                    pulled_constraints.into_iter().fold(Or::new_true(),
                                        |acc, c| Or::build_and(acc, c))
                                };
                        let and_constraint = pull_and(constraint.and_constraint);
                        let or_constraint =
                            constraint.or_constraint.0.into_iter().fold(Or::new_false(),
                                |acc, c| Or::build_or(acc, pull_and(c)));
                        RegionConstraint::new_from_or(Or::build_and(and_constraint,
                                or_constraint))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:817",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(817u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
818fn pull_region_outlives_constraints_out_of_universe<
819    Infcx: InferCtxtLike<Interner = I>,
820    I: Interner,
821>(
822    infcx: &Infcx,
823    constraint: RegionConstraint<I>,
824    u: UniverseIndex,
825    assumptions: &Assumptions<I>,
826) -> RegionConstraint<I> {
827    assert!(max_universe(infcx, constraint.clone()) <= u);
828
829    // FIXME(-Zassumptions-on-binders): we don't lower universes of region variables when exiting `u`
830    // this seems dubious/potentially wrong? we can't just blindly do this though as if we had something
831    // like `!T_u -> ?x_u -> !U_u` then lowering `?x` to `u-1` when exiting `u` would be wrong.
832    //
833    // I'm not even sure this would be necessary given we filter out region constraints involving regions#
834    // from the current universe and only retain those between placeholders.
835
836    use LeafRegionConstraint::*;
837
838    let pull_and = |and: And<I>| {
839        let mut pulled_constraints = Vec::new();
840        for (c, span) in and.0 {
841            match c {
842                Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
843                    assert!(max_universe(infcx, c.clone()) < u);
844                    pulled_constraints.push(Or::new_leaf(c, span));
845                }
846                RegionOutlives(region_1, region_2) => {
847                    let region_1_u = max_universe(infcx, region_1);
848                    let region_2_u = max_universe(infcx, region_2);
849
850                    if region_1_u != u && region_2_u != u {
851                        pulled_constraints.push(Or::new_leaf(c, span));
852                        continue;
853                    }
854
855                    // The constraint may already be entailed by the assumptions of the binder we are
856                    // leaving, e.g. `for<'a, 'b> where 'b: 'a { 'b: 'a }`. There is nothing to lift into
857                    // a smaller universe in that case, and looking for lower universe candidates would
858                    // wrongly result in `Or([])` whenever the placeholders have no lower universe bounds.
859                    if regions_outlived_by(region_1, assumptions).any(|r| r == region_2) {
860                        continue;
861                    }
862
863                    let mut candidates = vec![];
864
865                    for ub in regions_outlived_by(region_1, assumptions)
866                        .filter(|r| max_universe(infcx, *r) < u)
867                    {
868                        // FIXME(-Zassumptions-on-binders): if `region_2` is in a smaller universe there'll be both
869                        // `'region_2` and `'static` as lower bounds which seems... unfortunate and may cause us to
870                        // add a bunch of duplicate `'ub: 'static` candidates the more binders we leave.
871                        for lb in regions_outliving(region_2, assumptions, infcx.cx())
872                            .filter(|r| max_universe(infcx, *r) < u)
873                        {
874                            // As long as any region outlived by `region_1` outlives any region region which
875                            // `region_2` outlives, we know that `region_1: region_2` holds. In other words,
876                            // there exists some set of 4 regions for which `'r1: 'i1` `'i1: 'i2` `'i2: 'r2`
877                            candidates.push((RegionOutlives(ub, lb), NoSpan));
878                        }
879                    }
880
881                    pulled_constraints.push(Or::new(candidates.into_iter().map(|c| And::new([c]))));
882                }
883            };
884        }
885
886        pulled_constraints.into_iter().fold(Or::new_true(), |acc, c| Or::build_and(acc, c))
887    };
888
889    let and_constraint = pull_and(constraint.and_constraint);
890    let or_constraint = constraint
891        .or_constraint
892        .0
893        .into_iter()
894        .fold(Or::new_false(), |acc, c| Or::build_or(acc, pull_and(c)));
895    RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint))
896}
897
898#[automatically_derived]
impl<I: Interner, S: Clone + std::fmt::Debug> ::core::fmt::Debug for
    RootDestructuredConstraints<I, S> where I: Interner, S: ::core::fmt::Debug
    {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            RootDestructuredConstraints {
                constraint: ref __field_constraint,
                failing_leafs: ref __field_failing_leafs } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f,
                        "RootDestructuredConstraints");
                ::core::fmt::DebugStruct::field(&mut __builder, "constraint",
                    __field_constraint);
                ::core::fmt::DebugStruct::field(&mut __builder,
                    "failing_leafs", __field_failing_leafs);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Debug; I: Interner, S)]
899pub struct RootDestructuredConstraints<I: Interner, S: Clone + std::fmt::Debug> {
900    pub constraint: RegionConstraint<I, S>,
901    pub failing_leafs: Vec<(LeafRegionConstraint<I>, S)>,
902}
903
904/// Converts type outlives constraints into region outlives constraints. This assumes the *complete* set of
905/// assumptions are known. This should not be called until the end of type checking.
906///
907/// The returned region constraint will not have *any* PlaceholderTyOutlives or AliasTyOutlivesViaEnv constraints.
908{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("destructure_type_outlives_constraints_in_root",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(908u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("constraint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("constraint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                RootDestructuredConstraints<I, S> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use LeafRegionConstraint::*;
                        let mut failing_leafs: Vec<(LeafRegionConstraint<I>, S)> =
                            ::alloc::vec::Vec::new();
                        let mut destructure_and =
                            |and: &And<I, S>|
                                {
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:922",
                                                            "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(922u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("rewriting and: {0:?}",
                                                                                        and) as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let mut destructured_constraints = Vec::new();
                                    for (c, span) in &and.0 {
                                        match c {
                                            Ambiguity | RegionOutlives(..) => {
                                                destructured_constraints.push(Or::new_leaf(c.clone(),
                                                        span.clone()))
                                            }
                                            PlaceholderTyOutlives(ty, r) => {
                                                let contents =
                                                    Or::new(regions_outlived_by_placeholder(*ty, assumptions,
                                                                infcx.cx()).map(move |assumption_r|
                                                                {
                                                                    And::new([(RegionOutlives(assumption_r, *r), span.clone())])
                                                                }));
                                                if contents.is_false() {
                                                    failing_leafs.push((c.clone(), span.clone()));
                                                }
                                                destructured_constraints.push(contents)
                                            }
                                            AliasTyOutlivesViaEnv(bound_outlives) => {
                                                let content =
                                                    alias_outlives_candidates_from_assumptions(infcx,
                                                            *bound_outlives, assumptions).with_spans(span.clone());
                                                if content.is_false() {
                                                    failing_leafs.push((c.clone(), span.clone()));
                                                }
                                                destructured_constraints.push(content);
                                            }
                                        }
                                    }
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:955",
                                                            "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(955u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("destructured_constraints")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("destructured_constraints");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&destructured_constraints)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let merged_constraints =
                                        destructured_constraints.into_iter().fold(Or::new_true(),
                                            |acc, c| Or::build_and(acc, c));
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:959",
                                                            "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(959u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("merged_constraints")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("merged_constraints");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&merged_constraints)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    merged_constraints
                                };
                        let and_constraint =
                            destructure_and(&constraint.and_constraint);
                        let or_constraint =
                            constraint.or_constraint.0.into_iter().fold(Or::new_false(),
                                |acc, c| Or::build_or(acc, destructure_and(&c)));
                        RootDestructuredConstraints {
                            constraint: RegionConstraint::new_from_or(Or::build_and(and_constraint,
                                    or_constraint)),
                            failing_leafs,
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:908",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(908u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
909pub fn destructure_type_outlives_constraints_in_root<
910    Infcx: InferCtxtLike<Interner = I>,
911    I: Interner,
912    S: ConstraintSpan,
913>(
914    infcx: &Infcx,
915    constraint: RegionConstraint<I, S>,
916    assumptions: &Assumptions<I>,
917) -> RootDestructuredConstraints<I, S> {
918    use LeafRegionConstraint::*;
919
920    let mut failing_leafs: Vec<(LeafRegionConstraint<I>, S)> = vec![];
921    let mut destructure_and = |and: &And<I, S>| {
922        debug!("rewriting and: {:?}", and);
923        let mut destructured_constraints = Vec::new();
924        for (c, span) in &and.0 {
925            match c {
926                Ambiguity | RegionOutlives(..) => {
927                    destructured_constraints.push(Or::new_leaf(c.clone(), span.clone()))
928                }
929                PlaceholderTyOutlives(ty, r) => {
930                    let contents =
931                        Or::new(regions_outlived_by_placeholder(*ty, assumptions, infcx.cx()).map(
932                            move |assumption_r| {
933                                And::new([(RegionOutlives(assumption_r, *r), span.clone())])
934                            },
935                        ));
936                    if contents.is_false() {
937                        failing_leafs.push((c.clone(), span.clone()));
938                    }
939                    destructured_constraints.push(contents)
940                }
941                AliasTyOutlivesViaEnv(bound_outlives) => {
942                    let content = alias_outlives_candidates_from_assumptions(
943                        infcx,
944                        *bound_outlives,
945                        assumptions,
946                    )
947                    .with_spans(span.clone());
948                    if content.is_false() {
949                        failing_leafs.push((c.clone(), span.clone()));
950                    }
951                    destructured_constraints.push(content);
952                }
953            }
954        }
955        debug!(?destructured_constraints);
956        let merged_constraints = destructured_constraints
957            .into_iter()
958            .fold(Or::new_true(), |acc, c| Or::build_and(acc, c));
959        debug!(?merged_constraints);
960        merged_constraints
961    };
962
963    let and_constraint = destructure_and(&constraint.and_constraint);
964    let or_constraint = constraint
965        .or_constraint
966        .0
967        .into_iter()
968        .fold(Or::new_false(), |acc, c| Or::build_or(acc, destructure_and(&c)));
969
970    RootDestructuredConstraints {
971        constraint: RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint)),
972        failing_leafs,
973    }
974}
975
976/// Converts type outlives constraints into either region outlives constraints, or type outlives
977/// constraints which do not contain anything from `u`.
978///
979/// This only works off assumptions associated with the binder corresponding to `u` both for
980/// perf reasons and because the full set of region assumptions is not known during type checking
981/// due to closure signature inference.
982///
983/// This only really causes problems for higher-ranked outlives assumptions, for example if we have
984/// `where for<'a> <T as Trait<'a>>::Assoc: 'b` then we can't use that to prove `<T as Trait<'!c>>::Assoc: 'b`
985/// until we are in the root context. See comments inside this function for more detail.
986{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(986u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("constraint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("constraint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: RegionConstraint<I> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use LeafRegionConstraint::*;
                        if !(max_universe(infcx, constraint.clone()) <= u) {
                            {
                                ::core::panicking::panic_fmt(format_args!("constraint {0:?} contains terms from a larger universe than {1:?}",
                                        constraint.clone(), u));
                            }
                        };
                        let rewrite_and =
                            |and: And<I>|
                                {
                                    let mut rewritten_constraints = Vec::new();
                                    for (c, NoSpan) in and.0 {
                                        match c {
                                            Ambiguity | RegionOutlives(..) => {
                                                rewritten_constraints.push(Or::new_leaf(c, NoSpan))
                                            }
                                            PlaceholderTyOutlives(ty, region) => {
                                                rewritten_constraints.push(rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx,
                                                        ty, region, u, assumptions));
                                            }
                                            AliasTyOutlivesViaEnv(bound_outlives) => {
                                                rewritten_constraints.push(rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx,
                                                        bound_outlives, u, assumptions));
                                            }
                                        }
                                    }
                                    rewritten_constraints.into_iter().fold(Or::new_true(),
                                        |acc, c| Or::build_and(acc, c))
                                };
                        let and_constraint = rewrite_and(constraint.and_constraint);
                        let or_constraint =
                            constraint.or_constraint.0.into_iter().fold(Or::new_false(),
                                |acc, c| Or::build_or(acc, rewrite_and(c)));
                        RegionConstraint::new_from_or(Or::build_and(and_constraint,
                                or_constraint))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:986",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(986u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
987fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<
988    Infcx: InferCtxtLike<Interner = I>,
989    I: Interner,
990>(
991    infcx: &Infcx,
992    constraint: RegionConstraint<I>,
993    u: UniverseIndex,
994    assumptions: &Assumptions<I>,
995) -> RegionConstraint<I> {
996    use LeafRegionConstraint::*;
997
998    assert!(
999        max_universe(infcx, constraint.clone()) <= u,
1000        "constraint {:?} contains terms from a larger universe than {:?}",
1001        constraint.clone(),
1002        u
1003    );
1004
1005    let rewrite_and = |and: And<I>| {
1006        let mut rewritten_constraints = Vec::new();
1007        for (c, NoSpan) in and.0 {
1008            match c {
1009                Ambiguity | RegionOutlives(..) => {
1010                    rewritten_constraints.push(Or::new_leaf(c, NoSpan))
1011                }
1012                PlaceholderTyOutlives(ty, region) => {
1013                    rewritten_constraints.push(rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx, ty, region, u, assumptions));
1014                }
1015                AliasTyOutlivesViaEnv(bound_outlives) => {
1016                    rewritten_constraints.push(rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx, bound_outlives, u, assumptions));
1017                }
1018            }
1019        }
1020        rewritten_constraints.into_iter().fold(Or::new_true(), |acc, c| Or::build_and(acc, c))
1021    };
1022
1023    let and_constraint = rewrite_and(constraint.and_constraint);
1024    let or_constraint = constraint
1025        .or_constraint
1026        .0
1027        .into_iter()
1028        .fold(Or::new_false(), |acc, c| Or::build_or(acc, rewrite_and(c)));
1029
1030    RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint))
1031}
1032
1033{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(1033u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("ty")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("ty");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("region")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("region");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&region)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: Or<I> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use LeafRegionConstraint::*;
                        let ty_u = max_universe(infcx, ty);
                        let region_u = max_universe(infcx, region);
                        if region_u != u && ty_u != u {
                            return Or::new_leaf(PlaceholderTyOutlives(ty, region),
                                    NoSpan);
                        }
                        let mut candidates = ::alloc::vec::Vec::new();
                        candidates.extend(regions_outlived_by_placeholder(ty,
                                    assumptions,
                                    infcx.cx()).map(move |assumption_r|
                                    RegionOutlives(assumption_r, region)));
                        if region_u == u && ty_u < u {
                            candidates.extend(regions_outliving::<I>(region,
                                            assumptions,
                                            infcx.cx()).filter(|r|
                                            max_universe(infcx, *r) <
                                                u).map(|r| PlaceholderTyOutlives(ty, r)));
                        }
                        Or::new(candidates.into_iter().map(|c|
                                    And::new([(c, NoSpan)])))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:1033",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(1033u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
1034fn rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling<
1035    Infcx: InferCtxtLike<Interner = I>,
1036    I: Interner,
1037>(
1038    infcx: &Infcx,
1039    ty: I::Ty,
1040    region: Region<I>,
1041    u: UniverseIndex,
1042    assumptions: &Assumptions<I>,
1043) -> Or<I> {
1044    use LeafRegionConstraint::*;
1045
1046    let ty_u = max_universe(infcx, ty);
1047    let region_u = max_universe(infcx, region);
1048
1049    if region_u != u && ty_u != u {
1050        return Or::new_leaf(PlaceholderTyOutlives(ty, region), NoSpan);
1051    }
1052
1053    let mut candidates = vec![];
1054
1055    // There could be `!T: 'region` assumptions in the env even if `!T` is in a
1056    // smaller universe
1057    candidates.extend(
1058        regions_outlived_by_placeholder(ty, assumptions, infcx.cx())
1059            .map(move |assumption_r| RegionOutlives(assumption_r, region)),
1060    );
1061
1062    // We can express `!T: 'region` as `!T: 'r` where `'r: 'region`. This is only necessary
1063    // if the placeholder type is in a smaller universe as otherwise we know all regions which
1064    // the placeholder outlives and can just destructure into an OR of RegionOutlives.
1065    if region_u == u && ty_u < u {
1066        candidates.extend(
1067            regions_outliving::<I>(region, assumptions, infcx.cx())
1068                .filter(|r| max_universe(infcx, *r) < u)
1069                .map(|r| PlaceholderTyOutlives(ty, r)),
1070        );
1071    }
1072
1073    Or::new(candidates.into_iter().map(|c| And::new([(c, NoSpan)])))
1074}
1075
1076{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handling",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(1076u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("bound_outlives")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("bound_outlives");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("u")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("u");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_outlives)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&u)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: Or<I> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use LeafRegionConstraint::*;
                        if max_universe(infcx, bound_outlives) != u {
                            return Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives),
                                    NoSpan);
                        }
                        let mut candidates = Vec::new();
                        let higher_ranked_candidate_for_outlived_region =
                            |region|
                                {
                                    let bound_outlives =
                                        bound_outlives.map_bound(|(alias, _)| (alias, region));
                                    let mut replacer =
                                        MakeHigherRankederer {
                                            cx: infcx,
                                            preexisting_var_count: bound_outlives.bound_vars().len(),
                                            regions: IndexMap::default(),
                                            universe: u,
                                            current_index: DebruijnIndex::ZERO,
                                        };
                                    let escaping_outlives =
                                        bound_outlives.skip_binder().fold_with(&mut replacer);
                                    let bound_vars = bound_outlives.bound_vars();
                                    let bound_vars =
                                        bound_vars.iter().chain(core::mem::take(&mut replacer.regions).into_iter().map(|(_,
                                                        bound_region)|
                                                    BoundVariableKind::Region(bound_region.kind)));
                                    let bound_outlives =
                                        Binder::bind_with_vars(escaping_outlives,
                                            I::BoundVarKinds::from_vars(infcx.cx(), bound_vars));
                                    if max_universe(infcx, bound_outlives) == u {
                                        return Or::new_ambig(NoSpan);
                                    }
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:1135",
                                                            "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(1135u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("higher ranked candidate: {0:?}",
                                                                                        bound_outlives) as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives), NoSpan)
                                };
                        let escaping_r = bound_outlives.skip_binder().1;
                        if max_universe(infcx, escaping_r) < u ||
                                escaping_r.has_escaping_bound_vars() {
                            candidates.push(higher_ranked_candidate_for_outlived_region(escaping_r))
                        } else {
                            for r in
                                regions_outliving(escaping_r, assumptions, infcx.cx()) {
                                candidates.push(higher_ranked_candidate_for_outlived_region(r));
                            }
                        };
                        candidates.push(alias_outlives_candidates_from_assumptions(infcx,
                                bound_outlives, assumptions));
                        match infcx.typing_mode_raw() {
                            TypingMode::Coherence =>
                                candidates.push(Or::new_ambig(NoSpan)),
                            TypingMode::Typeck { .. } | TypingMode::Reflection |
                                TypingMode::ErasedNotCoherence { .. } |
                                TypingMode::PostTypeckThroughBorrowck { .. } |
                                TypingMode::PostBorrowck { .. } | TypingMode::PostAnalysis |
                                TypingMode::Codegen => (),
                        };
                        candidates.into_iter().fold(Or::new_false(),
                            |acc, c| Or::build_or(acc, c))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:1076",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(1076u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
1077fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handling<
1078    Infcx: InferCtxtLike<Interner = I>,
1079    I: Interner,
1080>(
1081    infcx: &Infcx,
1082    bound_outlives: Binder<I, (AliasTy<I>, Region<I>)>,
1083    u: UniverseIndex,
1084    assumptions: &Assumptions<I>,
1085) -> Or<I> {
1086    use LeafRegionConstraint::*;
1087
1088    if max_universe(infcx, bound_outlives) != u {
1089        return Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives), NoSpan);
1090    }
1091
1092    let mut candidates = Vec::new();
1093
1094    // given there can be higher ranked assumptions, e.g. `for<'a> <T as Trait<'a>>::Assoc: 'c`, that
1095    // means that it's actually *always* possible for an alias outlive to be satisfied in the root universe
1096    // which means there should *always* be atleast one candidate when destructuring alias outlives.
1097    //
1098    // we dont care about this for region outlives as `for<'a> 'a: 'b` can't exist as we don't elaborate
1099    // higher ranked type outlives assumptions into higher ranked region outlives assumptions. similarly,
1100    // we don't care about `for<'a> Foo<'a>: 'b` as we always destructure adts into their components and if
1101    // we dont equivalently elaborate the assumption into assumptions on the adt's components we just drop the
1102    // assumptions
1103    //
1104    // so actually only `for<'a, 'b> Alias<'a>: 'b` and `for<'a> T: 'a` are assumptions we actually need to
1105    // handle.
1106    let higher_ranked_candidate_for_outlived_region = |region| {
1107        let bound_outlives = bound_outlives.map_bound(|(alias, _)| (alias, region));
1108
1109        let mut replacer = MakeHigherRankederer {
1110            cx: infcx,
1111            preexisting_var_count: bound_outlives.bound_vars().len(),
1112            regions: IndexMap::default(),
1113            universe: u,
1114            current_index: DebruijnIndex::ZERO,
1115        };
1116        let escaping_outlives = bound_outlives.skip_binder().fold_with(&mut replacer);
1117        let bound_vars = bound_outlives.bound_vars();
1118        let bound_vars = bound_vars.iter().chain(
1119            core::mem::take(&mut replacer.regions)
1120                .into_iter()
1121                .map(|(_, bound_region)| BoundVariableKind::Region(bound_region.kind)),
1122        );
1123        let bound_outlives = Binder::bind_with_vars(
1124            escaping_outlives,
1125            I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
1126        );
1127
1128        // `MakeHigherRankederer` only folds regions. A non-lifetime binder can leave
1129        // a placeholder type in `u`, so this type-outlives constraint cannot be
1130        // handled by the region-outlives-only eager placeholder machinery.
1131        if max_universe(infcx, bound_outlives) == u {
1132            return Or::new_ambig(NoSpan);
1133        }
1134
1135        debug!("higher ranked candidate: {bound_outlives:?}");
1136        Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives), NoSpan)
1137    };
1138
1139    // We elaborate something like `Alias<'a_u2>: 'b_u2` into alias outlives involving each
1140    // region which is known to outlive `'b_u2`. So e.g. if `'c_u2: 'b_u2` is known to hold
1141    // would wind up looking at `Alias<'a_u2>: 'c_u2` as well as `Alias<'a_u2>: 'b_u2`.
1142    //
1143    // This is important in two cases. First, if the outliving region is in a lower universe then
1144    // we've successfully lowered the universe of one of the terms in our alias outlives constraint.
1145    //
1146    // Secondly, if it's a region in the current universe *and* it's a region in the components of the
1147    // alias then we get a less general constraint after replacing with bound vars compared to if we
1148    // had just replaced the initial region. See `assumptions_on_binders/alias_outlives_with_repeated_placeholder.rs`
1149    let escaping_r = bound_outlives.skip_binder().1;
1150    if max_universe(infcx, escaping_r) < u || escaping_r.has_escaping_bound_vars() {
1151        // we don't know anything about lower universe regions, and we also don't bother
1152        // looking at the assumptions on the `AliasTyOutlivesViaEnv` binder.
1153        candidates.push(higher_ranked_candidate_for_outlived_region(escaping_r))
1154    } else {
1155        for r in regions_outliving(escaping_r, assumptions, infcx.cx()) {
1156            candidates.push(higher_ranked_candidate_for_outlived_region(r));
1157        }
1158    };
1159
1160    // Actually look at the assumptions and matching our higher ranked alias outlives goal
1161    // against potentially higher ranked type outlives assumptions.
1162    candidates.push(alias_outlives_candidates_from_assumptions(infcx, bound_outlives, assumptions));
1163
1164    // I'm not convinced our handling here is *complete* so for now
1165    // let's be conservative and not let alias outlives' cause NoSolution
1166    // in coherence
1167    match infcx.typing_mode_raw() {
1168        TypingMode::Coherence => candidates.push(Or::new_ambig(NoSpan)),
1169        TypingMode::Typeck { .. }
1170        | TypingMode::Reflection
1171        | TypingMode::ErasedNotCoherence { .. }
1172        | TypingMode::PostTypeckThroughBorrowck { .. }
1173        | TypingMode::PostBorrowck { .. }
1174        | TypingMode::PostAnalysis
1175        | TypingMode::Codegen => (),
1176    };
1177
1178    candidates.into_iter().fold(Or::new_false(), |acc, c| Or::build_or(acc, c))
1179}
1180
1181/// Returns all regions `r2` for which `r: r2` is known to hold in
1182/// the universe associated with `assumptions`
1183pub fn regions_outlived_by<I: Interner>(
1184    r: Region<I>,
1185    assumptions: &Assumptions<I>,
1186) -> impl Iterator<Item = Region<I>> {
1187    assumptions.region_outlives.reachable_from(r).into_iter().chain([r])
1188}
1189
1190/// Returns all regions `r2` for which `r2: r` is known to hold in
1191/// the universe associated with `assumptions`
1192pub fn regions_outliving<I: Interner>(
1193    r: Region<I>,
1194    assumptions: &Assumptions<I>,
1195    cx: I,
1196) -> impl Iterator<Item = Region<I>> {
1197    assumptions
1198        .inverse_region_outlives
1199        .reachable_from(r)
1200        .into_iter()
1201        // FIXME(-Zassumptions-on-binders): 'static may have been an input region canonicalized to something else is that important?
1202        // FIXME(-Zassumptions-on-binders): do we need to adding the reflexive edge here?
1203        .chain([r, Region::new_static(cx)])
1204}
1205
1206/// Returns all regions `r` for which `!t: r` is known to hold in
1207/// the universe associated with `assumptions`
1208pub fn regions_outlived_by_placeholder<I: Interner>(
1209    t: I::Ty,
1210    assumptions: &Assumptions<I>,
1211    cx: I,
1212) -> impl Iterator<Item = Region<I>> {
1213    match t.kind() {
1214        TyKind::Placeholder(..) | TyKind::Param(..) => (),
1215        _ => {
    ::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:?}"),
1216    }
1217
1218    assumptions.type_outlives.iter().flat_map(move |binder| match binder.no_bound_vars() {
1219        Some(OutlivesClause(ty, r)) => (ty == t).then_some(r),
1220        None => Some(Region::new_static(cx)),
1221    })
1222}
1223
1224pub struct MakeHigherRankederer<'a, I: Interner, Infcx: InferCtxtLike<Interner = I>> {
1225    cx: &'a Infcx,
1226    preexisting_var_count: usize,
1227    regions: IndexMap<Region<I>, BoundRegion<I>>,
1228    universe: UniverseIndex,
1229    current_index: DebruijnIndex,
1230}
1231
1232impl<'a, I: Interner, Infcx: InferCtxtLike<Interner = I>> MakeHigherRankederer<'a, I, Infcx> {
1233    fn existing_var_count(&self) -> usize {
1234        self.preexisting_var_count + self.regions.len()
1235    }
1236}
1237
1238impl<'a, I: Interner, Infcx: InferCtxtLike<Interner = I>> TypeFolder<I>
1239    for MakeHigherRankederer<'a, I, Infcx>
1240{
1241    fn cx(&self) -> I {
1242        self.cx.cx()
1243    }
1244
1245    fn fold_region(&mut self, r: Region<I>) -> Region<I> {
1246        let cx = self.cx();
1247
1248        match r.kind() {
1249            RegionKind::RePlaceholder(p) if p.universe == self.universe => {
1250                let existing_var_count = self.existing_var_count();
1251                let mapped_var = self.regions.entry(r).or_insert(BoundRegion {
1252                    var: BoundVar::from_usize(existing_var_count),
1253                    kind: p.bound.kind,
1254                });
1255                Region::new_bound(cx, self.current_index, *mapped_var)
1256            }
1257            RegionKind::ReVar(inf) => {
1258                let u = self.cx.universe_of_region(inf).unwrap();
1259                if u == self.universe {
1260                    let existing_var_count = self.existing_var_count();
1261                    let mapped_var = self.regions.entry(r).or_insert(BoundRegion {
1262                        var: BoundVar::from_usize(existing_var_count),
1263                        kind: BoundRegionKind::Anon,
1264                    });
1265                    Region::new_bound(cx, self.current_index, *mapped_var)
1266                } else {
1267                    r
1268                }
1269            }
1270            _ => r,
1271        }
1272    }
1273
1274    fn fold_binder<T: TypeFoldable<I>>(&mut self, b: Binder<I, T>) -> Binder<I, T> {
1275        self.current_index.shift_in(1);
1276        let b = b.super_fold_with(self);
1277        self.current_index.shift_out(1);
1278        b
1279    }
1280}
1281
1282/// Converts an `AliasTyOutlivesViaEnv` constraint into an OR of region outlives constraints by
1283/// matching the alias against any `Alias: 'a` assumptions. This is somewhat tricky as we have a
1284/// potentially higher ranked alias being equated with a potentially higher ranked assumption and
1285/// we don't handle it correctly right now (though it is a somewhat reasonable halfway step).
1286{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("alias_outlives_candidates_from_assumptions",
                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                ::tracing_core::__macro_support::Option::Some(1286u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("bound_outlives")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("bound_outlives");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assumptions")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assumptions");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_outlives)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assumptions)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: Or<I> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let mut candidates = Vec::new();
                        let prev_universe = infcx.universe();
                        infcx.enter_forall_with_empty_assumptions(bound_outlives,
                            |(alias, r)|
                                {
                                    for bound_type_outlives in assumptions.type_outlives.iter()
                                        {
                                        let OutlivesClause(alias2, r2) =
                                            infcx.instantiate_binder_with_infer(*bound_type_outlives);
                                        let mut relation =
                                            HigherRankedAliasMatcher {
                                                infcx,
                                                region_constraints: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                        [LeafRegionConstraint::RegionOutlives(r2, r)])),
                                            };
                                        if let Ok(_) =
                                                relation.relate(set_aliases_to_non_rigid(infcx.cx(),
                                                            alias.to_ty(infcx.cx(), IsRigid::No)).skip_norm_wip(),
                                                    set_aliases_to_non_rigid(infcx.cx(),
                                                            alias2).skip_norm_wip()) {
                                            candidates.push(And::new(relation.region_constraints.into_iter().map(|c|
                                                            (c, NoSpan))));
                                        }
                                    }
                                });
                        let constraint =
                            RegionConstraint::new_from_or(Or::new(candidates));
                        let largest_universe = infcx.universe();
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:1322",
                                                "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                                                ::tracing_core::__macro_support::Option::Some(1322u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("prev_universe")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("prev_universe");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("largest_universe")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("largest_universe");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev_universe)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&largest_universe)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let canonical_constraint =
                            ((prev_universe.index() +
                                                        1)..=largest_universe.index()).map(|u|
                                            UniverseIndex::from_usize(u)).rev().fold(constraint,
                                |constraint, u|
                                    {
                                        eagerly_handle_placeholders_in_universe(infcx, constraint,
                                            u)
                                    });
                        canonical_constraint.splatted_and_constraints()
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs:1286",
                        "rustc_type_ir::region_constraint", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/852931e6d0b2fc1b2f3f353f1f004b77cc02409f/compiler/rustc_type_ir/src/region_constraint.rs"),
                        ::tracing_core::__macro_support::Option::Some(1286u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::region_constraint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(infcx), ret)]
1287fn alias_outlives_candidates_from_assumptions<Infcx: InferCtxtLike<Interner = I>, I: Interner>(
1288    infcx: &Infcx,
1289    bound_outlives: Binder<I, (AliasTy<I>, Region<I>)>,
1290    assumptions: &Assumptions<I>,
1291) -> Or<I> {
1292    let mut candidates = Vec::new();
1293
1294    let prev_universe = infcx.universe();
1295
1296    infcx.enter_forall_with_empty_assumptions(bound_outlives, |(alias, r)| {
1297        for bound_type_outlives in assumptions.type_outlives.iter() {
1298            let OutlivesClause(alias2, r2) =
1299                infcx.instantiate_binder_with_infer(*bound_type_outlives);
1300
1301            let mut relation = HigherRankedAliasMatcher {
1302                infcx,
1303                region_constraints: vec![LeafRegionConstraint::RegionOutlives(r2, r)],
1304            };
1305
1306            // FIXME(#155345): Both sides should be rigid in the future.
1307            // Currently we can't guarantee that.
1308            if let Ok(_) = relation.relate(
1309                set_aliases_to_non_rigid(infcx.cx(), alias.to_ty(infcx.cx(), IsRigid::No))
1310                    .skip_norm_wip(),
1311                set_aliases_to_non_rigid(infcx.cx(), alias2).skip_norm_wip(),
1312            ) {
1313                candidates
1314                    .push(And::new(relation.region_constraints.into_iter().map(|c| (c, NoSpan))));
1315            }
1316        }
1317    });
1318
1319    let constraint = RegionConstraint::new_from_or(Or::new(candidates));
1320
1321    let largest_universe = infcx.universe();
1322    debug!(?prev_universe, ?largest_universe);
1323
1324    let canonical_constraint = ((prev_universe.index() + 1)..=largest_universe.index())
1325        .map(|u| UniverseIndex::from_usize(u))
1326        .rev()
1327        .fold(constraint, |constraint, u| {
1328            eagerly_handle_placeholders_in_universe(infcx, constraint, u)
1329        });
1330
1331    canonical_constraint.splatted_and_constraints()
1332}
1333
1334struct HigherRankedAliasMatcher<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> {
1335    infcx: &'a Infcx,
1336    region_constraints: Vec<LeafRegionConstraint<I>>,
1337}
1338
1339impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeRelation<I>
1340    for HigherRankedAliasMatcher<'a, Infcx, I>
1341{
1342    fn cx(&self) -> I {
1343        self.infcx.cx()
1344    }
1345
1346    fn relate_ty_args(
1347        &mut self,
1348        a_ty: I::Ty,
1349        _b_ty: I::Ty,
1350        _ty_def_id: I::DefId,
1351        a_args: I::GenericArgs,
1352        b_args: I::GenericArgs,
1353        _mk: impl FnOnce(I::GenericArgs) -> I::Ty,
1354    ) -> RelateResult<I, I::Ty> {
1355        rustc_type_ir::relate::relate_args_invariantly(self, a_args, b_args)?;
1356        Ok(a_ty)
1357    }
1358
1359    fn relate_with_variance<T: Relate<I>>(
1360        &mut self,
1361        _variance: Variance,
1362        _info: VarianceDiagInfo<I>,
1363        a: T,
1364        b: T,
1365    ) -> RelateResult<I, T> {
1366        // FIXME(-Zassumptions-on-binders): bivariance is important for opaque type args so
1367        // we should actually handle variance in some way here.
1368        self.relate(a, b)
1369    }
1370
1371    fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult<I, I::Ty> {
1372        rustc_type_ir::relate::structurally_relate_tys(self, a, b)
1373    }
1374
1375    fn regions(&mut self, a: Region<I>, b: Region<I>) -> RelateResult<I, Region<I>> {
1376        if a != b {
1377            self.region_constraints.push(LeafRegionConstraint::RegionOutlives(a, b));
1378            self.region_constraints.push(LeafRegionConstraint::RegionOutlives(b, a));
1379        }
1380        Ok(a)
1381    }
1382
1383    fn consts(&mut self, a: Const<I>, b: Const<I>) -> RelateResult<I, Const<I>> {
1384        rustc_type_ir::relate::structurally_relate_consts(self, a, b)
1385    }
1386
1387    fn binders<T>(&mut self, a: Binder<I, T>, b: Binder<I, T>) -> RelateResult<I, Binder<I, T>>
1388    where
1389        T: Relate<I>,
1390    {
1391        self.infcx.enter_forall_with_empty_assumptions(a, |a| {
1392            let u = self.infcx.universe();
1393            self.infcx.insert_placeholder_assumptions(u, Assumptions::empty());
1394            let b = self.infcx.instantiate_binder_with_infer(b);
1395            self.relate(a, b)
1396        })?;
1397
1398        self.infcx.enter_forall_with_empty_assumptions(b, |b| {
1399            let u = self.infcx.universe();
1400            self.infcx.insert_placeholder_assumptions(u, Assumptions::empty());
1401            let a = self.infcx.instantiate_binder_with_infer(a);
1402            self.relate(a, b)
1403        })?;
1404
1405        Ok(a)
1406    }
1407}