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