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>>;
        let _: ::core::clone::AssertParamIsClone<ty::VisibleForLeakCheck>;
        *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 &&
            self.visible_for_leak_check == other.visible_for_leak_check
    }
}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>>;
        let _: ::core::cmp::AssertParamIsEq<ty::VisibleForLeakCheck>;
    }
}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_field4_finish(f, "Constraint",
            "kind", &self.kind, "sub", &self.sub, "sup", &self.sup,
            "visible_for_leak_check", &&self.visible_for_leak_check)
    }
}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);
        ::core::hash::Hash::hash(&self.visible_for_leak_check, state)
    }
}Hash)]
116pub struct Constraint<'tcx> {
117    pub kind: ConstraintKind,
118    // If `kind` is `VarSubVar`, `VarSubReg`, `VarEqVar` or `VarEqReg`, this must be a `ReVar`.
119    pub sub: Region<'tcx>,
120    // If `kind` is `VarSubVar`, `RegSubVar` or `VarEqVar`, this must be a `ReVar`.
121    pub sup: Region<'tcx>,
122    pub visible_for_leak_check: ty::VisibleForLeakCheck,
123}
124
125impl Constraint<'_> {
126    pub fn involves_placeholders(&self) -> bool {
127        self.sub.is_placeholder() || self.sup.is_placeholder()
128    }
129
130    pub fn iter_outlives(self) -> impl Iterator<Item = Self> {
131        let Constraint { kind, sub, sup, visible_for_leak_check } = self;
132
133        match kind {
134            ConstraintKind::VarSubVar
135            | ConstraintKind::RegSubVar
136            | ConstraintKind::VarSubReg
137            | ConstraintKind::RegSubReg => iter::once(self).chain(None),
138
139            ConstraintKind::VarEqVar => iter::once(Constraint {
140                kind: ConstraintKind::VarSubVar,
141                sub,
142                sup,
143                visible_for_leak_check,
144            })
145            .chain(Some(Constraint {
146                kind: ConstraintKind::VarSubVar,
147                sub: sup,
148                sup: sub,
149                visible_for_leak_check,
150            })),
151            ConstraintKind::VarEqReg => iter::once(Constraint {
152                kind: ConstraintKind::VarSubReg,
153                sub,
154                sup,
155                visible_for_leak_check,
156            })
157            .chain(Some(Constraint {
158                kind: ConstraintKind::RegSubVar,
159                sub: sup,
160                sup: sub,
161                visible_for_leak_check,
162            })),
163            ConstraintKind::RegEqReg => iter::once(Constraint {
164                kind: ConstraintKind::RegSubReg,
165                sub,
166                sup,
167                visible_for_leak_check,
168            })
169            .chain(Some(Constraint {
170                kind: ConstraintKind::RegSubReg,
171                sub: sup,
172                sup: sub,
173                visible_for_leak_check,
174            })),
175        }
176    }
177}
178
179#[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)]
180pub struct Verify<'tcx> {
181    pub kind: GenericKind<'tcx>,
182    pub origin: SubregionOrigin<'tcx>,
183    pub region: Region<'tcx>,
184    pub bound: VerifyBound<'tcx>,
185}
186
187#[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)]
188pub enum GenericKind<'tcx> {
189    Param(ty::ParamTy),
190    Placeholder(ty::PlaceholderType<'tcx>),
191    Alias(ty::AliasTy<'tcx>),
192}
193
194/// Describes the things that some `GenericKind` value `G` is known to
195/// outlive. Each variant of `VerifyBound` can be thought of as a
196/// function:
197/// ```ignore (pseudo-rust)
198/// fn(min: Region) -> bool { .. }
199/// ```
200/// where `true` means that the region `min` meets that `G: min`.
201/// (False means nothing.)
202///
203/// So, for example, if we have the type `T` and we have in scope that
204/// `T: 'a` and `T: 'b`, then the verify bound might be:
205/// ```ignore (pseudo-rust)
206/// fn(min: Region) -> bool {
207///    ('a: min) || ('b: min)
208/// }
209/// ```
210/// This is described with an `AnyRegion('a, 'b)` node.
211#[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)]
212pub enum VerifyBound<'tcx> {
213    /// See [`VerifyIfEq`] docs
214    IfEq(ty::Binder<'tcx, VerifyIfEq<'tcx>>),
215
216    /// Given a region `R`, expands to the function:
217    ///
218    /// ```ignore (pseudo-rust)
219    /// fn(min) -> bool {
220    ///     R: min
221    /// }
222    /// ```
223    ///
224    /// This is used when we can establish that `G: R` -- therefore,
225    /// if `R: min`, then by transitivity `G: min`.
226    OutlivedBy(Region<'tcx>),
227
228    /// Given a region `R`, true if it is `'empty`.
229    IsEmpty,
230
231    /// Given a set of bounds `B`, expands to the function:
232    ///
233    /// ```ignore (pseudo-rust)
234    /// fn(min) -> bool {
235    ///     exists (b in B) { b(min) }
236    /// }
237    /// ```
238    ///
239    /// In other words, if we meet some bound in `B`, that suffices.
240    /// This is used when all the bounds in `B` are known to apply to `G`.
241    AnyBound(Vec<VerifyBound<'tcx>>),
242
243    /// Given a set of bounds `B`, expands to the function:
244    ///
245    /// ```ignore (pseudo-rust)
246    /// fn(min) -> bool {
247    ///     forall (b in B) { b(min) }
248    /// }
249    /// ```
250    ///
251    /// In other words, if we meet *all* bounds in `B`, that suffices.
252    /// This is used when *some* bound in `B` is known to suffice, but
253    /// we don't know which.
254    AllBounds(Vec<VerifyBound<'tcx>>),
255}
256
257/// This is a "conditional bound" that checks the result of inference
258/// and supplies a bound if it ended up being relevant. It's used in situations
259/// like this:
260///
261/// ```rust,ignore (pseudo-Rust)
262/// fn foo<'a, 'b, T: SomeTrait<'a>>
263/// where
264///    <T as SomeTrait<'a>>::Item: 'b
265/// ```
266///
267/// If we have an obligation like `<T as SomeTrait<'?x>>::Item: 'c`, then
268/// we don't know yet whether it suffices to show that `'b: 'c`. If `'?x` winds
269/// up being equal to `'a`, then the where-clauses on function applies, and
270/// in that case we can show `'b: 'c`. But if `'?x` winds up being something
271/// else, the bound isn't relevant.
272///
273/// In the [`VerifyBound`], this struct is enclosed in `Binder` to account
274/// for cases like
275///
276/// ```rust,ignore (pseudo-Rust)
277/// where for<'a> <T as SomeTrait<'a>::Item: 'a
278/// ```
279///
280/// The idea is that we have to find some instantiation of `'a` that can
281/// make `<T as SomeTrait<'a>>::Item` equal to the final value of `G`,
282/// the generic we are checking.
283///
284/// ```ignore (pseudo-rust)
285/// fn(min) -> bool {
286///     exists<'a> {
287///         if G == K {
288///             B(min)
289///         } else {
290///             false
291///         }
292///     }
293/// }
294/// ```
295#[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)]
296pub struct VerifyIfEq<'tcx> {
297    /// Type which must match the generic `G`
298    pub ty: Ty<'tcx>,
299
300    /// Bound that applies if `ty` is equal.
301    pub bound: Region<'tcx>,
302}
303
304#[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)]
305pub(crate) struct TwoRegions<'tcx> {
306    a: Region<'tcx>,
307    b: Region<'tcx>,
308}
309
310#[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)]
311pub(crate) enum UndoLog<'tcx> {
312    /// We added `RegionVid`.
313    AddVar(RegionVid),
314
315    /// We added the given `constraint`.
316    AddConstraint(usize),
317
318    /// We added the given `verify`.
319    AddVerify(usize),
320
321    /// We added a GLB/LUB "combination variable".
322    AddCombination(CombineMapType, TwoRegions<'tcx>),
323}
324
325#[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)]
326pub(crate) enum CombineMapType {
327    Lub,
328    Glb,
329}
330
331type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
332
333#[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)]
334pub struct RegionVariableInfo<'tcx> {
335    pub origin: RegionVariableOrigin<'tcx>,
336    // FIXME: This is only necessary for `fn take_and_reset_data` and
337    // `lexical_region_resolve`. We should rework `lexical_region_resolve`
338    // in the near/medium future anyways and could move the unverse info
339    // for `fn take_and_reset_data` into a separate table which is
340    // only populated when needed.
341    //
342    // For both of these cases it is fine that this can diverge from the
343    // actual universe of the variable, which is directly stored in the
344    // unification table for unknown region variables. At some point we could
345    // stop emitting bidirectional outlives constraints if equate succeeds.
346    // This would be currently unsound as it would cause us to drop the universe
347    // changes in `lexical_region_resolve`.
348    pub universe: ty::UniverseIndex,
349}
350
351pub(crate) struct RegionSnapshot {
352    any_unifications: bool,
353}
354
355impl<'tcx> RegionConstraintStorage<'tcx> {
356    #[inline]
357    pub(crate) fn with_log<'a>(
358        &'a mut self,
359        undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
360    ) -> RegionConstraintCollector<'a, 'tcx> {
361        RegionConstraintCollector { storage: self, undo_log }
362    }
363}
364
365impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
366    pub fn num_region_vars(&self) -> usize {
367        self.storage.var_infos.len()
368    }
369
370    /// Takes (and clears) the current set of constraints. Note that
371    /// the set of variables remains intact, but all relationships
372    /// between them are reset. This is used during NLL checking to
373    /// grab the set of constraints that arose from a particular
374    /// operation.
375    ///
376    /// We don't want to leak relationships between variables between
377    /// points because just because (say) `r1 == r2` was true at some
378    /// point P in the graph doesn't imply that it will be true at
379    /// some other point Q, in NLL.
380    ///
381    /// Not legal during a snapshot.
382    pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx> {
383        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));
384
385        // If you add a new field to `RegionConstraintCollector`, you
386        // should think carefully about whether it needs to be cleared
387        // or updated in some way.
388        let RegionConstraintStorage {
389            var_infos: _,
390            data,
391            lubs,
392            glbs,
393            unification_table: _,
394            any_unifications,
395        } = self.storage;
396
397        // Clear the tables of (lubs, glbs), so that we will create
398        // fresh regions if we do a LUB operation. As it happens,
399        // LUB/GLB are not performed by the MIR type-checker, which is
400        // the one that uses this method, but it's good to be correct.
401        lubs.clear();
402        glbs.clear();
403
404        let data = mem::take(data);
405
406        // Clear all unifications and recreate the variables a "now
407        // un-unified" state. Note that when we unify `a` and `b`, we
408        // also insert `a <= b` and a `b <= a` edges, so the
409        // `RegionConstraintData` contains the relationship here.
410        if *any_unifications {
411            *any_unifications = false;
412            // Manually inlined `self.unification_table_mut()` as `self` is used in the closure.
413            ut::UnificationTable::with_log(&mut self.storage.unification_table, &mut self.undo_log)
414                .reset_unifications(|key| RegionVariableValue::Unknown {
415                    universe: self.storage.var_infos[key.vid].universe,
416                });
417        }
418
419        data
420    }
421
422    pub fn data(&self) -> &RegionConstraintData<'tcx> {
423        &self.storage.data
424    }
425
426    pub(super) fn start_snapshot(&self) -> RegionSnapshot {
427        {
    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:427",
                        "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(427u32),
                        ::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");
428        RegionSnapshot { any_unifications: self.storage.any_unifications }
429    }
430
431    pub(super) fn rollback_to(&mut self, snapshot: RegionSnapshot) {
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: rollback_to({0:?})",
                                                    snapshot) as &dyn Value))])
            });
    } else { ; }
};debug!("RegionConstraintCollector: rollback_to({:?})", snapshot);
433        self.storage.any_unifications = snapshot.any_unifications;
434    }
435
436    pub(super) fn new_region_var(
437        &mut self,
438        universe: ty::UniverseIndex,
439        origin: RegionVariableOrigin<'tcx>,
440    ) -> RegionVid {
441        let vid = self.storage.var_infos.push(RegionVariableInfo { origin, universe });
442
443        let u_vid = self.unification_table_mut().new_key(RegionVariableValue::Unknown { universe });
444        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);
445        self.undo_log.push(AddVar(vid));
446        {
    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:446",
                        "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(446u32),
                        ::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);
