Skip to main content

rustc_infer/infer/region_constraints/
mod.rs

1//! See `README.md`.
2
3use std::ops::Range;
4use std::{cmp, fmt, iter, mem};
5
6use rustc_data_structures::fx::FxHashMap;
7use rustc_data_structures::undo_log::UndoLogs;
8use rustc_data_structures::unify as ut;
9use rustc_index::IndexVec;
10use rustc_macros::{TypeFoldable, TypeVisitable};
11use rustc_middle::ty::{self, ReBound, ReStatic, ReVar, Region, RegionVid, Ty, TyCtxt};
12use rustc_middle::{bug, span_bug};
13use tracing::{debug, instrument};
14
15use self::CombineMapType::*;
16use self::UndoLog::*;
17use super::{RegionVariableOrigin, Rollback, SubregionOrigin};
18use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, Snapshot};
19use crate::infer::unify_key::{RegionVariableValue, RegionVidKey};
20
21mod leak_check;
22
23#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for RegionConstraintStorage<'tcx> {
    #[inline]
    fn clone(&self) -> RegionConstraintStorage<'tcx> {
        RegionConstraintStorage {
            var_infos: ::core::clone::Clone::clone(&self.var_infos),
            data: ::core::clone::Clone::clone(&self.data),
            lubs: ::core::clone::Clone::clone(&self.lubs),
            glbs: ::core::clone::Clone::clone(&self.glbs),
            unification_table: ::core::clone::Clone::clone(&self.unification_table),
            any_unifications: ::core::clone::Clone::clone(&self.any_unifications),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::default::Default for RegionConstraintStorage<'tcx> {
    #[inline]
    fn default() -> RegionConstraintStorage<'tcx> {
        RegionConstraintStorage {
            var_infos: ::core::default::Default::default(),
            data: ::core::default::Default::default(),
            lubs: ::core::default::Default::default(),
            glbs: ::core::default::Default::default(),
            unification_table: ::core::default::Default::default(),
            any_unifications: ::core::default::Default::default(),
        }
    }
}Default)]
24pub struct RegionConstraintStorage<'tcx> {
25    /// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
26    pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo<'tcx>>,
27
28    pub(super) data: RegionConstraintData<'tcx>,
29
30    /// For a given pair of regions (R1, R2), maps to a region R3 that
31    /// is designated as their LUB (edges R1 <= R3 and R2 <= R3
32    /// exist). This prevents us from making many such regions.
33    lubs: CombineMap<'tcx>,
34
35    /// For a given pair of regions (R1, R2), maps to a region R3 that
36    /// is designated as their GLB (edges R3 <= R1 and R3 <= R2
37    /// exist). This prevents us from making many such regions.
38    glbs: CombineMap<'tcx>,
39
40    /// When we add a R1 == R2 constraint, we currently add (a) edges
41    /// R1 <= R2 and R2 <= R1 and (b) we unify the two regions in this
42    /// table. You can then call `opportunistic_resolve_var` early
43    /// which will map R1 and R2 to some common region (i.e., either
44    /// R1 or R2). This is important when fulfillment, dropck and other such
45    /// code is iterating to a fixed point, because otherwise we sometimes
46    /// would wind up with a fresh stream of region variables that have been
47    /// equated but appear distinct.
48    pub(super) unification_table: ut::UnificationTableStorage<RegionVidKey<'tcx>>,
49
50    /// a flag set to true when we perform any unifications; this is used
51    /// to micro-optimize `take_and_reset_data`
52    any_unifications: bool,
53}
54
55pub struct RegionConstraintCollector<'a, 'tcx> {
56    storage: &'a mut RegionConstraintStorage<'tcx>,
57    undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
58}
59
60pub type VarInfos<'tcx> = IndexVec<RegionVid, RegionVariableInfo<'tcx>>;
61
62/// The full set of region constraints gathered up by the collector.
63/// Describes constraints between the region variables and other
64/// regions, as well as other conditions that must be verified, or
65/// assumptions that can be made.
66#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for RegionConstraintData<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "RegionConstraintData", "constraints", &self.constraints,
            "verifys", &&self.verifys)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::default::Default for RegionConstraintData<'tcx> {
    #[inline]
    fn default() -> RegionConstraintData<'tcx> {
        RegionConstraintData {
            constraints: ::core::default::Default::default(),
            verifys: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for RegionConstraintData<'tcx> {
    #[inline]
    fn clone(&self) -> RegionConstraintData<'tcx> {
        RegionConstraintData {
            constraints: ::core::clone::Clone::clone(&self.constraints),
            verifys: ::core::clone::Clone::clone(&self.verifys),
        }
    }
}Clone)]
67pub struct RegionConstraintData<'tcx> {
68    /// Constraints of the form `A <= B`, where either `A` or `B` can
69    /// be a region variable (or neither, as it happens).
70    pub constraints: Vec<(Constraint<'tcx>, SubregionOrigin<'tcx>)>,
71
72    /// A "verify" is something that we need to verify after inference
73    /// is done, but which does not directly affect inference in any
74    /// way.
75    ///
76    /// An example is a `A <= B` where neither `A` nor `B` are
77    /// inference variables.
78    pub verifys: Vec<Verify<'tcx>>,
79}
80
81/// Represents a constraint that influences the inference process.
82#[derive(#[automatically_derived]
impl ::core::clone::Clone for ConstraintKind {
    #[inline]
    fn clone(&self) -> ConstraintKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ConstraintKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for ConstraintKind {
    #[inline]
    fn eq(&self, other: &ConstraintKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ConstraintKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for ConstraintKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ConstraintKind::VarSubVar => "VarSubVar",
                ConstraintKind::RegSubVar => "RegSubVar",
                ConstraintKind::VarSubReg => "VarSubReg",
                ConstraintKind::RegSubReg => "RegSubReg",
                ConstraintKind::VarEqVar => "VarEqVar",
                ConstraintKind::VarEqReg => "VarEqReg",
                ConstraintKind::RegEqReg => "RegEqReg",
            })
    }
}Debug, #[automatically_derived]
impl ::core::hash::Hash for ConstraintKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash)]
83pub enum ConstraintKind {
84    /// A region variable is a subregion of another.
85    VarSubVar,
86
87    /// A concrete region is a subregion of region variable.
88    RegSubVar,
89
90    /// A region variable is a subregion of a concrete region. This does not
91    /// directly affect inference, but instead is checked after
92    /// inference is complete.
93    VarSubReg,
94
95    /// A constraint where neither side is a variable. This does not
96    /// directly affect inference, but instead is checked after
97    /// inference is complete.
98    RegSubReg,
99
100    /// A region variable is equal to another.
101    VarEqVar,
102
103    /// A region variable is equal to a concrete region. This does not
104    /// directly affect inference, but instead is checked after
105    /// inference is complete.
106    VarEqReg,
107
108    /// An equality constraint where neither side is a variable. This does not
109    /// directly affect inference, but instead is checked after
110    /// inference is complete.
111    RegEqReg,
112}
113
114/// Represents a constraint that influences the inference process.
115#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for Constraint<'tcx> {
    #[inline]
    fn clone(&self) -> Constraint<'tcx> {
        let _: ::core::clone::AssertParamIsClone<ConstraintKind>;
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for Constraint<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for Constraint<'tcx> {
    #[inline]
    fn eq(&self, other: &Constraint<'tcx>) -> bool {
        self.kind == other.kind && self.sub == other.sub &&
            self.sup == other.sup
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for Constraint<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<ConstraintKind>;
        let _: ::core::cmp::AssertParamIsEq<Region<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Region<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Constraint<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "Constraint",
            "kind", &self.kind, "sub", &self.sub, "sup", &&self.sup)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for Constraint<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.kind, state);
        ::core::hash::Hash::hash(&self.sub, state);
        ::core::hash::Hash::hash(&self.sup, state)
    }
}Hash)]
116pub struct Constraint<'tcx> {
117    pub kind: ConstraintKind,
118    // If `kind` is `VarSubVar` or `VarSubReg`, this must be a `ReVar`.
119    pub sub: Region<'tcx>,
120    // If `kind` is `VarSubVar` or `RegSubVar`, this must be a `ReVar`.
121    pub sup: Region<'tcx>,
122}
123
124impl Constraint<'_> {
125    pub fn involves_placeholders(&self) -> bool {
126        self.sub.is_placeholder() || self.sup.is_placeholder()
127    }
128
129    pub fn iter_outlives(self) -> impl Iterator<Item = Self> {
130        let Constraint { kind, sub, sup } = self;
131
132        match kind {
133            ConstraintKind::VarSubVar
134            | ConstraintKind::RegSubVar
135            | ConstraintKind::VarSubReg
136            | ConstraintKind::RegSubReg => iter::once(self).chain(None),
137
138            ConstraintKind::VarEqVar => {
139                iter::once(Constraint { kind: ConstraintKind::VarSubVar, sub, sup })
140                    .chain(Some(Constraint { kind: ConstraintKind::VarSubVar, sub: sup, sup: sub }))
141            }
142            ConstraintKind::VarEqReg => {
143                iter::once(Constraint { kind: ConstraintKind::VarSubReg, sub, sup })
144                    .chain(Some(Constraint { kind: ConstraintKind::RegSubVar, sub: sup, sup: sub }))
145            }
146            ConstraintKind::RegEqReg => {
147                iter::once(Constraint { kind: ConstraintKind::RegSubReg, sub, sup })
148                    .chain(Some(Constraint { kind: ConstraintKind::RegSubReg, sub: sup, sup: sub }))
149            }
150        }
151    }
152}
153
154#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Verify<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f, "Verify",
            "kind", &self.kind, "origin", &self.origin, "region",
            &self.region, "bound", &&self.bound)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Verify<'tcx> {
    #[inline]
    fn clone(&self) -> Verify<'tcx> {
        Verify {
            kind: ::core::clone::Clone::clone(&self.kind),
            origin: ::core::clone::Clone::clone(&self.origin),
            region: ::core::clone::Clone::clone(&self.region),
            bound: ::core::clone::Clone::clone(&self.bound),
        }
    }
}Clone)]
155pub struct Verify<'tcx> {
156    pub kind: GenericKind<'tcx>,
157    pub origin: SubregionOrigin<'tcx>,
158    pub region: Region<'tcx>,
159    pub bound: VerifyBound<'tcx>,
160}
161
162#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for GenericKind<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for GenericKind<'tcx> {
    #[inline]
    fn clone(&self) -> GenericKind<'tcx> {
        let _: ::core::clone::AssertParamIsClone<ty::ParamTy>;
        let _: ::core::clone::AssertParamIsClone<ty::PlaceholderType<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<ty::AliasTy<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for GenericKind<'tcx> {
    #[inline]
    fn eq(&self, other: &GenericKind<'tcx>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (GenericKind::Param(__self_0), GenericKind::Param(__arg1_0))
                    => __self_0 == __arg1_0,
                (GenericKind::Placeholder(__self_0),
                    GenericKind::Placeholder(__arg1_0)) => __self_0 == __arg1_0,
                (GenericKind::Alias(__self_0), GenericKind::Alias(__arg1_0))
                    => __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for GenericKind<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<ty::ParamTy>;
        let _: ::core::cmp::AssertParamIsEq<ty::PlaceholderType<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<ty::AliasTy<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for GenericKind<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            GenericKind::Param(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            GenericKind::Placeholder(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            GenericKind::Alias(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
        }
    }
}Hash, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for GenericKind<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        GenericKind::Param(__binding_0) => {
                            GenericKind::Param(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        GenericKind::Placeholder(__binding_0) => {
                            GenericKind::Placeholder(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        GenericKind::Alias(__binding_0) => {
                            GenericKind::Alias(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    GenericKind::Param(__binding_0) => {
                        GenericKind::Param(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    GenericKind::Placeholder(__binding_0) => {
                        GenericKind::Placeholder(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    GenericKind::Alias(__binding_0) => {
                        GenericKind::Alias(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for GenericKind<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    GenericKind::Param(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    GenericKind::Placeholder(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    GenericKind::Alias(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
163pub enum GenericKind<'tcx> {
164    Param(ty::ParamTy),
165    Placeholder(ty::PlaceholderType<'tcx>),
166    Alias(ty::AliasTy<'tcx>),
167}
168
169/// Describes the things that some `GenericKind` value `G` is known to
170/// outlive. Each variant of `VerifyBound` can be thought of as a
171/// function:
172/// ```ignore (pseudo-rust)
173/// fn(min: Region) -> bool { .. }
174/// ```
175/// where `true` means that the region `min` meets that `G: min`.
176/// (False means nothing.)
177///
178/// So, for example, if we have the type `T` and we have in scope that
179/// `T: 'a` and `T: 'b`, then the verify bound might be:
180/// ```ignore (pseudo-rust)
181/// fn(min: Region) -> bool {
182///    ('a: min) || ('b: min)
183/// }
184/// ```
185/// This is described with an `AnyRegion('a, 'b)` node.
186#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for VerifyBound<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            VerifyBound::IfEq(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "IfEq",
                    &__self_0),
            VerifyBound::OutlivedBy(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "OutlivedBy", &__self_0),
            VerifyBound::IsEmpty =>
                ::core::fmt::Formatter::write_str(f, "IsEmpty"),
            VerifyBound::AnyBound(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "AnyBound", &__self_0),
            VerifyBound::AllBounds(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "AllBounds", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for VerifyBound<'tcx> {
    #[inline]
    fn clone(&self) -> VerifyBound<'tcx> {
        match self {
            VerifyBound::IfEq(__self_0) =>
                VerifyBound::IfEq(::core::clone::Clone::clone(__self_0)),
            VerifyBound::OutlivedBy(__self_0) =>
                VerifyBound::OutlivedBy(::core::clone::Clone::clone(__self_0)),
            VerifyBound::IsEmpty => VerifyBound::IsEmpty,
            VerifyBound::AnyBound(__self_0) =>
                VerifyBound::AnyBound(::core::clone::Clone::clone(__self_0)),
            VerifyBound::AllBounds(__self_0) =>
                VerifyBound::AllBounds(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for VerifyBound<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        VerifyBound::IfEq(__binding_0) => {
                            VerifyBound::IfEq(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        VerifyBound::OutlivedBy(__binding_0) => {
                            VerifyBound::OutlivedBy(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        VerifyBound::IsEmpty => { VerifyBound::IsEmpty }
                        VerifyBound::AnyBound(__binding_0) => {
                            VerifyBound::AnyBound(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        VerifyBound::AllBounds(__binding_0) => {
                            VerifyBound::AllBounds(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    VerifyBound::IfEq(__binding_0) => {
                        VerifyBound::IfEq(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    VerifyBound::OutlivedBy(__binding_0) => {
                        VerifyBound::OutlivedBy(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    VerifyBound::IsEmpty => { VerifyBound::IsEmpty }
                    VerifyBound::AnyBound(__binding_0) => {
                        VerifyBound::AnyBound(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    VerifyBound::AllBounds(__binding_0) => {
                        VerifyBound::AllBounds(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for VerifyBound<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    VerifyBound::IfEq(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    VerifyBound::OutlivedBy(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    VerifyBound::IsEmpty => {}
                    VerifyBound::AnyBound(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    VerifyBound::AllBounds(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
187pub enum VerifyBound<'tcx> {
188    /// See [`VerifyIfEq`] docs
189    IfEq(ty::Binder<'tcx, VerifyIfEq<'tcx>>),
190
191    /// Given a region `R`, expands to the function:
192    ///
193    /// ```ignore (pseudo-rust)
194    /// fn(min) -> bool {
195    ///     R: min
196    /// }
197    /// ```
198    ///
199    /// This is used when we can establish that `G: R` -- therefore,
200    /// if `R: min`, then by transitivity `G: min`.
201    OutlivedBy(Region<'tcx>),
202
203    /// Given a region `R`, true if it is `'empty`.
204    IsEmpty,
205
206    /// Given a set of bounds `B`, expands to the function:
207    ///
208    /// ```ignore (pseudo-rust)
209    /// fn(min) -> bool {
210    ///     exists (b in B) { b(min) }
211    /// }
212    /// ```
213    ///
214    /// In other words, if we meet some bound in `B`, that suffices.
215    /// This is used when all the bounds in `B` are known to apply to `G`.
216    AnyBound(Vec<VerifyBound<'tcx>>),
217
218    /// Given a set of bounds `B`, expands to the function:
219    ///
220    /// ```ignore (pseudo-rust)
221    /// fn(min) -> bool {
222    ///     forall (b in B) { b(min) }
223    /// }
224    /// ```
225    ///
226    /// In other words, if we meet *all* bounds in `B`, that suffices.
227    /// This is used when *some* bound in `B` is known to suffice, but
228    /// we don't know which.
229    AllBounds(Vec<VerifyBound<'tcx>>),
230}
231
232/// This is a "conditional bound" that checks the result of inference
233/// and supplies a bound if it ended up being relevant. It's used in situations
234/// like this:
235///
236/// ```rust,ignore (pseudo-Rust)
237/// fn foo<'a, 'b, T: SomeTrait<'a>>
238/// where
239///    <T as SomeTrait<'a>>::Item: 'b
240/// ```
241///
242/// If we have an obligation like `<T as SomeTrait<'?x>>::Item: 'c`, then
243/// we don't know yet whether it suffices to show that `'b: 'c`. If `'?x` winds
244/// up being equal to `'a`, then the where-clauses on function applies, and
245/// in that case we can show `'b: 'c`. But if `'?x` winds up being something
246/// else, the bound isn't relevant.
247///
248/// In the [`VerifyBound`], this struct is enclosed in `Binder` to account
249/// for cases like
250///
251/// ```rust,ignore (pseudo-Rust)
252/// where for<'a> <T as SomeTrait<'a>::Item: 'a
253/// ```
254///
255/// The idea is that we have to find some instantiation of `'a` that can
256/// make `<T as SomeTrait<'a>>::Item` equal to the final value of `G`,
257/// the generic we are checking.
258///
259/// ```ignore (pseudo-rust)
260/// fn(min) -> bool {
261///     exists<'a> {
262///         if G == K {
263///             B(min)
264///         } else {
265///             false
266///         }
267///     }
268/// }
269/// ```
270#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for VerifyIfEq<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "VerifyIfEq",
            "ty", &self.ty, "bound", &&self.bound)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for VerifyIfEq<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for VerifyIfEq<'tcx> {
    #[inline]
    fn clone(&self) -> VerifyIfEq<'tcx> {
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        *self
    }
}Clone, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for VerifyIfEq<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        VerifyIfEq { ty: __binding_0, bound: __binding_1 } => {
                            VerifyIfEq {
                                ty: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                bound: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    VerifyIfEq { ty: __binding_0, bound: __binding_1 } => {
                        VerifyIfEq {
                            ty: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            bound: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for VerifyIfEq<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    VerifyIfEq { ty: ref __binding_0, bound: ref __binding_1 }
                        => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
271pub struct VerifyIfEq<'tcx> {
272    /// Type which must match the generic `G`
273    pub ty: Ty<'tcx>,
274
275    /// Bound that applies if `ty` is equal.
276    pub bound: Region<'tcx>,
277}
278
279#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TwoRegions<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TwoRegions<'tcx> {
    #[inline]
    fn clone(&self) -> TwoRegions<'tcx> {
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for TwoRegions<'tcx> {
    #[inline]
    fn eq(&self, other: &TwoRegions<'tcx>) -> bool {
        self.a == other.a && self.b == other.b
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for TwoRegions<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Region<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Region<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for TwoRegions<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.a, state);
        ::core::hash::Hash::hash(&self.b, state)
    }
}Hash)]
280pub(crate) struct TwoRegions<'tcx> {
281    a: Region<'tcx>,
282    b: Region<'tcx>,
283}
284
285#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for UndoLog<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for UndoLog<'tcx> {
    #[inline]
    fn clone(&self) -> UndoLog<'tcx> {
        let _: ::core::clone::AssertParamIsClone<RegionVid>;
        let _: ::core::clone::AssertParamIsClone<usize>;
        let _: ::core::clone::AssertParamIsClone<CombineMapType>;
        let _: ::core::clone::AssertParamIsClone<TwoRegions<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for UndoLog<'tcx> {
    #[inline]
    fn eq(&self, other: &UndoLog<'tcx>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (UndoLog::AddVar(__self_0), UndoLog::AddVar(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (UndoLog::AddConstraint(__self_0),
                    UndoLog::AddConstraint(__arg1_0)) => __self_0 == __arg1_0,
                (UndoLog::AddVerify(__self_0), UndoLog::AddVerify(__arg1_0))
                    => __self_0 == __arg1_0,
                (UndoLog::AddCombination(__self_0, __self_1),
                    UndoLog::AddCombination(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq)]
286pub(crate) enum UndoLog<'tcx> {
287    /// We added `RegionVid`.
288    AddVar(RegionVid),
289
290    /// We added the given `constraint`.
291    AddConstraint(usize),
292
293    /// We added the given `verify`.
294    AddVerify(usize),
295
296    /// We added a GLB/LUB "combination variable".
297    AddCombination(CombineMapType, TwoRegions<'tcx>),
298}
299
300#[derive(#[automatically_derived]
impl ::core::marker::Copy for CombineMapType { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CombineMapType {
    #[inline]
    fn clone(&self) -> CombineMapType { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for CombineMapType {
    #[inline]
    fn eq(&self, other: &CombineMapType) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq)]
301pub(crate) enum CombineMapType {
302    Lub,
303    Glb,
304}
305
306type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
307
308#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for RegionVariableInfo<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "RegionVariableInfo", "origin", &self.origin, "universe",
            &&self.universe)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for RegionVariableInfo<'tcx> {
    #[inline]
    fn clone(&self) -> RegionVariableInfo<'tcx> {
        let _: ::core::clone::AssertParamIsClone<RegionVariableOrigin<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<ty::UniverseIndex>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for RegionVariableInfo<'tcx> { }Copy)]
309pub struct RegionVariableInfo<'tcx> {
310    pub origin: RegionVariableOrigin<'tcx>,
311    // FIXME: This is only necessary for `fn take_and_reset_data` and
312    // `lexical_region_resolve`. We should rework `lexical_region_resolve`
313    // in the near/medium future anyways and could move the unverse info
314    // for `fn take_and_reset_data` into a separate table which is
315    // only populated when needed.
316    //
317    // For both of these cases it is fine that this can diverge from the
318    // actual universe of the variable, which is directly stored in the
319    // unification table for unknown region variables. At some point we could
320    // stop emitting bidirectional outlives constraints if equate succeeds.
321    // This would be currently unsound as it would cause us to drop the universe
322    // changes in `lexical_region_resolve`.
323    pub universe: ty::UniverseIndex,
324}
325
326pub(crate) struct RegionSnapshot {
327    any_unifications: bool,
328}
329
330impl<'tcx> RegionConstraintStorage<'tcx> {
331    #[inline]
332    pub(crate) fn with_log<'a>(
333        &'a mut self,
334        undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
335    ) -> RegionConstraintCollector<'a, 'tcx> {
336        RegionConstraintCollector { storage: self, undo_log }
337    }
338}
339
340impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
341    pub fn num_region_vars(&self) -> usize {
342        self.storage.var_infos.len()
343    }
344
345    /// Takes (and clears) the current set of constraints. Note that
346    /// the set of variables remains intact, but all relationships
347    /// between them are reset. This is used during NLL checking to
348    /// grab the set of constraints that arose from a particular
349    /// operation.
350    ///
351    /// We don't want to leak relationships between variables between
352    /// points because just because (say) `r1 == r2` was true at some
353    /// point P in the graph doesn't imply that it will be true at
354    /// some other point Q, in NLL.
355    ///
356    /// Not legal during a snapshot.
357    pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx> {
358        if !!UndoLogs::<UndoLog<'_>>::in_snapshot(&self.undo_log) {
    ::core::panicking::panic("assertion failed: !UndoLogs::<UndoLog<\'_>>::in_snapshot(&self.undo_log)")
};assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&self.undo_log));
359
360        // If you add a new field to `RegionConstraintCollector`, you
361        // should think carefully about whether it needs to be cleared
362        // or updated in some way.
363        let RegionConstraintStorage {
364            var_infos: _,
365            data,
366            lubs,
367            glbs,
368            unification_table: _,
369            any_unifications,
370        } = self.storage;
371
372        // Clear the tables of (lubs, glbs), so that we will create
373        // fresh regions if we do a LUB operation. As it happens,
374        // LUB/GLB are not performed by the MIR type-checker, which is
375        // the one that uses this method, but it's good to be correct.
376        lubs.clear();
377        glbs.clear();
378
379        let data = mem::take(data);
380
381        // Clear all unifications and recreate the variables a "now
382        // un-unified" state. Note that when we unify `a` and `b`, we
383        // also insert `a <= b` and a `b <= a` edges, so the
384        // `RegionConstraintData` contains the relationship here.
385        if *any_unifications {
386            *any_unifications = false;
387            // Manually inlined `self.unification_table_mut()` as `self` is used in the closure.
388            ut::UnificationTable::with_log(&mut self.storage.unification_table, &mut self.undo_log)
389                .reset_unifications(|key| RegionVariableValue::Unknown {
390                    universe: self.storage.var_infos[key.vid].universe,
391                });
392        }
393
394        data
395    }
396
397    pub fn data(&self) -> &RegionConstraintData<'tcx> {
398        &self.storage.data
399    }
400
401    pub(super) fn start_snapshot(&self) -> RegionSnapshot {
402        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:402",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(402u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: start_snapshot")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: start_snapshot");
403        RegionSnapshot { any_unifications: self.storage.any_unifications }
404    }
405
406    pub(super) fn rollback_to(&mut self, snapshot: RegionSnapshot) {
407        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:407",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(407u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: rollback_to({0:?})",
                                                    snapshot) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: rollback_to({:?})", snapshot);
408        self.storage.any_unifications = snapshot.any_unifications;
409    }
410
411    pub(super) fn new_region_var(
412        &mut self,
413        universe: ty::UniverseIndex,
414        origin: RegionVariableOrigin<'tcx>,
415    ) -> RegionVid {
416        let vid = self.storage.var_infos.push(RegionVariableInfo { origin, universe });
417
418        let u_vid = self.unification_table_mut().new_key(RegionVariableValue::Unknown { universe });
419        match (&vid, &u_vid.vid) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(vid, u_vid.vid);
420        self.undo_log.push(AddVar(vid));
421        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:421",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(421u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("created new region variable {0:?} in {1:?} with origin {2:?}",
                                                    vid, universe, origin) as &dyn Value))])
            });
    } else { ; }
};debug!("created new region variable {:?} in {:?} with origin {:?}", vid, universe, origin);
422        vid
423    }
424
425    /// Returns the origin for the given variable.
426    pub(super) fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin<'tcx> {
427        self.storage.var_infos[vid].origin
428    }
429
430    fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) {
431        // cannot add constraints once regions are resolved
432        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:432",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(432u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: add_constraint({0:?})",
                                                    constraint) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: add_constraint({:?})", constraint);
433
434        let index = self.storage.data.constraints.len();
435        self.storage.data.constraints.push((constraint, origin));
436        self.undo_log.push(AddConstraint(index));
437    }
438
439    fn add_verify(&mut self, verify: Verify<'tcx>) {
440        // cannot add verifys once regions are resolved
441        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:441",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(441u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: add_verify({0:?})",
                                                    verify) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: add_verify({:?})", verify);
442
443        // skip no-op cases known to be satisfied
444        if let VerifyBound::AllBounds(ref bs) = verify.bound
445            && bs.is_empty()
446        {
447            return;
448        }
449
450        let index = self.storage.data.verifys.len();
451        self.storage.data.verifys.push(verify);
452        self.undo_log.push(AddVerify(index));
453    }
454
455    pub(super) fn make_eqregion(
456        &mut self,
457        origin: SubregionOrigin<'tcx>,
458        a: Region<'tcx>,
459        b: Region<'tcx>,
460    ) {
461        if a != b {
462            // FIXME: We could only emit constraints if `unify_var_{var, value}` fails when
463            // equating region vars.
464            match (a.kind(), b.kind(), a, b) {
465                (ReBound(..), _, _, _) | (_, ReBound(..), _, _) => {
466                    ::rustc_middle::util::bug::span_bug_fmt(origin.span(),
    format_args!("cannot relate bound region: {0:?} == {1:?}", a, b));span_bug!(origin.span(), "cannot relate bound region: {:?} == {:?}", a, b);
467                }
468                (ReVar(a_vid), ReVar(b_vid), _, _) => {
469                    self.add_constraint(
470                        Constraint { kind: ConstraintKind::VarEqVar, sub: a, sup: b },
471                        origin,
472                    );
473                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:473",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(473u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("make_eqregion: unifying {0:?} with {1:?}",
                                                    a_vid, b_vid) as &dyn Value))])
            });
    } else { ; }
};debug!("make_eqregion: unifying {:?} with {:?}", a_vid, b_vid);
474                    if self.unification_table_mut().unify_var_var(a_vid, b_vid).is_ok() {
475                        self.storage.any_unifications = true;
476                    }
477                }
478                (ReVar(vid), _, var, reg) | (_, ReVar(vid), reg, var) => {
479                    if reg.is_static() {
480                        // all regions are subregions of static, so don't go bidirectional here
481                        self.add_constraint(
482                            Constraint { kind: ConstraintKind::RegSubVar, sub: reg, sup: var },
483                            origin,
484                        );
485                    } else {
486                        self.add_constraint(
487                            Constraint { kind: ConstraintKind::VarEqReg, sub: var, sup: reg },
488                            origin,
489                        );
490                    }
491                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:491",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(491u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("make_eqregion: unifying {0:?} with {1:?}",
                                                    vid, reg) as &dyn Value))])
            });
    } else { ; }
};debug!("make_eqregion: unifying {:?} with {:?}", vid, reg);
492                    if self
493                        .unification_table_mut()
494                        .unify_var_value(vid, RegionVariableValue::Known { value: reg })
495                        .is_ok()
496                    {
497                        self.storage.any_unifications = true;
498                    };
499                }
500                (ReStatic, _, st, reg) | (_, ReStatic, reg, st) => {
501                    // all regions are subregions of static, so don't go bidirectional here
502                    self.add_constraint(
503                        Constraint { kind: ConstraintKind::RegSubReg, sub: st, sup: reg },
504                        origin,
505                    );
506                }
507                _ => {
508                    self.add_constraint(
509                        Constraint { kind: ConstraintKind::RegEqReg, sub: a, sup: b },
510                        origin,
511                    );
512                }
513            }
514        }
515    }
516
517    #[allow(clippy :: suspicious_else_formatting)]
{
    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("make_subregion",
                                    "rustc_infer::infer::region_constraints",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(517u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                                    ::tracing_core::field::FieldSet::new(&["sub", "sup"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sub)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sup)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:525",
                                    "rustc_infer::infer::region_constraints",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(525u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                                    ::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};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("origin = {0:#?}",
                                                                origin) as &dyn Value))])
                        });
                } else { ; }
            };
            match (sub.kind(), sup.kind()) {
                (ReBound(..), _) | (_, ReBound(..)) => {
                    ::rustc_middle::util::bug::span_bug_fmt(origin.span(),
                        format_args!("cannot relate bound region: {0:?} <= {1:?}",
                            sub, sup));
                }
                (_, ReStatic) => {}
                (ReVar(sub_id), ReVar(sup_id)) => {
                    if sub_id != sup_id {
                        self.add_constraint(Constraint {
                                kind: ConstraintKind::VarSubVar,
                                sub,
                                sup,
                            }, origin);
                    }
                }
                (_, ReVar(_)) =>
                    self.add_constraint(Constraint {
                            kind: ConstraintKind::RegSubVar,
                            sub,
                            sup,
                        }, origin),
                (ReVar(_), _) =>
                    self.add_constraint(Constraint {
                            kind: ConstraintKind::VarSubReg,
                            sub,
                            sup,
                        }, origin),
                _ => {
                    if sub != sup {
                        self.add_constraint(Constraint {
                                kind: ConstraintKind::RegSubReg,
                                sub,
                                sup,
                            }, origin)
                    }
                }
            }
        }
    }
}#[instrument(skip(self, origin), level = "debug")]
518    pub(super) fn make_subregion(
519        &mut self,
520        origin: SubregionOrigin<'tcx>,
521        sub: Region<'tcx>,
522        sup: Region<'tcx>,
523    ) {
524        // cannot add constraints once regions are resolved
525        debug!("origin = {:#?}", origin);
526
527        match (sub.kind(), sup.kind()) {
528            (ReBound(..), _) | (_, ReBound(..)) => {
529                span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup);
530            }
531            (_, ReStatic) => {
532                // all regions are subregions of static, so we can ignore this
533            }
534            (ReVar(sub_id), ReVar(sup_id)) => {
535                if sub_id != sup_id {
536                    self.add_constraint(
537                        Constraint { kind: ConstraintKind::VarSubVar, sub, sup },
538                        origin,
539                    );
540                }
541            }
542            (_, ReVar(_)) => self
543                .add_constraint(Constraint { kind: ConstraintKind::RegSubVar, sub, sup }, origin),
544            (ReVar(_), _) => self
545                .add_constraint(Constraint { kind: ConstraintKind::VarSubReg, sub, sup }, origin),
546            _ => {
547                if sub != sup {
548                    self.add_constraint(
549                        Constraint { kind: ConstraintKind::RegSubReg, sub, sup },
550                        origin,
551                    )
552                }
553            }
554        }
555    }
556
557    pub(super) fn verify_generic_bound(
558        &mut self,
559        origin: SubregionOrigin<'tcx>,
560        kind: GenericKind<'tcx>,
561        sub: Region<'tcx>,
562        bound: VerifyBound<'tcx>,
563    ) {
564        self.add_verify(Verify { kind, origin, region: sub, bound });
565    }
566
567    pub(super) fn lub_regions(
568        &mut self,
569        tcx: TyCtxt<'tcx>,
570        origin: SubregionOrigin<'tcx>,
571        a: Region<'tcx>,
572        b: Region<'tcx>,
573    ) -> Region<'tcx> {
574        // cannot add constraints once regions are resolved
575        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:575",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(575u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: lub_regions({0:?}, {1:?})",
                                                    a, b) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: lub_regions({:?}, {:?})", a, b);
