Skip to main content

rustc_infer/infer/lexical_region_resolve/
mod.rs

1//! Lexical region resolution.
2
3use std::fmt;
4
5use rustc_data_structures::fx::FxHashSet;
6use rustc_data_structures::intern::Interned;
7use rustc_data_structures::unord::UnordSet;
8use rustc_index::{IndexSlice, IndexVec};
9use rustc_middle::ty::{
10    self, ReBound, ReEarlyParam, ReErased, ReError, ReLateParam, RePlaceholder, ReStatic, ReVar,
11    Region, RegionVid, Ty, TyCtxt, TypeFoldable, fold_regions,
12};
13use rustc_middle::{bug, span_bug};
14use rustc_span::Span;
15use tracing::{debug, instrument};
16
17use super::outlives::test_type_match;
18use crate::infer::lexical_region_resolve::indexed_edges::{EdgeDirection, IndexedConstraintEdges};
19use crate::infer::region_constraints::{
20    ConstraintKind, GenericKind, RegionConstraintData, VarInfos, VerifyBound,
21};
22use crate::infer::{RegionRelations, RegionVariableOrigin, SubregionOrigin};
23
24mod indexed_edges;
25
26/// This function performs lexical region resolution given a complete
27/// set of constraints and variable origins. It performs a fixed-point
28/// iteration to find region values which satisfy all constraints,
29/// assuming such values can be found. It returns the final values of
30/// all the variables as well as a set of errors that must be reported.
31#[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("resolve",
                                    "rustc_infer::infer::lexical_region_resolve",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(31u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set(&[]) })
                } 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:
                    (LexicalRegionResolutions<'tcx>,
                    Vec<RegionResolutionError<'tcx>>) = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !data.constraints.iter().all(|(c, _)|
                            match c.kind {
                                ConstraintKind::VarSubVar | ConstraintKind::RegSubVar |
                                    ConstraintKind::VarSubReg | ConstraintKind::RegSubReg =>
                                    true,
                                ConstraintKind::VarEqVar | ConstraintKind::VarEqReg |
                                    ConstraintKind::RegEqReg => false,
                            }) {
                {
                    ::core::panicking::panic_fmt(format_args!("Every constraint should be decomposed into outlives here"));
                }
            };
            let mut errors = ::alloc::vec::Vec::new();
            let mut resolver =
                LexicalResolver { region_rels, var_infos, data };
            let values = resolver.infer_variable_values(&mut errors);
            (values, errors)
        }
    }
}#[instrument(level = "debug", skip(region_rels, var_infos, data))]
32pub(crate) fn resolve<'tcx>(
33    region_rels: &RegionRelations<'_, 'tcx>,
34    var_infos: VarInfos<'tcx>,
35    data: RegionConstraintData<'tcx>,
36) -> (LexicalRegionResolutions<'tcx>, Vec<RegionResolutionError<'tcx>>) {
37    assert!(
38        data.constraints.iter().all(|(c, _)| match c.kind {
39            ConstraintKind::VarSubVar
40            | ConstraintKind::RegSubVar
41            | ConstraintKind::VarSubReg
42            | ConstraintKind::RegSubReg => true,
43
44            ConstraintKind::VarEqVar | ConstraintKind::VarEqReg | ConstraintKind::RegEqReg => false,
45        }),
46        "Every constraint should be decomposed into outlives here"
47    );
48
49    let mut errors = vec![];
50    let mut resolver = LexicalResolver { region_rels, var_infos, data };
51    let values = resolver.infer_variable_values(&mut errors);
52    (values, errors)
53}
54
55/// Contains the result of lexical region resolution. Offers methods
56/// to lookup up the final value of a region variable.
57#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for LexicalRegionResolutions<'tcx> {
    #[inline]
    fn clone(&self) -> LexicalRegionResolutions<'tcx> {
        LexicalRegionResolutions {
            values: ::core::clone::Clone::clone(&self.values),
        }
    }
}Clone)]
58pub(crate) struct LexicalRegionResolutions<'tcx> {
59    pub(crate) values: IndexVec<RegionVid, VarValue<'tcx>>,
60}
61
62#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for VarValue<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for VarValue<'tcx> {
    #[inline]
    fn clone(&self) -> VarValue<'tcx> {
        let _: ::core::clone::AssertParamIsClone<ty::UniverseIndex>;
        let _: ::core::clone::AssertParamIsClone<Region<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for VarValue<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            VarValue::Empty(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Empty",
                    &__self_0),
            VarValue::Value(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Value",
                    &__self_0),
            VarValue::ErrorValue =>
                ::core::fmt::Formatter::write_str(f, "ErrorValue"),
        }
    }
}Debug)]
63pub(crate) enum VarValue<'tcx> {
64    /// Empty lifetime is for data that is never accessed. We tag the
65    /// empty lifetime with a universe -- the idea is that we don't
66    /// want `exists<'a> { forall<'b> { 'b: 'a } }` to be satisfiable.
67    /// Therefore, the `'empty` in a universe `U` is less than all
68    /// regions visible from `U`, but not less than regions not visible
69    /// from `U`.
70    Empty(ty::UniverseIndex),
71    Value(Region<'tcx>),
72    ErrorValue,
73}
74
75#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for RegionResolutionError<'tcx> {
    #[inline]
    fn clone(&self) -> RegionResolutionError<'tcx> {
        match self {
            RegionResolutionError::ConcreteFailure(__self_0, __self_1,
                __self_2) =>
                RegionResolutionError::ConcreteFailure(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1),
                    ::core::clone::Clone::clone(__self_2)),
            RegionResolutionError::GenericBoundFailure(__self_0, __self_1,
                __self_2) =>
                RegionResolutionError::GenericBoundFailure(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1),
                    ::core::clone::Clone::clone(__self_2)),
            RegionResolutionError::SubSupConflict(__self_0, __self_1,
                __self_2, __self_3, __self_4, __self_5, __self_6) =>
                RegionResolutionError::SubSupConflict(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1),
                    ::core::clone::Clone::clone(__self_2),
                    ::core::clone::Clone::clone(__self_3),
                    ::core::clone::Clone::clone(__self_4),
                    ::core::clone::Clone::clone(__self_5),
                    ::core::clone::Clone::clone(__self_6)),
            RegionResolutionError::UpperBoundUniverseConflict(__self_0,
                __self_1, __self_2, __self_3, __self_4) =>
                RegionResolutionError::UpperBoundUniverseConflict(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1),
                    ::core::clone::Clone::clone(__self_2),
                    ::core::clone::Clone::clone(__self_3),
                    ::core::clone::Clone::clone(__self_4)),
            RegionResolutionError::CannotNormalize(__self_0, __self_1) =>
                RegionResolutionError::CannotNormalize(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1)),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for RegionResolutionError<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            RegionResolutionError::ConcreteFailure(__self_0, __self_1,
                __self_2) =>
                ::core::fmt::Formatter::debug_tuple_field3_finish(f,
                    "ConcreteFailure", __self_0, __self_1, &__self_2),
            RegionResolutionError::GenericBoundFailure(__self_0, __self_1,
                __self_2) =>
                ::core::fmt::Formatter::debug_tuple_field3_finish(f,
                    "GenericBoundFailure", __self_0, __self_1, &__self_2),
            RegionResolutionError::SubSupConflict(__self_0, __self_1,
                __self_2, __self_3, __self_4, __self_5, __self_6) => {
                let values: &[&dyn ::core::fmt::Debug] =
                    &[__self_0, __self_1, __self_2, __self_3, __self_4,
                                __self_5, &__self_6];
                ::core::fmt::Formatter::debug_tuple_fields_finish(f,
                    "SubSupConflict", values)
            }
            RegionResolutionError::UpperBoundUniverseConflict(__self_0,
                __self_1, __self_2, __self_3, __self_4) =>
                ::core::fmt::Formatter::debug_tuple_field5_finish(f,
                    "UpperBoundUniverseConflict", __self_0, __self_1, __self_2,
                    __self_3, &__self_4),
            RegionResolutionError::CannotNormalize(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "CannotNormalize", __self_0, &__self_1),
        }
    }
}Debug)]
76pub enum RegionResolutionError<'tcx> {
77    /// `ConcreteFailure(o, a, b)`:
78    ///
79    /// `o` requires that `a <= b`, but this does not hold
80    ConcreteFailure(SubregionOrigin<'tcx>, Region<'tcx>, Region<'tcx>),
81
82    /// `GenericBoundFailure(p, s, a)`:
83    ///
84    /// The parameter/associated-type `p` must be known to outlive the lifetime
85    /// `a` (but none of the known bounds are sufficient).
86    GenericBoundFailure(SubregionOrigin<'tcx>, GenericKind<'tcx>, Region<'tcx>),
87
88    /// `SubSupConflict(v, v_origin, sub_origin, sub_r, sup_origin, sup_r)`:
89    ///
90    /// Could not infer a value for `v` (which has origin `v_origin`)
91    /// because `sub_r <= v` (due to `sub_origin`) but `v <= sup_r` (due to `sup_origin`) and
92    /// `sub_r <= sup_r` does not hold.
93    SubSupConflict(
94        RegionVid,
95        RegionVariableOrigin<'tcx>,
96        SubregionOrigin<'tcx>,
97        Region<'tcx>,
98        SubregionOrigin<'tcx>,
99        Region<'tcx>,
100        Vec<Span>, // All the influences on a given value that didn't meet its constraints.
101    ),
102
103    /// Indicates a `'b: 'a` constraint where `'a` is in a universe that
104    /// cannot name the placeholder `'b`.
105    UpperBoundUniverseConflict(
106        RegionVid,
107        RegionVariableOrigin<'tcx>,
108        ty::UniverseIndex,     // the universe index of the region variable
109        SubregionOrigin<'tcx>, // cause of the constraint
110        Region<'tcx>,          // the placeholder `'b`
111    ),
112
113    CannotNormalize(ty::PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>),
114}
115
116impl<'tcx> RegionResolutionError<'tcx> {
117    pub fn origin(&self) -> &SubregionOrigin<'tcx> {
118        match self {
119            RegionResolutionError::ConcreteFailure(origin, _, _)
120            | RegionResolutionError::GenericBoundFailure(origin, _, _)
121            | RegionResolutionError::SubSupConflict(_, _, origin, _, _, _, _)
122            | RegionResolutionError::UpperBoundUniverseConflict(_, _, _, origin, _)
123            | RegionResolutionError::CannotNormalize(_, origin) => origin,
124        }
125    }
126}
127
128struct RegionAndOrigin<'tcx> {
129    region: Region<'tcx>,
130    origin: SubregionOrigin<'tcx>,
131}
132
133struct LexicalResolver<'cx, 'tcx> {
134    region_rels: &'cx RegionRelations<'cx, 'tcx>,
135    var_infos: VarInfos<'tcx>,
136    data: RegionConstraintData<'tcx>,
137}
138
139impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
140    fn tcx(&self) -> TyCtxt<'tcx> {
141        self.region_rels.tcx
142    }
143
144    fn infer_variable_values(
145        &mut self,
146        errors: &mut Vec<RegionResolutionError<'tcx>>,
147    ) -> LexicalRegionResolutions<'tcx> {
148        let mut var_data = self.construct_var_data();
149
150        // Deduplicating constraints is shown to have a positive perf impact.
151        let mut seen = UnordSet::default();
152        self.data.constraints.retain(|(constraint, _)| seen.insert(*constraint));
153
154        if truecfg!(debug_assertions) {
155            self.dump_constraints();
156        }
157
158        self.expansion(&mut var_data);
159        self.collect_errors(&mut var_data, errors);
160        self.collect_var_errors(&var_data, errors);
161        var_data
162    }
163
164    fn num_vars(&self) -> usize {
165        self.var_infos.len()
166    }
167
168    /// Initially, the value for all variables is set to `'empty`, the
169    /// empty region. The `expansion` phase will grow this larger.
170    fn construct_var_data(&self) -> LexicalRegionResolutions<'tcx> {
171        LexicalRegionResolutions {
172            values: IndexVec::<RegionVid, _>::from_fn_n(
173                |vid| {
174                    let vid_universe = self.var_infos[vid].universe;
175                    VarValue::Empty(vid_universe)
176                },
177                self.num_vars(),
178            ),
179        }
180    }
181
182    #[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("dump_constraints",
                                    "rustc_infer::infer::lexical_region_resolve",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(182u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set(&[]) })
                } 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;
        }
        {
            for (idx, (constraint, _)) in
                self.data.constraints.iter().enumerate() {
                {
                    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/lexical_region_resolve/mod.rs:185",
                                        "rustc_infer::infer::lexical_region_resolve",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(185u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&format_args!("Constraint {0} => {1:?}",
                                                                    idx, constraint) as &dyn Value))])
                            });
                    } else { ; }
                };
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
183    fn dump_constraints(&self) {
184        for (idx, (constraint, _)) in self.data.constraints.iter().enumerate() {
185            debug!("Constraint {} => {:?}", idx, constraint);
186        }
187    }
188
189    fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
190        // In the first pass, we expand region vids according to constraints we
191        // have previously found. In the second pass, we loop through the region
192        // vids we expanded and expand *across* region vids (effectively
193        // "expanding" new `RegSubVar` constraints).
194
195        // Tracks the `VarSubVar` constraints generated for each region vid. We
196        // later use this to expand across vids.
197        let mut constraints = IndexVec::from_elem(Vec::new(), &var_values.values);
198        // Tracks the changed region vids.
199        let mut changes = Vec::new();
200        for (c, _) in &self.data.constraints {
201            match c.kind {
202                ConstraintKind::RegSubVar => {
203                    let sup_vid = c.sup.as_var();
204                    let sup_data = var_values.value_mut(sup_vid);
205
206                    if self.expand_node(c.sub, sup_vid, sup_data) {
207                        changes.push(sup_vid);
208                    }
209                }
210                ConstraintKind::VarSubVar => {
211                    let sub_vid = c.sub.as_var();
212                    let sup_vid = c.sup.as_var();
213                    match *var_values.value(sub_vid) {
214                        VarValue::ErrorValue => continue,
215                        VarValue::Empty(sub_universe) => {
216                            let sup_data = var_values.value_mut(sup_vid);
217
218                            let changed = match *sup_data {
219                                VarValue::Empty(sup_universe) => {
220                                    // Empty regions are ordered according to the universe
221                                    // they are associated with.
222                                    let ui = sub_universe.min(sup_universe);
223
224                                    {
    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/lexical_region_resolve/mod.rs:224",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(224u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("Expanding value of {0:?} from empty lifetime with universe {1:?} to empty lifetime with universe {2:?}",
                                                    sup_vid, sup_universe, ui) as &dyn Value))])
            });
    } else { ; }
};debug!(
225                                        "Expanding value of {:?} \
226                                    from empty lifetime with universe {:?} \
227                                    to empty lifetime with universe {:?}",
228                                        sup_vid, sup_universe, ui
229                                    );
230
231                                    *sup_data = VarValue::Empty(ui);
232                                    true
233                                }
234                                VarValue::Value(cur_region) => {
235                                    match cur_region.kind() {
236                                        // If this empty region is from a universe that can name
237                                        // the placeholder universe, then the LUB is the
238                                        // Placeholder region (which is the cur_region). Otherwise,
239                                        // the LUB is the Static lifetime.
240                                        RePlaceholder(placeholder)
241                                            if !sub_universe.can_name(placeholder.universe) =>
242                                        {
243                                            let lub = self.tcx().lifetimes.re_static;
244                                            {
    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/lexical_region_resolve/mod.rs:244",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(244u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("Expanding value of {0:?} from {1:?} to {2:?}",
                                                    sup_vid, cur_region, lub) as &dyn Value))])
            });
    } else { ; }
};debug!(
245                                                "Expanding value of {:?} from {:?} to {:?}",
246                                                sup_vid, cur_region, lub
247                                            );
248
249                                            *sup_data = VarValue::Value(lub);
250                                            true
251                                        }
252
253                                        _ => false,
254                                    }
255                                }
256
257                                VarValue::ErrorValue => false,
258                            };
259
260                            if changed {
261                                changes.push(sup_vid);
262                            }
263                            match sup_data {
264                                VarValue::Value(Region(Interned(ReStatic, _)))
265                                | VarValue::ErrorValue => (),
266                                _ => {
267                                    constraints[sub_vid].push((sub_vid, sup_vid));
268                                    constraints[sup_vid].push((sub_vid, sup_vid));
269                                }
270                            }
271                        }
272                        VarValue::Value(sub_region) => {
273                            let sup_data = var_values.value_mut(sup_vid);
274
275                            if self.expand_node(sub_region, sup_vid, sup_data) {
276                                changes.push(sup_vid);
277                            }
278                            match sup_data {
279                                VarValue::Value(Region(Interned(ReStatic, _)))
280                                | VarValue::ErrorValue => (),
281                                _ => {
282                                    constraints[sub_vid].push((sub_vid, sup_vid));
283                                    constraints[sup_vid].push((sub_vid, sup_vid));
284                                }
285                            }
286                        }
287                    }
288                }
289                ConstraintKind::RegSubReg | ConstraintKind::VarSubReg => {
290                    // These constraints are checked after expansion
291                    // is done, in `collect_errors`.
292                    continue;
293                }
294
295                ConstraintKind::VarEqVar | ConstraintKind::VarEqReg | ConstraintKind::RegEqReg => {
296                    ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
297                }
298            }
299        }
300
301        while let Some(vid) = changes.pop() {
302            constraints[vid].retain(|&(a_vid, b_vid)| {
303                let VarValue::Value(a_region) = *var_values.value(a_vid) else {
304                    return false;
305                };
306                let b_data = var_values.value_mut(b_vid);
307                if self.expand_node(a_region, b_vid, b_data) {
308                    changes.push(b_vid);
309                }
310                !#[allow(non_exhaustive_omitted_patterns)] match b_data {
    VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue =>
        true,
    _ => false,
}matches!(
311                    b_data,
312                    VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue
313                )
314            });
315        }
316    }
317
318    /// Expands the value of the region represented with `b_vid` with current
319    /// value `b_data` to the lub of `b_data` and `a_region`. The corresponds
320    /// with the constraint `'?b: 'a` (`'a <: '?b`), where `'a` is some known
321    /// region and `'?b` is some region variable.
322    fn expand_node(
323        &self,
324        a_region: Region<'tcx>,
325        b_vid: RegionVid,
326        b_data: &mut VarValue<'tcx>,
327    ) -> bool {
328        {
    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/lexical_region_resolve/mod.rs:328",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(328u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("expand_node({0:?}, {1:?} == {2:?})",
                                                    a_region, b_vid, b_data) as &dyn Value))])
            });
    } else { ; }
};debug!("expand_node({:?}, {:?} == {:?})", a_region, b_vid, b_data);
329
330        match *b_data {
331            VarValue::Empty(empty_ui) => {
332                let lub = match a_region.kind() {
333                    RePlaceholder(placeholder) => {
334                        // If this empty region is from a universe that can
335                        // name the placeholder, then the placeholder is
336                        // larger; otherwise, the only ancestor is `'static`.
337                        if empty_ui.can_name(placeholder.universe) {
338                            ty::Region::new_placeholder(self.tcx(), placeholder)
339                        } else {
340                            self.tcx().lifetimes.re_static
341                        }
342                    }
343
344                    _ => a_region,
345                };
346
347                {
    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/lexical_region_resolve/mod.rs:347",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(347u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("Expanding value of {0:?} from empty lifetime to {1:?}",
                                                    b_vid, lub) as &dyn Value))])
            });
    } else { ; }
};debug!("Expanding value of {:?} from empty lifetime to {:?}", b_vid, lub);
348
349                *b_data = VarValue::Value(lub);
350                true
351            }
352            VarValue::Value(cur_region) => {
353                // This is a specialized version of the `lub_concrete_regions`
354                // check below for a common case, here purely as an
355                // optimization.
356                let b_universe = self.var_infos[b_vid].universe;
357
358                let mut lub = self.lub_concrete_regions(a_region, cur_region);
359                if lub == cur_region {
360                    return false;
361                }
362
363                // Watch out for `'b: !1` relationships, where the
364                // universe of `'b` can't name the placeholder `!1`. In
365                // that case, we have to grow `'b` to be `'static` for the
366                // relationship to hold. This is obviously a kind of sub-optimal
367                // choice -- in the future, when we incorporate a knowledge
368                // of the parameter environment, we might be able to find a
369                // tighter bound than `'static`.
370                //
371                // (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.)
372                if let ty::RePlaceholder(p) = lub.kind()
373                    && b_universe.cannot_name(p.universe)
374                {
375                    lub = self.tcx().lifetimes.re_static;
376                }
377
378                {
    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/lexical_region_resolve/mod.rs:378",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(378u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("Expanding value of {0:?} from {1:?} to {2:?}",
                                                    b_vid, cur_region, lub) as &dyn Value))])
            });
    } else { ; }
};debug!("Expanding value of {:?} from {:?} to {:?}", b_vid, cur_region, lub);
379
380                *b_data = VarValue::Value(lub);
381                true
382            }
383
384            VarValue::ErrorValue => false,
385        }
386    }
387
388    /// True if `a <= b`.
389    fn sub_region_values(&self, a: VarValue<'tcx>, b: VarValue<'tcx>) -> bool {
390        match (a, b) {
391            // Error region is `'static`
392            (VarValue::ErrorValue, _) | (_, VarValue::ErrorValue) => return true,
393            (VarValue::Empty(a_ui), VarValue::Empty(b_ui)) => {
394                // Empty regions are ordered according to the universe
395                // they are associated with.
396                a_ui.min(b_ui) == b_ui
397            }
398            (VarValue::Value(a), VarValue::Empty(_)) => {
399                match a.kind() {
400                    // this is always on an error path,
401                    // so it doesn't really matter if it's shorter or longer than an empty region
402                    ReError(_) => false,
403
404                    ReBound(..) | ReErased => {
405                        ::rustc_middle::util::bug::bug_fmt(format_args!("cannot relate region: {0:?}",
        a));bug!("cannot relate region: {:?}", a);
406                    }
407
408                    ReVar(v_id) => {
409                        ::rustc_middle::util::bug::span_bug_fmt(self.var_infos[v_id].origin.span(),
    format_args!("lub_concrete_regions invoked with non-concrete region: {0:?}",
        a));span_bug!(
410                            self.var_infos[v_id].origin.span(),
411                            "lub_concrete_regions invoked with non-concrete region: {:?}",
412                            a
413                        );
414                    }
415
416                    ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
417                        // nothing lives longer than `'static`
418
419                        // All empty regions are less than early-bound, free,
420                        // and scope regions.
421
422                        false
423                    }
424
425                    RePlaceholder(_) => {
426                        // The LUB is either `a` or `'static`
427                        false
428                    }
429                }
430            }
431            (VarValue::Empty(a_ui), VarValue::Value(b)) => {
432                match b.kind() {
433                    // this is always on an error path,
434                    // so it doesn't really matter if it's shorter or longer than an empty region
435                    ReError(_) => false,
436
437                    ReBound(..) | ReErased => {
438                        ::rustc_middle::util::bug::bug_fmt(format_args!("cannot relate region: {0:?}",
        b));bug!("cannot relate region: {:?}", b);
439                    }
440
441                    ReVar(v_id) => {
442                        ::rustc_middle::util::bug::span_bug_fmt(self.var_infos[v_id].origin.span(),
    format_args!("lub_concrete_regions invoked with non-concrete regions: {0:?}",
        b));span_bug!(
443                            self.var_infos[v_id].origin.span(),
444                            "lub_concrete_regions invoked with non-concrete regions: {:?}",
445                            b
446                        );
447                    }
448
449                    ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
450                        // nothing lives longer than `'static`
451                        // All empty regions are less than early-bound, late-bound,
452                        // and scope regions.
453                        true
454                    }
455
456                    RePlaceholder(placeholder) => {
457                        // If this empty region is from a universe that can
458                        // name the placeholder, then the placeholder is
459                        // larger; otherwise, the only ancestor is `'static`.
460                        return a_ui.can_name(placeholder.universe);
461                    }
462                }
463            }
464            (VarValue::Value(a), VarValue::Value(b)) => self.sub_concrete_regions(a, b),
465        }
466    }
467
468    /// True if `a <= b`, but not defined over inference variables.
469    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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("sub_concrete_regions",
                                    "rustc_infer::infer::lexical_region_resolve",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(469u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                    ::tracing_core::field::FieldSet::new(&["a", "b"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: bool = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let sub_free_regions =
                |r1, r2|
                    self.region_rels.free_regions.sub_free_regions(tcx, r1, r2);
            if b.is_free() && sub_free_regions(tcx.lifetimes.re_static, b) {
                return true;
            }
            if a.is_free() && b.is_free() { return sub_free_regions(a, b); }
            self.lub_concrete_regions(a, b) == b
        }
    }
}#[instrument(level = "trace", skip(self))]
470    fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
471        let tcx = self.tcx();
472        let sub_free_regions = |r1, r2| self.region_rels.free_regions.sub_free_regions(tcx, r1, r2);
473
474        // Check for the case where we know that `'b: 'static` -- in that case,
475        // `a <= b` for all `a`.
476        if b.is_free() && sub_free_regions(tcx.lifetimes.re_static, b) {
477            return true;
478        }
479
480        // If both `a` and `b` are free, consult the declared
481        // relationships. Note that this can be more precise than the
482        // `lub` relationship defined below, since sometimes the "lub"
483        // is actually the `postdom_upper_bound` (see
484        // `TransitiveRelation` for more details).
485        if a.is_free() && b.is_free() {
486            return sub_free_regions(a, b);
487        }
488
489        // For other cases, leverage the LUB code to find the LUB and
490        // check if it is equal to `b`.
491        self.lub_concrete_regions(a, b) == b
492    }
493
494    /// Returns the least-upper-bound of `a` and `b`; i.e., the
495    /// smallest region `c` such that `a <= c` and `b <= c`.
496    ///
497    /// Neither `a` nor `b` may be an inference variable (hence the
498    /// term "concrete regions").
499    x;#[instrument(level = "trace", skip(self), ret)]
500    fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
501        match (a.kind(), b.kind()) {
502            (ReBound(..), _) | (_, ReBound(..)) | (ReErased, _) | (_, ReErased) => {
503                bug!("cannot relate region: LUB({:?}, {:?})", a, b);
504            }
505
506            (ReVar(v_id), _) | (_, ReVar(v_id)) => {
507                span_bug!(
508                    self.var_infos[v_id].origin.span(),
509                    "lub_concrete_regions invoked with non-concrete \
510                     regions: {:?}, {:?}",
511                    a,
512                    b
513                );
514            }
515
516            (ReError(_), _) => a,
517
518            (_, ReError(_)) => b,
519
520            (ReStatic, _) | (_, ReStatic) => {
521                // nothing lives longer than `'static`
522                self.tcx().lifetimes.re_static
523            }
524
525            (ReEarlyParam(_) | ReLateParam(_), ReEarlyParam(_) | ReLateParam(_)) => {
526                self.region_rels.lub_param_regions(a, b)
527            }
528
529            // For these types, we cannot define any additional
530            // relationship:
531            (RePlaceholder(..), _) | (_, RePlaceholder(..)) => {
532                if a == b {
533                    a
534                } else {
535                    self.tcx().lifetimes.re_static
536                }
537            }
538        }
539    }
540
541    /// After expansion is complete, go and check upper bounds (i.e.,
542    /// cases where the region cannot grow larger than a fixed point)
543    /// and check that they are satisfied.
544    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
                ::tracing::Level::INFO <=
                    ::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("collect_errors",
                                    "rustc_infer::infer::lexical_region_resolve",
                                    ::tracing::Level::INFO,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(544u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::INFO <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::INFO <=
                                    ::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,
                        &{ meta.fields().value_set(&[]) })
                } 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;
        }
        {
            for (c, origin) in &self.data.constraints {
                {
                    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/lexical_region_resolve/mod.rs:551",
                                        "rustc_infer::infer::lexical_region_resolve",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(551u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                        ::tracing_core::field::FieldSet::new(&["c", "origin"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&debug(&c) as
                                                            &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&debug(&origin) as
                                                            &dyn Value))])
                            });
                    } else { ; }
                };
                match c.kind {
                    ConstraintKind::RegSubVar | ConstraintKind::VarSubVar => {}
                    ConstraintKind::RegSubReg => {
                        if self.sub_concrete_regions(c.sub, c.sup) { continue; }
                        {
                            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/lexical_region_resolve/mod.rs:562",
                                                "rustc_infer::infer::lexical_region_resolve",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(562u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        let mut iter = __CALLSITE.metadata().fields().iter();
                                        __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                            ::tracing::__macro_support::Option::Some(&format_args!("region error at {0:?}: cannot verify that {1:?} <= {2:?}",
                                                                            origin, c.sub, c.sup) as &dyn Value))])
                                    });
                            } else { ; }
                        };
                        errors.push(RegionResolutionError::ConcreteFailure((*origin).clone(),
                                c.sub, c.sup));
                    }
                    ConstraintKind::VarSubReg => {
                        let sub_vid = c.sub.as_var();
                        let sub_data = var_data.value_mut(sub_vid);
                        {
                            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/lexical_region_resolve/mod.rs:577",
                                                "rustc_infer::infer::lexical_region_resolve",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(577u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        let mut iter = __CALLSITE.metadata().fields().iter();
                                        __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                            ::tracing::__macro_support::Option::Some(&format_args!("contraction: {0:?} == {1:?}, {2:?}",
                                                                            sub_vid, sub_data, c.sup) as &dyn Value))])
                                    });
                            } else { ; }
                        };
                        let VarValue::Value(sub_region) =
                            *sub_data else { continue; };
                        if !self.sub_concrete_regions(sub_region, c.sup) {
                            {
                                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/lexical_region_resolve/mod.rs:587",
                                                    "rustc_infer::infer::lexical_region_resolve",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(587u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                                    ::tracing_core::field::FieldSet::new(&["message"],
                                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                    ::tracing::metadata::Kind::EVENT)
                                            };
                                        ::tracing::callsite::DefaultCallsite::new(&META)
                                    };
                                let enabled =
                                    ::tracing::Level::DEBUG <=
                                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                            ::tracing::Level::DEBUG <=
                                                ::tracing::level_filters::LevelFilter::current() &&
                                        {
                                            let interest = __CALLSITE.interest();
                                            !interest.is_never() &&
                                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                    interest)
                                        };
                                if enabled {
                                    (|value_set: ::tracing::field::ValueSet|
                                                {
                                                    let meta = __CALLSITE.metadata();
                                                    ::tracing::Event::dispatch(meta, &value_set);
                                                    ;
                                                })({
                                            #[allow(unused_imports)]
                                            use ::tracing::field::{debug, display, Value};
                                            let mut iter = __CALLSITE.metadata().fields().iter();
                                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                ::tracing::__macro_support::Option::Some(&format_args!("region error at {0:?}: cannot verify that {1:?}={2:?} <= {3:?}",
                                                                                origin, sub_vid, sub_region, c.sup) as &dyn Value))])
                                        });
                                } else { ; }
                            };
                            *sub_data = VarValue::ErrorValue;
                        }
                    }
                    ConstraintKind::VarEqVar | ConstraintKind::VarEqReg |
                        ConstraintKind::RegEqReg => {
                        ::core::panicking::panic("internal error: entered unreachable code")
                    }
                }
            }
            for verify in &self.data.verifys {
                {
                    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/lexical_region_resolve/mod.rs:602",
                                        "rustc_infer::infer::lexical_region_resolve",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(602u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&format_args!("collect_errors: verify={0:?}",
                                                                    verify) as &dyn Value))])
                            });
                    } else { ; }
                };
                let sub = var_data.normalize(self.tcx(), verify.region);
                let verify_kind_ty = verify.kind.to_ty(self.tcx());
                let verify_kind_ty =
                    var_data.normalize(self.tcx(), verify_kind_ty);
                if self.bound_is_met(&verify.bound, var_data, verify_kind_ty,
                        sub) {
                    continue;
                }
                {
                    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/lexical_region_resolve/mod.rs:611",
                                        "rustc_infer::infer::lexical_region_resolve",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(611u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&format_args!("collect_errors: region error at {0:?}: cannot verify that {1:?} <= {2:?}",
                                                                    verify.origin, verify.region, verify.bound) as
                                                            &dyn Value))])
                            });
                    } else { ; }
                };
                errors.push(RegionResolutionError::GenericBoundFailure(verify.origin.clone(),
                        verify.kind, sub));
            }
        }
    }
}#[instrument(skip(self, var_data, errors))]
545    fn collect_errors(
546        &self,
547        var_data: &mut LexicalRegionResolutions<'tcx>,
548        errors: &mut Vec<RegionResolutionError<'tcx>>,
549    ) {
550        for (c, origin) in &self.data.constraints {
551            debug!(?c, ?origin);
552            match c.kind {
553                ConstraintKind::RegSubVar | ConstraintKind::VarSubVar => {
554                    // Expansion will ensure that these constraints hold. Ignore.
555                }
556
557                ConstraintKind::RegSubReg => {
558                    if self.sub_concrete_regions(c.sub, c.sup) {
559                        continue;
560                    }
561
562                    debug!(
563                        "region error at {:?}: cannot verify that {:?} <= {:?}",
564                        origin, c.sub, c.sup
565                    );
566
567                    errors.push(RegionResolutionError::ConcreteFailure(
568                        (*origin).clone(),
569                        c.sub,
570                        c.sup,
571                    ));
572                }
573
574                ConstraintKind::VarSubReg => {
575                    let sub_vid = c.sub.as_var();
576                    let sub_data = var_data.value_mut(sub_vid);
577                    debug!("contraction: {:?} == {:?}, {:?}", sub_vid, sub_data, c.sup);
578
579                    let VarValue::Value(sub_region) = *sub_data else {
580                        continue;
581                    };
582
583                    // Do not report these errors immediately:
584                    // instead, set the variable value to error and
585                    // collect them later.
586                    if !self.sub_concrete_regions(sub_region, c.sup) {
587                        debug!(
588                            "region error at {:?}: cannot verify that {:?}={:?} <= {:?}",
589                            origin, sub_vid, sub_region, c.sup
590                        );
591                        *sub_data = VarValue::ErrorValue;
592                    }
593                }
594
595                ConstraintKind::VarEqVar | ConstraintKind::VarEqReg | ConstraintKind::RegEqReg => {
596                    unreachable!()
597                }
598            }
599        }
600
601        for verify in &self.data.verifys {
602            debug!("collect_errors: verify={:?}", verify);
603            let sub = var_data.normalize(self.tcx(), verify.region);
604
605            let verify_kind_ty = verify.kind.to_ty(self.tcx());
606            let verify_kind_ty = var_data.normalize(self.tcx(), verify_kind_ty);
607            if self.bound_is_met(&verify.bound, var_data, verify_kind_ty, sub) {
608                continue;
609            }
610
611            debug!(
612                "collect_errors: region error at {:?}: \
613                 cannot verify that {:?} <= {:?}",
614                verify.origin, verify.region, verify.bound
615            );
616
617            errors.push(RegionResolutionError::GenericBoundFailure(
618                verify.origin.clone(),
619                verify.kind,
620                sub,
621            ));
622        }
623    }
624
625    /// Go over the variables that were declared to be error variables
626    /// and create a `RegionResolutionError` for each of them.
627    fn collect_var_errors(
628        &self,
629        var_data: &LexicalRegionResolutions<'tcx>,
630        errors: &mut Vec<RegionResolutionError<'tcx>>,
631    ) {
632        {
    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/lexical_region_resolve/mod.rs:632",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(632u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("collect_var_errors, var_data = {0:#?}",
                                                    var_data.values) as &dyn Value))])
            });
    } else { ; }
};debug!("collect_var_errors, var_data = {:#?}", var_data.values);
633
634        // This is the best way that I have found to suppress
635        // duplicate and related errors. Basically we keep a set of
636        // flags for every node. Whenever an error occurs, we will
637        // walk some portion of the graph looking to find pairs of
638        // conflicting regions to report to the user. As we walk, we
639        // trip the flags from false to true, and if we find that
640        // we've already reported an error involving any particular
641        // node we just stop and don't report the current error. The
642        // idea is to report errors that derive from independent
643        // regions of the graph, but not those that derive from
644        // overlapping locations.
645        let mut dup_vec = IndexVec::from_elem_n(None, self.num_vars());
646
647        // Only construct the edge index when necessary, because it's moderately expensive.
648        let mut edges: Option<IndexedConstraintEdges<'_, 'tcx>> = None;
649
650        for (node_vid, value) in var_data.values.iter_enumerated() {
651            match *value {
652                VarValue::Empty(_) | VarValue::Value(_) => { /* Inference successful */ }
653                VarValue::ErrorValue => {
654                    // Inference impossible: this value contains
655                    // inconsistent constraints.
656                    //
657                    // I think that in this case we should report an
658                    // error now -- unlike the case above, we can't
659                    // wait to see whether the user needs the result
660                    // of this variable. The reason is that the mere
661                    // existence of this variable implies that the
662                    // region graph is inconsistent, whether or not it
663                    // is used.
664                    //
665                    // For example, we may have created a region
666                    // variable that is the GLB of two other regions
667                    // which do not have a GLB. Even if that variable
668                    // is not used, it implies that those two regions
669                    // *should* have a GLB.
670                    //
671                    // At least I think this is true. It may be that
672                    // the mere existence of a conflict in a region
673                    // variable that is not used is not a problem, so
674                    // if this rule starts to create problems we'll
675                    // have to revisit this portion of the code and
676                    // think hard about it. =) -- nikomatsakis
677
678                    // Obtain the spans for all the places that can
679                    // influence the constraints on this value for
680                    // richer diagnostics in `static_impl_trait`.
681
682                    let e = edges.get_or_insert_with(|| {
683                        IndexedConstraintEdges::build_index(self.num_vars(), &self.data)
684                    });
685                    self.collect_error_for_expanding_node(e, &mut dup_vec, node_vid, errors);
686                }
687            }
688        }
689    }
690
691    fn collect_error_for_expanding_node(
692        &self,
693        edges: &IndexedConstraintEdges<'_, 'tcx>,
694        dup_vec: &mut IndexSlice<RegionVid, Option<RegionVid>>,
695        node_idx: RegionVid,
696        errors: &mut Vec<RegionResolutionError<'tcx>>,
697    ) {
698        // Errors in expanding nodes result from a lower-bound that is
699        // not contained by an upper-bound.
700        let (mut lower_bounds, lower_vid_bounds, lower_dup) =
701            self.collect_bounding_regions(edges, node_idx, EdgeDirection::In, Some(dup_vec));
702        let (mut upper_bounds, _, upper_dup) =
703            self.collect_bounding_regions(edges, node_idx, EdgeDirection::Out, Some(dup_vec));
704
705        if lower_dup || upper_dup {
706            return;
707        }
708
709        // We place late-bound regions first because we are special casing
710        // SubSupConflict(ReLateParam, ReLateParam) when reporting error, and so
711        // the user will more likely get a specific suggestion.
712        fn region_order_key(x: &RegionAndOrigin<'_>) -> u8 {
713            match x.region.kind() {
714                ReEarlyParam(_) => 0,
715                ReLateParam(_) => 1,
716                _ => 2,
717            }
718        }
719        lower_bounds.sort_by_key(region_order_key);
720        upper_bounds.sort_by_key(region_order_key);
721
722        let node_universe = self.var_infos[node_idx].universe;
723
724        for lower_bound in &lower_bounds {
725            let effective_lower_bound = if let ty::RePlaceholder(p) = lower_bound.region.kind() {
726                if node_universe.cannot_name(p.universe) {
727                    self.tcx().lifetimes.re_static
728                } else {
729                    lower_bound.region
730                }
731            } else {
732                lower_bound.region
733            };
734
735            for upper_bound in &upper_bounds {
736                if !self.sub_concrete_regions(effective_lower_bound, upper_bound.region) {
737                    let origin = self.var_infos[node_idx].origin;
738                    {
    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/lexical_region_resolve/mod.rs:738",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(738u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("region inference error at {0:?} for {1:?}: SubSupConflict sub: {2:?} sup: {3:?}",
                                                    origin, node_idx, lower_bound.region, upper_bound.region) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(
739                        "region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
740                         sup: {:?}",
741                        origin, node_idx, lower_bound.region, upper_bound.region
742                    );
743
744                    errors.push(RegionResolutionError::SubSupConflict(
745                        node_idx,
746                        origin,
747                        lower_bound.origin.clone(),
748                        lower_bound.region,
749                        upper_bound.origin.clone(),
750                        upper_bound.region,
751                        ::alloc::vec::Vec::new()vec![],
752                    ));
753                    return;
754                }
755            }
756        }
757
758        // If we have a scenario like `exists<'a> { forall<'b> { 'b:
759        // 'a } }`, we wind up without any lower-bound -- all we have
760        // are placeholders as upper bounds, but the universe of the
761        // variable `'a`, or some variable that `'a` has to outlive, doesn't
762        // permit those placeholders.
763        //
764        // We only iterate to find the min, which means it doesn't cause reproducibility issues
765        #[allow(rustc::potential_query_instability)]
766        let min_universe = lower_vid_bounds
767            .into_iter()
768            .map(|vid| self.var_infos[vid].universe)
769            .min()
770            .expect("lower_vid_bounds should at least include `node_idx`");
771
772        for upper_bound in &upper_bounds {
773            if let ty::RePlaceholder(p) = upper_bound.region.kind() {
774                if min_universe.cannot_name(p.universe) {
775                    let origin = self.var_infos[node_idx].origin;
776                    errors.push(RegionResolutionError::UpperBoundUniverseConflict(
777                        node_idx,
778                        origin,
779                        min_universe,
780                        upper_bound.origin.clone(),
781                        upper_bound.region,
782                    ));
783                    return;
784                }
785            }
786        }
787
788        // Errors in earlier passes can yield error variables without
789        // resolution errors here; ICE if no errors have been emitted yet.
790        if !self.tcx().dcx().has_errors().is_some() {
    {
        ::core::panicking::panic_fmt(format_args!("collect_error_for_expanding_node() could not find error for var {0:?} in universe {1:?}, lower_bounds={2:#?}, upper_bounds={3:#?}",
                node_idx, node_universe, lower_bounds, upper_bounds));
    }
};assert!(
791            self.tcx().dcx().has_errors().is_some(),
792            "collect_error_for_expanding_node() could not find error for var {node_idx:?} in \
793            universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
794            upper_bounds={upper_bounds:#?}",
795        );
796    }
797
798    /// Collects all regions that "bound" the variable `orig_node_idx` in the
799    /// given direction.
800    ///
801    /// If `dup_vec` is `Some` it's used to track duplicates between successive
802    /// calls of this function.
803    ///
804    /// The return tuple fields are:
805    /// - a list of all concrete regions bounding the given region.
806    /// - the set of all region variables bounding the given region.
807    /// - a `bool` that's true if the returned region variables overlap with
808    ///   those returned by a previous call for another region.
809    fn collect_bounding_regions(
810        &self,
811        edges: &IndexedConstraintEdges<'_, 'tcx>,
812        orig_node_idx: RegionVid,
813        dir: EdgeDirection,
814        mut dup_vec: Option<&mut IndexSlice<RegionVid, Option<RegionVid>>>,
815    ) -> (Vec<RegionAndOrigin<'tcx>>, FxHashSet<RegionVid>, bool) {
816        struct WalkState<'tcx> {
817            set: FxHashSet<RegionVid>,
818            stack: Vec<RegionVid>,
819            result: Vec<RegionAndOrigin<'tcx>>,
820            dup_found: bool,
821        }
822        let mut state = WalkState {
823            set: Default::default(),
824            stack: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [orig_node_idx]))vec![orig_node_idx],
825            result: Vec::new(),
826            dup_found: false,
827        };
828        state.set.insert(orig_node_idx);
829
830        // to start off the process, walk the source node in the
831        // direction specified
832        process_edges(&mut state, edges, orig_node_idx, dir);
833
834        while let Some(node_idx) = state.stack.pop() {
835            // check whether we've visited this node on some previous walk
836            if let Some(dup_vec) = &mut dup_vec {
837                if dup_vec[node_idx].is_none() {
838                    dup_vec[node_idx] = Some(orig_node_idx);
839                } else if dup_vec[node_idx] != Some(orig_node_idx) {
840                    state.dup_found = true;
841                }
842
843                {
    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/lexical_region_resolve/mod.rs:843",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(843u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("collect_concrete_regions(orig_node_idx={0:?}, node_idx={1:?})",
                                                    orig_node_idx, node_idx) as &dyn Value))])
            });
    } else { ; }
};debug!(
844                    "collect_concrete_regions(orig_node_idx={:?}, node_idx={:?})",
845                    orig_node_idx, node_idx
846                );
847            }
848
849            process_edges(&mut state, edges, node_idx, dir);
850        }
851
852        let WalkState { result, dup_found, set, .. } = state;
853        return (result, set, dup_found);
854
855        fn process_edges<'tcx>(
856            state: &mut WalkState<'tcx>,
857            edges: &IndexedConstraintEdges<'_, 'tcx>,
858            source_vid: RegionVid,
859            dir: EdgeDirection,
860        ) {
861            {
    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/lexical_region_resolve/mod.rs:861",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(861u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("process_edges(source_vid={0:?}, dir={1:?})",
                                                    source_vid, dir) as &dyn Value))])
            });
    } else { ; }
};debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);
862
863            for (c, origin) in edges.adjacent_edges(source_vid, dir) {
864                match c.kind {
865                    ConstraintKind::VarSubVar => {
866                        let from_vid = c.sub.as_var();
867                        let to_vid = c.sup.as_var();
868                        let opp_vid = if from_vid == source_vid { to_vid } else { from_vid };
869                        if state.set.insert(opp_vid) {
870                            state.stack.push(opp_vid);
871                        }
872                    }
873
874                    ConstraintKind::RegSubVar => {
875                        let origin = (*origin).clone();
876                        state.result.push(RegionAndOrigin { region: c.sub, origin });
877                    }
878
879                    ConstraintKind::VarSubReg => {
880                        let origin = (*origin).clone();
881                        state.result.push(RegionAndOrigin { region: c.sup, origin });
882                    }
883
884                    ConstraintKind::RegSubReg => {
    ::core::panicking::panic_fmt(format_args!("cannot reach reg-sub-reg edge in region inference post-processing"));
}panic!(
885                        "cannot reach reg-sub-reg edge in region inference \
886                         post-processing"
887                    ),
888
889                    ConstraintKind::VarEqVar
890                    | ConstraintKind::VarEqReg
891                    | ConstraintKind::RegEqReg => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
892                }
893            }
894        }
895    }
896
897    fn bound_is_met(
898        &self,
899        bound: &VerifyBound<'tcx>,
900        var_values: &LexicalRegionResolutions<'tcx>,
901        generic_ty: Ty<'tcx>,
902        min: ty::Region<'tcx>,
903    ) -> bool {
904        if let ty::ReError(_) = min.kind() {
905            return true;
906        }
907
908        match bound {
909            VerifyBound::IfEq(verify_if_eq_b) => {
910                let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);
911                match test_type_match::extract_verify_if_eq(self.tcx(), &verify_if_eq_b, generic_ty)
912                {
913                    Some(r) => {
914                        self.bound_is_met(&VerifyBound::OutlivedBy(r), var_values, generic_ty, min)
915                    }
916
917                    None => false,
918                }
919            }
920
921            VerifyBound::OutlivedBy(r) => {
922                let a = match min.kind() {
923                    ty::ReVar(rid) => var_values.values[rid],
924                    _ => VarValue::Value(min),
925                };
926                let b = match r.kind() {
927                    ty::ReVar(rid) => var_values.values[rid],
928                    _ => VarValue::Value(*r),
929                };
930                self.sub_region_values(a, b)
931            }
932
933            VerifyBound::IsEmpty => match min.kind() {
934                ty::ReVar(rid) => match var_values.values[rid] {
935                    VarValue::ErrorValue => false,
936                    VarValue::Empty(_) => true,
937                    VarValue::Value(_) => false,
938                },
939                _ => false,
940            },
941
942            VerifyBound::AnyBound(bs) => {
943                bs.iter().any(|b| self.bound_is_met(b, var_values, generic_ty, min))
944            }
945
946            VerifyBound::AllBounds(bs) => {
947                bs.iter().all(|b| self.bound_is_met(b, var_values, generic_ty, min))
948            }
949        }
950    }
951}
952
953impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
954    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
955        f.write_fmt(format_args!("RegionAndOrigin({0:?},{1:?})", self.region,
        self.origin))write!(f, "RegionAndOrigin({:?},{:?})", self.region, self.origin)
