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;
        }
        {
            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    let mut errors = vec![];
38    let mut resolver = LexicalResolver { region_rels, var_infos, data };
39    let values = resolver.infer_variable_values(&mut errors);
40    (values, errors)
41}
42
43/// Contains the result of lexical region resolution. Offers methods
44/// to lookup up the final value of a region variable.
45#[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)]
46pub(crate) struct LexicalRegionResolutions<'tcx> {
47    pub(crate) values: IndexVec<RegionVid, VarValue<'tcx>>,
48}
49
50#[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)]
51pub(crate) enum VarValue<'tcx> {
52    /// Empty lifetime is for data that is never accessed. We tag the
53    /// empty lifetime with a universe -- the idea is that we don't
54    /// want `exists<'a> { forall<'b> { 'b: 'a } }` to be satisfiable.
55    /// Therefore, the `'empty` in a universe `U` is less than all
56    /// regions visible from `U`, but not less than regions not visible
57    /// from `U`.
58    Empty(ty::UniverseIndex),
59    Value(Region<'tcx>),
60    ErrorValue,
61}
62
63#[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)]
64pub enum RegionResolutionError<'tcx> {
65    /// `ConcreteFailure(o, a, b)`:
66    ///
67    /// `o` requires that `a <= b`, but this does not hold
68    ConcreteFailure(SubregionOrigin<'tcx>, Region<'tcx>, Region<'tcx>),
69
70    /// `GenericBoundFailure(p, s, a)`:
71    ///
72    /// The parameter/associated-type `p` must be known to outlive the lifetime
73    /// `a` (but none of the known bounds are sufficient).
74    GenericBoundFailure(SubregionOrigin<'tcx>, GenericKind<'tcx>, Region<'tcx>),
75
76    /// `SubSupConflict(v, v_origin, sub_origin, sub_r, sup_origin, sup_r)`:
77    ///
78    /// Could not infer a value for `v` (which has origin `v_origin`)
79    /// because `sub_r <= v` (due to `sub_origin`) but `v <= sup_r` (due to `sup_origin`) and
80    /// `sub_r <= sup_r` does not hold.
81    SubSupConflict(
82        RegionVid,
83        RegionVariableOrigin<'tcx>,
84        SubregionOrigin<'tcx>,
85        Region<'tcx>,
86        SubregionOrigin<'tcx>,
87        Region<'tcx>,
88        Vec<Span>, // All the influences on a given value that didn't meet its constraints.
89    ),
90
91    /// Indicates a `'b: 'a` constraint where `'a` is in a universe that
92    /// cannot name the placeholder `'b`.
93    UpperBoundUniverseConflict(
94        RegionVid,
95        RegionVariableOrigin<'tcx>,
96        ty::UniverseIndex,     // the universe index of the region variable
97        SubregionOrigin<'tcx>, // cause of the constraint
98        Region<'tcx>,          // the placeholder `'b`
99    ),
100
101    CannotNormalize(ty::PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>),
102}
103
104impl<'tcx> RegionResolutionError<'tcx> {
105    pub fn origin(&self) -> &SubregionOrigin<'tcx> {
106        match self {
107            RegionResolutionError::ConcreteFailure(origin, _, _)
108            | RegionResolutionError::GenericBoundFailure(origin, _, _)
109            | RegionResolutionError::SubSupConflict(_, _, origin, _, _, _, _)
110            | RegionResolutionError::UpperBoundUniverseConflict(_, _, _, origin, _)
111            | RegionResolutionError::CannotNormalize(_, origin) => origin,
112        }
113    }
114}
115
116struct RegionAndOrigin<'tcx> {
117    region: Region<'tcx>,
118    origin: SubregionOrigin<'tcx>,
119}
120
121struct LexicalResolver<'cx, 'tcx> {
122    region_rels: &'cx RegionRelations<'cx, 'tcx>,
123    var_infos: VarInfos<'tcx>,
124    data: RegionConstraintData<'tcx>,
125}
126
127impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
128    fn tcx(&self) -> TyCtxt<'tcx> {
129        self.region_rels.tcx
130    }
131
132    fn infer_variable_values(
133        &mut self,
134        errors: &mut Vec<RegionResolutionError<'tcx>>,
135    ) -> LexicalRegionResolutions<'tcx> {
136        let mut var_data = self.construct_var_data();
137
138        // Deduplicating constraints is shown to have a positive perf impact.
139        let mut seen = UnordSet::default();
140        self.data.constraints.retain(|(constraint, _)| seen.insert(*constraint));
141
142        if truecfg!(debug_assertions) {
143            self.dump_constraints();
144        }
145
146        self.expansion(&mut var_data);
147        self.collect_errors(&mut var_data, errors);
148        self.collect_var_errors(&var_data, errors);
149        var_data
150    }
151
152    fn num_vars(&self) -> usize {
153        self.var_infos.len()
154    }
155
156    /// Initially, the value for all variables is set to `'empty`, the
157    /// empty region. The `expansion` phase will grow this larger.
158    fn construct_var_data(&self) -> LexicalRegionResolutions<'tcx> {
159        LexicalRegionResolutions {
160            values: IndexVec::<RegionVid, _>::from_fn_n(
161                |vid| {
162                    let vid_universe = self.var_infos[vid].universe;
163                    VarValue::Empty(vid_universe)
164                },
165                self.num_vars(),
166            ),
167        }
168    }
169
170    #[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(170u32),
                                    ::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:173",
                                        "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(173u32),
                                        ::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))]