447        vid
448    }
449
450    /// Returns the origin for the given variable.
451    pub(super) fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin<'tcx> {
452        self.storage.var_infos[vid].origin
453    }
454
455    fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) {
456        // cannot add constraints once regions are resolved
457        {
    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:457",
                        "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(457u32),
                        ::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);
458
459        let index = self.storage.data.constraints.len();
460        self.storage.data.constraints.push((constraint, origin));
461        self.undo_log.push(AddConstraint(index));
462    }
463
464    fn add_verify(&mut self, verify: Verify<'tcx>) {
465        // cannot add verifys once regions are resolved
466        {
    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:466",
                        "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(466u32),
                        ::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);
467
468        // skip no-op cases known to be satisfied
469        if let VerifyBound::AllBounds(ref bs) = verify.bound
470            && bs.is_empty()
471        {
472            return;
473        }
474
475        let index = self.storage.data.verifys.len();
476        self.storage.data.verifys.push(verify);
477        self.undo_log.push(AddVerify(index));
478    }
479
480    pub(super) fn make_eqregion(
481        &mut self,
482        origin: SubregionOrigin<'tcx>,
483        a: Region<'tcx>,
484        b: Region<'tcx>,
485        visible_for_leak_check: ty::VisibleForLeakCheck,
486    ) {
487        if a != b {
488            // FIXME: We could only emit constraints if `unify_var_{var, value}` fails when
489            // equating region vars.
490            match (a.kind(), b.kind(), a, b) {
491                (ReBound(..), _, _, _) | (_, ReBound(..), _, _) => {
492                    ::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);
493                }
494                (ReVar(a_vid), ReVar(b_vid), _, _) => {
495                    self.add_constraint(
496                        Constraint {
497                            kind: ConstraintKind::VarEqVar,
498                            sub: a,
499                            sup: b,
500                            visible_for_leak_check,
501                        },
502                        origin,
503                    );
504                    {
    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:504",
                        "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(504u32),
                        ::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);
505                    if self.unification_table_mut().unify_var_var(a_vid, b_vid).is_ok() {
506                        self.storage.any_unifications = true;
507                    }
508                }
509                (ReVar(vid), _, var, reg) | (_, ReVar(vid), reg, var) => {
510                    if reg.is_static() {
511                        // all regions are subregions of static, so don't go bidirectional here
512                        self.add_constraint(
513                            Constraint {
514                                kind: ConstraintKind::RegSubVar,
515                                sub: reg,
516                                sup: var,
517                                visible_for_leak_check,
518                            },
519                            origin,
520                        );
521                    } else {
522                        self.add_constraint(
523                            Constraint {
524                                kind: ConstraintKind::VarEqReg,
525                                sub: var,
526                                sup: reg,
527                                visible_for_leak_check,
528                            },
529                            origin,
530                        );
531                    }
532                    {
    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:532",
                        "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(532u32),
                        ::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);
533                    if self
534                        .unification_table_mut()
535                        .unify_var_value(vid, RegionVariableValue::Known { value: reg })
536                        .is_ok()
537                    {
538                        self.storage.any_unifications = true;
539                    };
540                }
541                (ReStatic, _, st, reg) | (_, ReStatic, reg, st) => {
542                    // all regions are subregions of static, so don't go bidirectional here
543                    self.add_constraint(
544                        Constraint {
545                            kind: ConstraintKind::RegSubReg,
546                            sub: st,
547                            sup: reg,
548                            visible_for_leak_check,
549                        },
550                        origin,
551                    );
552                }
553                _ => {
554                    self.add_constraint(
555                        Constraint {
556                            kind: ConstraintKind::RegEqReg,
557                            sub: a,
558                            sup: b,
559                            visible_for_leak_check,
560                        },
561                        origin,
562                    );
563                }
564            }
565        }
566    }
567
568    #[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(568u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::region_constraints"),
                                    ::tracing_core::field::FieldSet::new(&["sub", "sup",
                                                    "visible_for_leak_check"],
                                        ::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)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&visible_for_leak_check)
                                                            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:577",
                                    "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(577u32),
                                    ::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,
                                visible_for_leak_check,
                            }, origin);
                    }
                }
                (_, ReVar(_)) =>
                    self.add_constraint(Constraint {
                            kind: ConstraintKind::RegSubVar,
                            sub,
                            sup,
                            visible_for_leak_check,
                        }, origin),
                (ReVar(_), _) =>
                    self.add_constraint(Constraint {
                            kind: ConstraintKind::VarSubReg,
                            sub,
                            sup,
                            visible_for_leak_check,
                        }, origin),
                _ => {
                    if sub != sup {
                        self.add_constraint(Constraint {
                                kind: ConstraintKind::RegSubReg,
                                sub,
                                sup,
                                visible_for_leak_check,
                            }, origin)
                    }
                }
            }
        }
    }
}#[instrument(skip(self, origin), level = "debug")]
569    pub(super) fn make_subregion(
570        &mut self,
571        origin: SubregionOrigin<'tcx>,
572        sub: Region<'tcx>,
573        sup: Region<'tcx>,
574        visible_for_leak_check: ty::VisibleForLeakCheck,
575    ) {
576        // cannot add constraints once regions are resolved
577        debug!("origin = {:#?}", origin);
578
579        match (sub.kind(), sup.kind()) {
580            (ReBound(..), _) | (_, ReBound(..)) => {
581                span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup);
582            }
583            (_, ReStatic) => {
584                // all regions are subregions of static, so we can ignore this
585            }
586            (ReVar(sub_id), ReVar(sup_id)) => {
587                if sub_id != sup_id {
588                    self.add_constraint(
589                        Constraint {
590                            kind: ConstraintKind::VarSubVar,
591                            sub,
592                            sup,
593                            visible_for_leak_check,
594                        },
595                        origin,
596                    );
597                }
598            }
599            (_, ReVar(_)) => self.add_constraint(
600                Constraint { kind: ConstraintKind::RegSubVar, sub, sup, visible_for_leak_check },
601                origin,
602            ),
603            (ReVar(_), _) => self.add_constraint(
604                Constraint { kind: ConstraintKind::VarSubReg, sub, sup, visible_for_leak_check },
605                origin,
606            ),
607            _ => {
608                if sub != sup {
609                    self.add_constraint(
610                        Constraint {
611                            kind: ConstraintKind::RegSubReg,
612                            sub,
613                            sup,
614                            visible_for_leak_check,
615                        },
616                        origin,
617                    )
618                }
619            }
620        }
621    }
622
623    pub(super) fn verify_generic_bound(
624        &mut self,
625        origin: SubregionOrigin<'tcx>,
626        kind: GenericKind<'tcx>,
627        sub: Region<'tcx>,
628        bound: VerifyBound<'tcx>,
629    ) {
630        self.add_verify(Verify { kind, origin, region: sub, bound });
631    }
632
633    pub(super) fn lub_regions(
634        &mut self,
635        tcx: TyCtxt<'tcx>,
636        origin: SubregionOrigin<'tcx>,
637        a: Region<'tcx>,
638        b: Region<'tcx>,
639    ) -> Region<'tcx> {
640        // cannot add constraints once regions are resolved
641        {
    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:641",
                        "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(641u32),
                        ::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);