956    }
957}
958
959impl<'tcx> LexicalRegionResolutions<'tcx> {
960    fn normalize<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
961    where
962        T: TypeFoldable<TyCtxt<'tcx>>,
963    {
964        fold_regions(tcx, value, |r, _db| self.resolve_region(tcx, r))
965    }
966
967    fn value(&self, rid: RegionVid) -> &VarValue<'tcx> {
968        &self.values[rid]
969    }
970
971    fn value_mut(&mut self, rid: RegionVid) -> &mut VarValue<'tcx> {
972        &mut self.values[rid]
973    }
974
975    pub(crate) fn resolve_region(
976        &self,
977        tcx: TyCtxt<'tcx>,
978        r: ty::Region<'tcx>,
979    ) -> ty::Region<'tcx> {
980        let result = match r.kind() {
981            ty::ReVar(rid) => match self.values[rid] {
982                VarValue::Empty(_) => r,
983                VarValue::Value(r) => r,
984                VarValue::ErrorValue => tcx.lifetimes.re_static,
985            },
986            _ => r,
987        };
988        {
    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/lexical_region_resolve/mod.rs:988",
                        "rustc_infer::infer::lexical_region_resolve",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(988u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::lexical_region_resolve"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("resolve_region({0:?}) = {1:?}",
                                                    r, result) as &dyn Value))])
            });
    } else { ; }
};debug!("resolve_region({:?}) = {:?}", r, result);
989        result
990    }
991}