171    fn dump_constraints(&self) {
172        for (idx, (constraint, _)) in self.data.constraints.iter().enumerate() {
173            debug!("Constraint {} => {:?}", idx, constraint);
174        }
175    }
176
177    fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
178        // In the first pass, we expand region vids according to constraints we
179        // have previously found. In the second pass, we loop through the region
180        // vids we expanded and expand *across* region vids (effectively
181        // "expanding" new `RegSubVar` constraints).
182
183        // Tracks the `VarSubVar` constraints generated for each region vid. We
184        // later use this to expand across vids.
185        let mut constraints = IndexVec::from_elem(Vec::new(), &var_values.values);
186        // Tracks the changed region vids.
187        let mut changes = Vec::new();
188        for (c, _) in &self.data.constraints {
189            match c.kind {
190                ConstraintKind::RegSubVar => {
191                    let sup_vid = c.sup.as_var();
192                    let sup_data = var_values.value_mut(sup_vid);
193
194                    if self.expand_node(c.sub, sup_vid, sup_data) {
195                        changes.push(sup_vid);
196                    }
197                }
198                ConstraintKind::VarSubVar => {
199                    let sub_vid = c.sub.as_var();
200                    let sup_vid = c.sup.as_var();
201                    match *var_values.value(sub_vid) {
202                        VarValue::ErrorValue => continue,
203                        VarValue::Empty(sub_universe) => {
204                            let sup_data = var_values.value_mut(sup_vid);
205
206                            let changed = match *sup_data {
207                                VarValue::Empty(sup_universe) => {
208                                    // Empty regions are ordered according to the universe
209                                    // they are associated with.
210                                    let ui = sub_universe.min(sup_universe);
211
212                                    {
    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:212",
                        "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(212u32),
                        ::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!(
213                                        "Expanding value of {:?} \
214                                    from empty lifetime with universe {:?} \
215                                    to empty lifetime with universe {:?}",
216                                        sup_vid, sup_universe, ui
217                                    );
218
219                                    *sup_data = VarValue::Empty(ui);
220                                    true
221                                }
222                                VarValue::Value(cur_region) => {
223                                    match cur_region.kind() {
224                                        // If this empty region is from a universe that can name
225                                        // the placeholder universe, then the LUB is the
226                                        // Placeholder region (which is the cur_region). Otherwise,
227                                        // the LUB is the Static lifetime.
228                                        RePlaceholder(placeholder)
229                                            if !sub_universe.can_name(placeholder.universe) =>
230                                        {
231                                            let lub = self.tcx().lifetimes.re_static;
232                                            {
    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:232",
                        "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(232u32),
                        ::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!(
233                                                "Expanding value of {:?} from {:?} to {:?}",
234                                                sup_vid, cur_region, lub
235                                            );
236
237                                            *sup_data = VarValue::Value(lub);
238                                            true
239                                        }
240
241                                        _ => false,
242                                    }
243                                }
244
245                                VarValue::ErrorValue => false,
246                            };
247
248                            if changed {
249                                changes.push(sup_vid);
250                            }
251                            match sup_data {
252                                VarValue::Value(Region(Interned(ReStatic, _)))
253                                | VarValue::ErrorValue => (),
254                                _ => {
255                                    constraints[sub_vid].push((sub_vid, sup_vid));
256                                    constraints[sup_vid].push((sub_vid, sup_vid));
257                                }
258                            }
259                        }
260                        VarValue::Value(sub_region) => {
261                            let sup_data = var_values.value_mut(sup_vid);
262
263                            if self.expand_node(sub_region, sup_vid, sup_data) {
264                                changes.push(sup_vid);
265                            }
266                            match sup_data {
267                                VarValue::Value(Region(Interned(ReStatic, _)))
268                                | VarValue::ErrorValue => (),
269                                _ => {
270                                    constraints[sub_vid].push((sub_vid, sup_vid));
271                                    constraints[sup_vid].push((sub_vid, sup_vid));
272                                }
273                            }
274                        }
275                    }
276                }
277                ConstraintKind::RegSubReg | ConstraintKind::VarSubReg => {
278                    // These constraints are checked after expansion
279                    // is done, in `collect_errors`.
280                    continue;
281                }
282            }
283        }
284
285        while let Some(vid) = changes.pop() {
286            constraints[vid].retain(|&(a_vid, b_vid)| {
287                let VarValue::Value(a_region) = *var_values.value(a_vid) else {
288                    return false;
289                };
290                let b_data = var_values.value_mut(b_vid);
291                if self.expand_node(a_region, b_vid, b_data) {
292                    changes.push(b_vid);
293                }
294                !#[allow(non_exhaustive_omitted_patterns)] match b_data {
    VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue =>
        true,
    _ => false,
}matches!(
295                    b_data,
296                    VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue
297                )
298            });
299        }
300    }
301
302    /// Expands the value of the region represented with `b_vid` with current
303    /// value `b_data` to the lub of `b_data` and `a_region`. The corresponds
304    /// with the constraint `'?b: 'a` (`'a <: '?b`), where `'a` is some known
305    /// region and `'?b` is some region variable.
306    fn expand_node(
307        &self,
308        a_region: Region<'tcx>,
309        b_vid: RegionVid,
310        b_data: &mut VarValue<'tcx>,
311    ) -> bool {
312        {
    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:312",
                        "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(312u32),
                        ::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);
313
314        match *b_data {
315            VarValue::Empty(empty_ui) => {
316                let lub = match a_region.kind() {
317                    RePlaceholder(placeholder) => {
318                        // If this empty region is from a universe that can
319                        // name the placeholder, then the placeholder is
320                        // larger; otherwise, the only ancestor is `'static`.
321                        if empty_ui.can_name(placeholder.universe) {
322                            ty::Region::new_placeholder(self.tcx(), placeholder)
323                        } else {
324                            self.tcx().lifetimes.re_static
325                        }
326                    }
327
328                    _ => a_region,
329                };
330
331                {
    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:331",
                        "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(331u32),
                        ::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);
332
333                *b_data = VarValue::Value(lub);
334                true
335            }
336            VarValue::Value(cur_region) => {
337                // This is a specialized version of the `lub_concrete_regions`
338                // check below for a common case, here purely as an
339                // optimization.
340                let b_universe = self.var_infos[b_vid].universe;
341
342                let mut lub = self.lub_concrete_regions(a_region, cur_region);
343                if lub == cur_region {
344                    return false;
345                }
346
347                // Watch out for `'b: !1` relationships, where the
348                // universe of `'b` can't name the placeholder `!1`. In
349                // that case, we have to grow `'b` to be `'static` for the
350                // relationship to hold. This is obviously a kind of sub-optimal
351                // choice -- in the future, when we incorporate a knowledge
352                // of the parameter environment, we might be able to find a
353                // tighter bound than `'static`.
354                //
355                // (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.)
356                if let ty::RePlaceholder(p) = lub.kind()
357                    && b_universe.cannot_name(p.universe)
358                {
359                    lub = self.tcx().lifetimes.re_static;
360                }
361
362                {
    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:362",
                        "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(362u32),
                        ::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);
363
364                *b_data = VarValue::Value(lub);
365                true
366            }
367
368            VarValue::ErrorValue => false,
369        }
370    }
371
372    /// True if `a <= b`.
373    fn sub_region_values(&self, a: VarValue<'tcx>, b: VarValue<'tcx>) -> bool {
374        match (a, b) {
375            // Error region is `'static`
376            (VarValue::ErrorValue, _) | (_, VarValue::ErrorValue) => return true,
377            (VarValue::Empty(a_ui), VarValue::Empty(b_ui)) => {
378                // Empty regions are ordered according to the universe
379                // they are associated with.
380                a_ui.min(b_ui) == b_ui
381            }
382            (VarValue::Value(a), VarValue::Empty(_)) => {
383                match a.kind() {
384                    // this is always on an error path,
385                    // so it doesn't really matter if it's shorter or longer than an empty region
386                    ReError(_) => false,
387
388                    ReBound(..) | ReErased => {
389                        ::rustc_middle::util::bug::bug_fmt(format_args!("cannot relate region: {0:?}",
        a));bug!("cannot relate region: {:?}", a);
390                    }
391
392                    ReVar(v_id) => {
393                        ::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!(
394                            self.var_infos[v_id].origin.span(),
395                            "lub_concrete_regions invoked with non-concrete region: {:?}",
396                            a
397                        );
398                    }
399
400                    ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
401                        // nothing lives longer than `'static`
402
403                        // All empty regions are less than early-bound, free,
404                        // and scope regions.
405
406                        false
407                    }
408
409                    RePlaceholder(_) => {
410                        // The LUB is either `a` or `'static`
411                        false
412                    }
413                }
414            }
415            (VarValue::Empty(a_ui), VarValue::Value(b)) => {
416                match b.kind() {
417                    // this is always on an error path,
418                    // so it doesn't really matter if it's shorter or longer than an empty region
419                    ReError(_) => false,
420
421                    ReBound(..) | ReErased => {
422                        ::rustc_middle::util::bug::bug_fmt(format_args!("cannot relate region: {0:?}",
        b));bug!("cannot relate region: {:?}", b);
423                    }
424
425                    ReVar(v_id) => {
426                        ::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!(
427                            self.var_infos[v_id].origin.span(),
428                            "lub_concrete_regions invoked with non-concrete regions: {:?}",
429                            b
430                        );
431                    }
432
433                    ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
434                        // nothing lives longer than `'static`
435                        // All empty regions are less than early-bound, late-bound,
436                        // and scope regions.
437                        true
438                    }
439
440                    RePlaceholder(placeholder) => {
441                        // If this empty region is from a universe that can
442                        // name the placeholder, then the placeholder is
443                        // larger; otherwise, the only ancestor is `'static`.
444                        return a_ui.can_name(placeholder.universe);
445                    }
446                }
447            }
448            (VarValue::Value(a), VarValue::Value(b)) => self.sub_concrete_regions(a, b),
449        }
450    }
451
452    /// True if `a <= b`, but not defined over inference variables.
453    #[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(453u32),
                                    ::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))]