576        if a.is_static() || b.is_static() {
577            a // nothing lives longer than static
578        } else if a == b {
579            a // LUB(a,a) = a
580        } else {
581            self.combine_vars(tcx, Lub, a, b, origin)
582        }
583    }
584
585    pub(super) fn glb_regions(
586        &mut self,
587        tcx: TyCtxt<'tcx>,
588        origin: SubregionOrigin<'tcx>,
589        a: Region<'tcx>,
590        b: Region<'tcx>,
591    ) -> Region<'tcx> {
592        // cannot add constraints once regions are resolved
593        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:593",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(593u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("RegionConstraintCollector: glb_regions({0:?}, {1:?})",
                                                    a, b) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: glb_regions({:?}, {:?})", a, b);
594        if a.is_static() {
595            b // static lives longer than everything else
596        } else if b.is_static() {
597            a // static lives longer than everything else
598        } else if a == b {
599            a // GLB(a,a) = a
600        } else {
601            self.combine_vars(tcx, Glb, a, b, origin)
602        }
603    }
604
605    /// Resolves a region var to its value in the unification table, if it exists.
606    /// Otherwise, it is resolved to the root `ReVar` in the table.
607    pub fn opportunistic_resolve_var(
608        &mut self,
609        tcx: TyCtxt<'tcx>,
610        vid: ty::RegionVid,
611    ) -> ty::Region<'tcx> {
612        let mut ut = self.unification_table_mut();
613        let root_vid = ut.find(vid).vid;
614        match ut.probe_value(root_vid) {
615            RegionVariableValue::Known { value } => value,
616            RegionVariableValue::Unknown { .. } => ty::Region::new_var(tcx, root_vid),
617        }
618    }
619
620    pub fn probe_value(
621        &mut self,
622        vid: ty::RegionVid,
623    ) -> Result<ty::Region<'tcx>, ty::UniverseIndex> {
624        match self.unification_table_mut().probe_value(vid) {
625            RegionVariableValue::Known { value } => Ok(value),
626            RegionVariableValue::Unknown { universe } => Err(universe),
627        }
628    }
629
630    fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> {
631        match t {
632            Glb => &mut self.storage.glbs,
633            Lub => &mut self.storage.lubs,
634        }
635    }
636
637    fn combine_vars(
638        &mut self,
639        tcx: TyCtxt<'tcx>,
640        t: CombineMapType,
641        a: Region<'tcx>,
642        b: Region<'tcx>,
643        origin: SubregionOrigin<'tcx>,
644    ) -> Region<'tcx> {
645        let vars = TwoRegions { a, b };
646        if let Some(&c) = self.combine_map(t).get(&vars) {
647            return ty::Region::new_var(tcx, c);
648        }
649        let a_universe = self.universe(a);
650        let b_universe = self.universe(b);
651        let c_universe = cmp::max(a_universe, b_universe);
652        let c = self.new_region_var(c_universe, RegionVariableOrigin::Misc(origin.span()));
653        self.combine_map(t).insert(vars, c);
654        self.undo_log.push(AddCombination(t, vars));
655        let new_r = ty::Region::new_var(tcx, c);
656        for old_r in [a, b] {
657            match t {
658                Glb => self.make_subregion(origin.clone(), new_r, old_r),
659                Lub => self.make_subregion(origin.clone(), old_r, new_r),
660            }
661        }
662        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/region_constraints/mod.rs:662",
                        "rustc_infer::infer::region_constraints",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/region_constraints/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(662u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("combine_vars() c={0:?}",
                                                    c) as &dyn Value))])
            });
    } else { ; }
};debug!("combine_vars() c={:?}", c);
663        new_r
664    }
665
666    pub fn universe(&mut self, region: Region<'tcx>) -> ty::UniverseIndex {
667        match region.kind() {
668            ty::ReStatic
669            | ty::ReErased
670            | ty::ReLateParam(..)
671            | ty::ReEarlyParam(..)
672            | ty::ReError(_) => ty::UniverseIndex::ROOT,
673            ty::RePlaceholder(placeholder) => placeholder.universe,
674            ty::ReVar(vid) => match self.probe_value(vid) {
675                Ok(value) => self.universe(value),
676                Err(universe) => universe,
677            },
678            ty::ReBound(..) => ::rustc_middle::util::bug::bug_fmt(format_args!("universe(): encountered bound region {0:?}",
        region))bug!("universe(): encountered bound region {:?}", region),
679        }
680    }
681
682    pub fn vars_since_snapshot<'a>(
683        &'a self,
684        value_count: usize,
685    ) -> (Range<RegionVid>, Vec<RegionVariableOrigin<'tcx>>) {
686        let range =
687            RegionVid::from(value_count)..RegionVid::from(self.storage.unification_table.len());
688        (
689            range.clone(),
690            (range.start..range.end).map(|index| self.storage.var_infos[index].origin).collect(),
691        )
692    }
693
694    /// See `InferCtxt::region_constraints_added_in_snapshot`.
695    pub fn region_constraints_added_in_snapshot(&self, mark: &Snapshot<'tcx>) -> bool {
696        self.undo_log
697            .region_constraints_in_snapshot(mark)
698            .any(|&elt| #[allow(non_exhaustive_omitted_patterns)] match elt {
    AddConstraint(_) => true,
    _ => false,
}matches!(elt, AddConstraint(_)))
699    }
700
701    #[inline]
702    fn unification_table_mut(&mut self) -> super::UnificationTable<'_, 'tcx, RegionVidKey<'tcx>> {
703        ut::UnificationTable::with_log(&mut self.storage.unification_table, self.undo_log)
704    }
705}
706
707impl fmt::Debug for RegionSnapshot {
708    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
709        f.write_fmt(format_args!("RegionSnapshot"))write!(f, "RegionSnapshot")
710    }
711}
712
713impl<'tcx> fmt::Debug for GenericKind<'tcx> {
714    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
715        match *self {
716            GenericKind::Param(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
717            GenericKind::Placeholder(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
718            GenericKind::Alias(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
719        }
720    }
721}
722
723impl<'tcx> fmt::Display for GenericKind<'tcx> {
724    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
725        match *self {
726            GenericKind::Param(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
727            GenericKind::Placeholder(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
728            GenericKind::Alias(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
729        }
730    }
731}
732
733impl<'tcx> GenericKind<'tcx> {
734    pub fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
735        match *self {
736            GenericKind::Param(ref p) => p.to_ty(tcx),
737            GenericKind::Placeholder(ref p) => Ty::new_placeholder(tcx, *p),
738            GenericKind::Alias(ref p) => p.to_ty(tcx),
739        }
740    }
741}
742
743impl<'tcx> VerifyBound<'tcx> {
744    pub fn must_hold(&self) -> bool {
745        match self {
746            VerifyBound::IfEq(..) => false,
747            VerifyBound::OutlivedBy(re) => re.is_static(),
748            VerifyBound::IsEmpty => false,
749            VerifyBound::AnyBound(bs) => bs.iter().any(|b| b.must_hold()),
750            VerifyBound::AllBounds(bs) => bs.iter().all(|b| b.must_hold()),
751        }
752    }
753
754    pub fn cannot_hold(&self) -> bool {
755        match self {
756            VerifyBound::IfEq(..) => false,
757            VerifyBound::IsEmpty => false,
758            VerifyBound::OutlivedBy(_) => false,
759            VerifyBound::AnyBound(bs) => bs.iter().all(|b| b.cannot_hold()),
760            VerifyBound::AllBounds(bs) => bs.iter().any(|b| b.cannot_hold()),
761        }
762    }
763
764    pub fn or(self, vb: VerifyBound<'tcx>) -> VerifyBound<'tcx> {
765        if self.must_hold() || vb.cannot_hold() {
766            self
767        } else if self.cannot_hold() || vb.must_hold() {
768            vb
769        } else {
770            VerifyBound::AnyBound(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [self, vb]))vec![self, vb])
771        }
772    }
773}
774
775impl<'tcx> RegionConstraintData<'tcx> {
776    /// Returns `true` if this region constraint data contains no constraints, and `false`
777    /// otherwise.
778    pub fn is_empty(&self) -> bool {
779        let RegionConstraintData { constraints, verifys } = self;
780        constraints.is_empty() && verifys.is_empty()
781    }
782}
783
784impl<'tcx> Rollback<UndoLog<'tcx>> for RegionConstraintStorage<'tcx> {
785    fn reverse(&mut self, undo: UndoLog<'tcx>) {
786        match undo {
787            AddVar(vid) => {
788                self.var_infos.pop().unwrap();
789                match (&self.var_infos.len(), &vid.index()) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(self.var_infos.len(), vid.index());
790            }
791            AddConstraint(index) => {
792                self.data.constraints.pop().unwrap();
793                match (&self.data.constraints.len(), &index) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(self.data.constraints.len(), index);
794            }
795            AddVerify(index) => {
796                self.data.verifys.pop();
797                match (&self.data.verifys.len(), &index) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(self.data.verifys.len(), index);
798            }
799            AddCombination(Glb, ref regions) => {
800                self.glbs.remove(regions);
801            }
802            AddCombination(Lub, ref regions) => {
803                self.lubs.remove(regions);
804            }
805        }
806    }
807}