642        if a.is_static() || b.is_static() {
643            a // nothing lives longer than static
644        } else if a == b {
645            a // LUB(a,a) = a
646        } else {
647            self.combine_vars(tcx, Lub, a, b, origin)
648        }
649    }
650
651    pub(super) fn glb_regions(
652        &mut self,
653        tcx: TyCtxt<'tcx>,
654        origin: SubregionOrigin<'tcx>,
655        a: Region<'tcx>,
656        b: Region<'tcx>,
657    ) -> Region<'tcx> {
658        // cannot add constraints once regions are resolved
659        {
    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:659",
                        "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(659u32),
                        ::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);
660        if a.is_static() {
661            b // static lives longer than everything else
662        } else if b.is_static() {
663            a // static lives longer than everything else
664        } else if a == b {
665            a // GLB(a,a) = a
666        } else {
667            self.combine_vars(tcx, Glb, a, b, origin)
668        }
669    }
670
671    /// Resolves a region var to its value in the unification table, if it exists.
672    /// Otherwise, it is resolved to the root `ReVar` in the table.
673    pub fn opportunistic_resolve_var(
674        &mut self,
675        tcx: TyCtxt<'tcx>,
676        vid: ty::RegionVid,
677    ) -> ty::Region<'tcx> {
678        let mut ut = self.unification_table_mut();
679        let root_vid = ut.find(vid).vid;
680        match ut.probe_value(root_vid) {
681            RegionVariableValue::Known { value } => value,
682            RegionVariableValue::Unknown { .. } => ty::Region::new_var(tcx, root_vid),
683        }
684    }
685
686    pub fn probe_value(
687        &mut self,
688        vid: ty::RegionVid,
689    ) -> Result<ty::Region<'tcx>, ty::UniverseIndex> {
690        match self.unification_table_mut().probe_value(vid) {
691            RegionVariableValue::Known { value } => Ok(value),
692            RegionVariableValue::Unknown { universe } => Err(universe),
693        }
694    }
695
696    fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> {
697        match t {
698            Glb => &mut self.storage.glbs,
699            Lub => &mut self.storage.lubs,
700        }
701    }
702
703    fn combine_vars(
704        &mut self,
705        tcx: TyCtxt<'tcx>,
706        t: CombineMapType,
707        a: Region<'tcx>,
708        b: Region<'tcx>,
709        origin: SubregionOrigin<'tcx>,
710    ) -> Region<'tcx> {
711        let vars = TwoRegions { a, b };
712        if let Some(&c) = self.combine_map(t).get(&vars) {
713            return ty::Region::new_var(tcx, c);
714        }
715        let a_universe = self.universe(a);
716        let b_universe = self.universe(b);
717        let c_universe = cmp::max(a_universe, b_universe);
718        let c = self.new_region_var(c_universe, RegionVariableOrigin::Misc(origin.span()));
719        self.combine_map(t).insert(vars, c);
720        self.undo_log.push(AddCombination(t, vars));
721        let new_r = ty::Region::new_var(tcx, c);
722        for old_r in [a, b] {
723            match t {
724                Glb => {
725                    self.make_subregion(origin.clone(), new_r, old_r, ty::VisibleForLeakCheck::Yes)
726                }
727                Lub => {
728                    self.make_subregion(origin.clone(), old_r, new_r, ty::VisibleForLeakCheck::Yes)
729                }
730            }
731        }
732        {
    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:732",
                        "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(732u32),
                        ::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);