454    fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
455        let tcx = self.tcx();
456        let sub_free_regions = |r1, r2| self.region_rels.free_regions.sub_free_regions(tcx, r1, r2);
457
458        // Check for the case where we know that `'b: 'static` -- in that case,
459        // `a <= b` for all `a`.
460        if b.is_free() && sub_free_regions(tcx.lifetimes.re_static, b) {
461            return true;
462        }
463
464        // If both `a` and `b` are free, consult the declared
465        // relationships. Note that this can be more precise than the
466        // `lub` relationship defined below, since sometimes the "lub"
467        // is actually the `postdom_upper_bound` (see
468        // `TransitiveRelation` for more details).
469        if a.is_free() && b.is_free() {
470            return sub_free_regions(a, b);
471        }
472
473        // For other cases, leverage the LUB code to find the LUB and
474        // check if it is equal to `b`.
475        self.lub_concrete_regions(a, b) == b
476    }
477
478    /// Returns the least-upper-bound of `a` and `b`; i.e., the
479    /// smallest region `c` such that `a <= c` and `b <= c`.
480    ///
481    /// Neither `a` nor `b` may be an inference variable (hence the
482    /// term "concrete regions").
483    x;#[instrument(level = "trace", skip(self), ret)]
484    fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
485        match (a.kind(), b.kind()) {
486            (ReBound(..), _) | (_, ReBound(..)) | (ReErased, _) | (_, ReErased) => {
487                bug!("cannot relate region: LUB({:?}, {:?})", a, b);
488            }
489
490            (ReVar(v_id), _) | (_, ReVar(v_id)) => {
491                span_bug!(
492                    self.var_infos[v_id].origin.span(),
493                    "lub_concrete_regions invoked with non-concrete \
494                     regions: {:?}, {:?}",
495                    a,
496                    b
497                );
498            }
499
500            (ReError(_), _) => a,
501
502            (_, ReError(_)) => b,
503
504            (ReStatic, _) | (_, ReStatic) => {
505                // nothing lives longer than `'static`
506                self.tcx().lifetimes.re_static
507            }
508
509            (ReEarlyParam(_) | ReLateParam(_), ReEarlyParam(_) | ReLateParam(_)) => {
510                self.region_rels.lub_param_regions(a, b)
511            }
512
513            // For these types, we cannot define any additional
514            // relationship:
515            (RePlaceholder(..), _) | (_, RePlaceholder(..)) => {
516                if a == b {
517                    a
518                } else {
519                    self.tcx().lifetimes.re_static
520                }
521            }
522        }
523    }
524
525    /// After expansion is complete, go and check upper bounds (i.e.,
526    /// cases where the region cannot grow larger than a fixed point)
527    /// and check that they are satisfied.
528    #[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(528u32),
                                    ::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:535",
                                        "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(535u32),
                                        ::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:546",
                                                "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(546u32),
                                                ::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:561",
                                                "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(561u32),
                                                ::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:571",
                                                    "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(571u32),
                                                    ::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;
                        }
                    }
                }
            }
            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:582",
                                        "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(582u32),
                                        ::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:591",
                                        "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(591u32),
                                        ::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))]