733        new_r
734    }
735
736    pub fn universe(&mut self, region: Region<'tcx>) -> ty::UniverseIndex {
737        match region.kind() {
738            ty::ReStatic
739            | ty::ReErased
740            | ty::ReLateParam(..)
741            | ty::ReEarlyParam(..)
742            | ty::ReError(_) => ty::UniverseIndex::ROOT,
743            ty::RePlaceholder(placeholder) => placeholder.universe,
744            ty::ReVar(vid) => match self.probe_value(vid) {
745                Ok(value) => self.universe(value),
746                Err(universe) => universe,
747            },
748            ty::ReBound(..) => ::rustc_middle::util::bug::bug_fmt(format_args!("universe(): encountered bound region {0:?}",
        region))bug!("universe(): encountered bound region {:?}", region),
749        }
750    }
751
752    pub fn vars_since_snapshot<'a>(
753        &'a self,
754        value_count: usize,
755    ) -> (Range<RegionVid>, Vec<RegionVariableOrigin<'tcx>>) {
756        let range =
757            RegionVid::from(value_count)..RegionVid::from(self.storage.unification_table.len());
758        (
759            range.clone(),
760            (range.start..range.end).map(|index| self.storage.var_infos[index].origin).collect(),
761        )
762    }
763
764    /// See `InferCtxt::region_constraints_added_in_snapshot`.
765    pub fn region_constraints_added_in_snapshot(&self, mark: &Snapshot<'tcx>) -> bool {
766        self.undo_log
767            .region_constraints_in_snapshot(mark)
768            .any(|&elt| #[allow(non_exhaustive_omitted_patterns)] match elt {
    AddConstraint(_) => true,
    _ => false,
}matches!(elt, AddConstraint(_)))
769    }
770
771    #[inline]
772    fn unification_table_mut(&mut self) -> super::UnificationTable<'_, 'tcx, RegionVidKey<'tcx>> {
773        ut::UnificationTable::with_log(&mut self.storage.unification_table, self.undo_log)
774    }
775}
776
777impl fmt::Debug for RegionSnapshot {
778    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
779        f.write_fmt(format_args!("RegionSnapshot"))write!(f, "RegionSnapshot")
780    }
781}
782
783impl<'tcx> fmt::Debug for GenericKind<'tcx> {
784    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
785        match *self {
786            GenericKind::Param(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
787            GenericKind::Placeholder(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
788            GenericKind::Alias(ref p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
789        }
790    }
791}
792
793impl<'tcx> fmt::Display for GenericKind<'tcx> {
794    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
795        match *self {
796            GenericKind::Param(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
797            GenericKind::Placeholder(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
798            GenericKind::Alias(ref p) => f.write_fmt(format_args!("{0}", p))write!(f, "{p}"),
799        }
800    }
801}
802
803impl<'tcx> GenericKind<'tcx> {
804    pub fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
805        match *self {
806            GenericKind::Param(ref p) => p.to_ty(tcx),
807            GenericKind::Placeholder(ref p) => Ty::new_placeholder(tcx, *p),
808            GenericKind::Alias(ref p) => p.to_ty(tcx),
809        }
810    }
811}
812
813impl<'tcx> VerifyBound<'tcx> {
814    pub fn must_hold(&self) -> bool {
815        match self {
816            VerifyBound::IfEq(..) => false,
817            VerifyBound::OutlivedBy(re) => re.is_static(),
818            VerifyBound::IsEmpty => false,
819            VerifyBound::AnyBound(bs) => bs.iter().any(|b| b.must_hold()),
820            VerifyBound::AllBounds(bs) => bs.iter().all(|b| b.must_hold()),
821        }
822    }
823
824    pub fn cannot_hold(&self) -> bool {
825        match self {
826            VerifyBound::IfEq(..) => false,
827            VerifyBound::IsEmpty => false,
828            VerifyBound::OutlivedBy(_) => false,
829            VerifyBound::AnyBound(bs) => bs.iter().all(|b| b.cannot_hold()),
830            VerifyBound::AllBounds(bs) => bs.iter().any(|b| b.cannot_hold()),
831        }
832    }
833
834    pub fn or(self, vb: VerifyBound<'tcx>) -> VerifyBound<'tcx> {
835        if self.must_hold() || vb.cannot_hold() {
836            self
837        } else if self.cannot_hold() || vb.must_hold() {
838            vb
839        } else {
840            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])
841        }
842    }
843}
844
845impl<'tcx> RegionConstraintData<'tcx> {
846    /// Returns `true` if this region constraint data contains no constraints, and `false`
847    /// otherwise.
848    pub fn is_empty(&self) -> bool {
849        let RegionConstraintData { constraints, verifys } = self;
850        constraints.is_empty() && verifys.is_empty()
851    }
852}
853
854impl<'tcx> Rollback<UndoLog<'tcx>> for RegionConstraintStorage<'tcx> {
855    fn reverse(&mut self, undo: UndoLog<'tcx>) {
856        match undo {
857            AddVar(vid) => {
858                self.var_infos.pop().unwrap();
859                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());
860            }
861            AddConstraint(index) => {
862                self.data.constraints.pop().unwrap();
863                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);
864            }
865            AddVerify(index) => {
866                self.data.verifys.pop();
867                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);
868            }
869            AddCombination(Glb, ref regions) => {
870                self.glbs.remove(regions);
871            }
872            AddCombination(Lub, ref regions) => {
873                self.lubs.remove(regions);
874            }
875        }
876    }
877}