529    fn collect_errors(
530        &self,
531        var_data: &mut LexicalRegionResolutions<'tcx>,
532        errors: &mut Vec<RegionResolutionError<'tcx>>,
533    ) {
534        for (c, origin) in &self.data.constraints {
535            debug!(?c, ?origin);
536            match c.kind {
537                ConstraintKind::RegSubVar | ConstraintKind::VarSubVar => {
538                    // Expansion will ensure that these constraints hold. Ignore.
539                }
540
541                ConstraintKind::RegSubReg => {
542                    if self.sub_concrete_regions(c.sub, c.sup) {
543                        continue;
544                    }
545
546                    debug!(
547                        "region error at {:?}: cannot verify that {:?} <= {:?}",
548                        origin, c.sub, c.sup
549                    );
550
551                    errors.push(RegionResolutionError::ConcreteFailure(
552                        (*origin).clone(),
553                        c.sub,
554                        c.sup,
555                    ));
556                }
557
558                ConstraintKind::VarSubReg => {
559                    let sub_vid = c.sub.as_var();
560                    let sub_data = var_data.value_mut(sub_vid);
561                    debug!("contraction: {:?} == {:?}, {:?}", sub_vid, sub_data, c.sup);
562
563                    let VarValue::Value(sub_region) = *sub_data else {
564                        continue;
565                    };
566
567                    // Do not report these errors immediately:
568                    // instead, set the variable value to error and
569                    // collect them later.
570                    if !self.sub_concrete_regions(sub_region, c.sup) {
571                        debug!(
572                            "region error at {:?}: cannot verify that {:?}={:?} <= {:?}",
573                            origin, sub_vid, sub_region, c.sup
574                        );
575                        *sub_data = VarValue::ErrorValue;
576                    }
577                }
578            }
579        }
580
581        for verify in &self.data.verifys {
582            debug!("collect_errors: verify={:?}", verify);
583            let sub = var_data.normalize(self.tcx(), verify.region);
584
585            let verify_kind_ty = verify.kind.to_ty(self.tcx());
586            let verify_kind_ty = var_data.normalize(self.tcx(), verify_kind_ty);
587            if self.bound_is_met(&verify.bound, var_data, verify_kind_ty, sub) {
588                continue;
589            }
590
591            debug!(
592                "collect_errors: region error at {:?}: \
593                 cannot verify that {:?} <= {:?}",
594                verify.origin, verify.region, verify.bound
595            );
596
597            errors.push(RegionResolutionError::GenericBoundFailure(
598                verify.origin.clone(),
599                verify.kind,
600                sub,
601            ));
602        }
603    }
604
605    /// Go over the variables that were declared to be error variables
606    /// and create a `RegionResolutionError` for each of them.
607    fn collect_var_errors(
608        &self,
609        var_data: &LexicalRegionResolutions<'tcx>,
610        errors: &mut Vec<RegionResolutionError<'tcx>>,
611    ) {
612        {
    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:612",
                        "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(612u32),
                        ::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);
613
614        // This is the best way that I have found to suppress
615        // duplicate and related errors. Basically we keep a set of
616        // flags for every node. Whenever an error occurs, we will
617        // walk some portion of the graph looking to find pairs of
618        // conflicting regions to report to the user. As we walk, we
619        // trip the flags from false to true, and if we find that
620        // we've already reported an error involving any particular
621        // node we just stop and don't report the current error. The
622        // idea is to report errors that derive from independent
623        // regions of the graph, but not those that derive from
624        // overlapping locations.
625        let mut dup_vec = IndexVec::from_elem_n(None, self.num_vars());
626
627        // Only construct the edge index when necessary, because it's moderately expensive.
628        let mut edges: Option<IndexedConstraintEdges<'_, 'tcx>> = None;
629
630        for (node_vid, value) in var_data.values.iter_enumerated() {
631            match *value {
632                VarValue::Empty(_) | VarValue::Value(_) => { /* Inference successful */ }
633                VarValue::ErrorValue => {
634                    // Inference impossible: this value contains
635                    // inconsistent constraints.
636                    //
637                    // I think that in this case we should report an
638                    // error now -- unlike the case above, we can't
639                    // wait to see whether the user needs the result
640                    // of this variable. The reason is that the mere
641                    // existence of this variable implies that the
642                    // region graph is inconsistent, whether or not it
643                    // is used.
644                    //
645                    // For example, we may have created a region
646                    // variable that is the GLB of two other regions
647                    // which do not have a GLB. Even if that variable
648                    // is not used, it implies that those two regions
649                    // *should* have a GLB.
650                    //
651                    // At least I think this is true. It may be that
652                    // the mere existence of a conflict in a region
653                    // variable that is not used is not a problem, so
654                    // if this rule starts to create problems we'll
655                    // have to revisit this portion of the code and
656                    // think hard about it. =) -- nikomatsakis
657
658                    // Obtain the spans for all the places that can
659                    // influence the constraints on this value for
660                    // richer diagnostics in `static_impl_trait`.
661
662                    let e = edges.get_or_insert_with(|| {
663                        IndexedConstraintEdges::build_index(self.num_vars(), &self.data)
664                    });
665                    self.collect_error_for_expanding_node(e, &mut dup_vec, node_vid, errors);
666                }
667            }
668        }
669    }
670
671    fn collect_error_for_expanding_node(
672        &self,
673        edges: &IndexedConstraintEdges<'_, 'tcx>,
674        dup_vec: &mut IndexSlice<RegionVid, Option<RegionVid>>,
675        node_idx: RegionVid,
676        errors: &mut Vec<RegionResolutionError<'tcx>>,
677    ) {
678        // Errors in expanding nodes result from a lower-bound that is
679        // not contained by an upper-bound.
680        let (mut lower_bounds, lower_vid_bounds, lower_dup) =
681            self.collect_bounding_regions(edges, node_idx, EdgeDirection::In, Some(dup_vec));
682        let (mut upper_bounds, _, upper_dup) =
683            self.collect_bounding_regions(edges, node_idx, EdgeDirection::Out, Some(dup_vec));
684
685        if lower_dup || upper_dup {
686            return;
687        }
688
689        // We place late-bound regions first because we are special casing
690        // SubSupConflict(ReLateParam, ReLateParam) when reporting error, and so
691        // the user will more likely get a specific suggestion.
692        fn region_order_key(x: &RegionAndOrigin<'_>) -> u8 {
693            match x.region.kind() {
694                ReEarlyParam(_) => 0,
695                ReLateParam(_) => 1,
696                _ => 2,
697            }
698        }
699        lower_bounds.sort_by_key(region_order_key);
700        upper_bounds.sort_by_key(region_order_key);
701
702        let node_universe = self.var_infos[node_idx].universe;
703
704        for lower_bound in &lower_bounds {
705            let effective_lower_bound = if let ty::RePlaceholder(p) = lower_bound.region.kind() {
706                if node_universe.cannot_name(p.universe) {
707                    self.tcx().lifetimes.re_static
708                } else {
709                    lower_bound.region
710                }
711            } else {
712                lower_bound.region
713            };
714
715            for upper_bound in &upper_bounds {
716                if !self.sub_concrete_regions(effective_lower_bound, upper_bound.region) {
717                    let origin = self.var_infos[node_idx].origin;
718                    {
    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:718",
                        "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(718u32),
                        ::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!(
719                        "region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
720                         sup: {:?}",
721                        origin, node_idx, lower_bound.region, upper_bound.region
722                    );
723
724                    errors.push(RegionResolutionError::SubSupConflict(
725                        node_idx,
726                        origin,
727                        lower_bound.origin.clone(),
728                        lower_bound.region,
729                        upper_bound.origin.clone(),
730                        upper_bound.region,
731                        ::alloc::vec::Vec::new()vec![],
732                    ));
733                    return;
734                }
735            }
736        }
737
738        // If we have a scenario like `exists<'a> { forall<'b> { 'b:
739        // 'a } }`, we wind up without any lower-bound -- all we have
740        // are placeholders as upper bounds, but the universe of the
741        // variable `'a`, or some variable that `'a` has to outlive, doesn't
742        // permit those placeholders.
743        //
744        // We only iterate to find the min, which means it doesn't cause reproducibility issues
745        #[allow(rustc::potential_query_instability)]
746        let min_universe = lower_vid_bounds
747            .into_iter()
748            .map(|vid| self.var_infos[vid].universe)
749            .min()
750            .expect("lower_vid_bounds should at least include `node_idx`");
751
752        for upper_bound in &upper_bounds {
753            if let ty::RePlaceholder(p) = upper_bound.region.kind() {
754                if min_universe.cannot_name(p.universe) {
755                    let origin = self.var_infos[node_idx].origin;
756                    errors.push(RegionResolutionError::UpperBoundUniverseConflict(
757                        node_idx,
758                        origin,
759                        min_universe,
760                        upper_bound.origin.clone(),
761                        upper_bound.region,
762                    ));
763                    return;
764                }
765            }
766        }
767
768        // Errors in earlier passes can yield error variables without
769        // resolution errors here; ICE if no errors have been emitted yet.
770        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!(
771            self.tcx().dcx().has_errors().is_some(),
772            "collect_error_for_expanding_node() could not find error for var {node_idx:?} in \
773            universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
774            upper_bounds={upper_bounds:#?}",
775        );
776    }
777
778    /// Collects all regions that "bound" the variable `orig_node_idx` in the
779    /// given direction.
780    ///
781    /// If `dup_vec` is `Some` it's used to track duplicates between successive
782    /// calls of this function.
783    ///
784    /// The return tuple fields are:
785    /// - a list of all concrete regions bounding the given region.
786    /// - the set of all region variables bounding the given region.
787    /// - a `bool` that's true if the returned region variables overlap with
788    ///   those returned by a previous call for another region.
789    fn collect_bounding_regions(
790        &self,
791        edges: &IndexedConstraintEdges<'_, 'tcx>,
792        orig_node_idx: RegionVid,
793        dir: EdgeDirection,
794        mut dup_vec: Option<&mut IndexSlice<RegionVid, Option<RegionVid>>>,
795    ) -> (Vec<RegionAndOrigin<'tcx>>, FxHashSet<RegionVid>, bool) {
796        struct WalkState<'tcx> {
797            set: FxHashSet<RegionVid>,
798            stack: Vec<RegionVid>,
799            result: Vec<RegionAndOrigin<'tcx>>,
800            dup_found: bool,
801        }
802        let mut state = WalkState {
803            set: Default::default(),
804            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],
805            result: Vec::new(),
806            dup_found: false,
807        };
808        state.set.insert(orig_node_idx);
809
810        // to start off the process, walk the source node in the
811        // direction specified
812        process_edges(&mut state, edges, orig_node_idx, dir);
813
814        while let Some(node_idx) = state.stack.pop() {
815            // check whether we've visited this node on some previous walk
816            if let Some(dup_vec) = &mut dup_vec {
817                if dup_vec[node_idx].is_none() {
818                    dup_vec[node_idx] = Some(orig_node_idx);
819                } else if dup_vec[node_idx] != Some(orig_node_idx) {
820                    state.dup_found = true;
821                }
822
823                {
    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:823",
                        "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(823u32),
                        ::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!(
824                    "collect_concrete_regions(orig_node_idx={:?}, node_idx={:?})",
825                    orig_node_idx, node_idx
826                );
827            }
828
829            process_edges(&mut state, edges, node_idx, dir);
830        }
831
832        let WalkState { result, dup_found, set, .. } = state;
833        return (result, set, dup_found);
834
835        fn process_edges<'tcx>(
836            state: &mut WalkState<'tcx>,
837            edges: &IndexedConstraintEdges<'_, 'tcx>,
838            source_vid: RegionVid,
839            dir: EdgeDirection,
840        ) {
841            {
    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:841",
                        "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(841u32),
                        ::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);
842
843            for (c, origin) in edges.adjacent_edges(source_vid, dir) {
844                match c.kind {
845                    ConstraintKind::VarSubVar => {
846                        let from_vid = c.sub.as_var();
847                        let to_vid = c.sup.as_var();
848                        let opp_vid = if from_vid == source_vid { to_vid } else { from_vid };
849                        if state.set.insert(opp_vid) {
850                            state.stack.push(opp_vid);
851                        }
852                    }
853
854                    ConstraintKind::RegSubVar => {
855                        let origin = origin.clone();
856                        state.result.push(RegionAndOrigin { region: c.sub, origin });
857                    }
858
859                    ConstraintKind::VarSubReg => {
860                        let origin = origin.clone();
861                        state.result.push(RegionAndOrigin { region: c.sup, origin });
862                    }
863
864                    ConstraintKind::RegSubReg => {
    ::core::panicking::panic_fmt(format_args!("cannot reach reg-sub-reg edge in region inference post-processing"));
}panic!(
865                        "cannot reach reg-sub-reg edge in region inference \
866                         post-processing"
867                    ),
868                }
869            }
870        }
871    }
872
873    fn bound_is_met(
874        &self,
875        bound: &VerifyBound<'tcx>,
876        var_values: &LexicalRegionResolutions<'tcx>,
877        generic_ty: Ty<'tcx>,
878        min: ty::Region<'tcx>,
879    ) -> bool {
880        if let ty::ReError(_) = min.kind() {
881            return true;
882        }
883
884        match bound {
885            VerifyBound::IfEq(verify_if_eq_b) => {
886                let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);
887                match test_type_match::extract_verify_if_eq(self.tcx(), &verify_if_eq_b, generic_ty)
888                {
889                    Some(r) => {
890                        self.bound_is_met(&VerifyBound::OutlivedBy(r), var_values, generic_ty, min)
891                    }
892
893                    None => false,
894                }
895            }
896
897            VerifyBound::OutlivedBy(r) => {
898                let a = match min.kind() {
899                    ty::ReVar(rid) => var_values.values[rid],
900                    _ => VarValue::Value(min),
901                };
902                let b = match r.kind() {
903                    ty::ReVar(rid) => var_values.values[rid],
904                    _ => VarValue::Value(*r),
905                };
906                self.sub_region_values(a, b)
907            }
908
909            VerifyBound::IsEmpty => match min.kind() {
910                ty::ReVar(rid) => match var_values.values[rid] {
911                    VarValue::ErrorValue => false,
912                    VarValue::Empty(_) => true,
913                    VarValue::Value(_) => false,
914                },
915                _ => false,
916            },
917
918            VerifyBound::AnyBound(bs) => {
919                bs.iter().any(|b| self.bound_is_met(b, var_values, generic_ty, min))
920            }
921
922            VerifyBound::AllBounds(bs) => {
923                bs.iter().all(|b| self.bound_is_met(b, var_values, generic_ty, min))
924            }
925        }
926    }
927}
928
929impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
930    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
931        f.write_fmt(format_args!("RegionAndOrigin({0:?},{1:?})", self.region,
        self.origin))write!(f, "RegionAndOrigin({:?},{:?})", self.region, self.origin)
932    }
933}
934
935impl<'tcx> LexicalRegionResolutions<'tcx> {
936    fn normalize<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
937    where
938        T: TypeFoldable<TyCtxt<'tcx>>,
939    {
940        fold_regions(tcx, value, |r, _db| self.resolve_region(tcx, r))
941    }
942
943    fn value(&self, rid: RegionVid) -> &VarValue<'tcx> {
944        &self.values[rid]
945    }
946
947    fn value_mut(&mut self, rid: RegionVid) -> &mut VarValue<'tcx> {
948        &mut self.values[rid]
949    }
950
951    pub(crate) fn resolve_region(
952        &self,
953        tcx: TyCtxt<'tcx>,
954        r: ty::Region<'tcx>,
955    ) -> ty::Region<'tcx> {
956        let result = match r.kind() {
957            ty::ReVar(rid) => match self.values[rid] {
958                VarValue::Empty(_) => r,
959                VarValue::Value(r) => r,
960                VarValue::ErrorValue => tcx.lifetimes.re_static,
961            },
962            _ => r,
963        };
964        {
    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:964",
                        "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(964u32),
                        ::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);
965        result
966    }
967}