Skip to main content

rustc_infer/infer/outlives/
obligations.rs

1//! Code that handles "type-outlives" constraints like `T: 'a`. This
2//! is based on the `push_outlives_components` function defined in rustc_infer,
3//! but it adds a bit of heuristics on top, in particular to deal with
4//! associated types and projections.
5//!
6//! When we process a given `T: 'a` obligation, we may produce two
7//! kinds of constraints for the region inferencer:
8//!
9//! - Relationships between inference variables and other regions.
10//!   For example, if we have `&'?0 u32: 'a`, then we would produce
11//!   a constraint that `'a <= '?0`.
12//! - "Verifys" that must be checked after inferencing is done.
13//!   For example, if we know that, for some type parameter `T`,
14//!   `T: 'a + 'b`, and we have a requirement that `T: '?1`,
15//!   then we add a "verify" that checks that `'?1 <= 'a || '?1 <= 'b`.
16//!   - Note the difference with the previous case: here, the region
17//!     variable must be less than something else, so this doesn't
18//!     affect how inference works (it finds the smallest region that
19//!     will do); it's just a post-condition that we have to check.
20//!
21//! **The key point is that once this function is done, we have
22//! reduced all of our "type-region outlives" obligations into relationships
23//! between individual regions.**
24//!
25//! One key input to this function is the set of "region-bound pairs".
26//! These are basically the relationships between type parameters and
27//! regions that are in scope at the point where the outlives
28//! obligation was incurred. **When type-checking a function,
29//! particularly in the face of closures, this is not known until
30//! regionck runs!** This is because some of those bounds come
31//! from things we have yet to infer.
32//!
33//! Consider:
34//!
35//! ```
36//! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)) {}
37//! fn foo<T>(x: T) {
38//!     bar(x, |y| { /* ... */})
39//!     //      ^ closure arg
40//! }
41//! ```
42//!
43//! Here, the type of `y` may involve inference variables and the
44//! like, and it may also contain implied bounds that are needed to
45//! type-check the closure body (e.g., here it informs us that `T`
46//! outlives the late-bound region `'a`).
47//!
48//! Note that by delaying the gathering of implied bounds until all
49//! inference information is known, we may find relationships between
50//! bound regions and other regions in the environment. For example,
51//! when we first check a closure like the one expected as argument
52//! to `foo`:
53//!
54//! ```
55//! fn foo<U, F: for<'a> FnMut(&'a U)>(_f: F) {}
56//! ```
57//!
58//! the type of the closure's first argument would be `&'a ?U`. We
59//! might later infer `?U` to something like `&'b u32`, which would
60//! imply that `'b: 'a`.
61
62use rustc_data_structures::undo_log::UndoLogs;
63use rustc_middle::bug;
64use rustc_middle::mir::ConstraintCategory;
65use rustc_middle::traits::query::NoSolution;
66use rustc_middle::ty::outlives::{Component, push_outlives_components};
67use rustc_middle::ty::{
68    self, GenericArgKind, GenericArgsRef, PolyTypeOutlivesPredicate, Region, Ty, TyCtxt,
69    TypeFoldable as _, TypeVisitableExt,
70};
71use smallvec::smallvec;
72use tracing::{debug, instrument};
73
74use super::env::OutlivesEnvironment;
75use crate::infer::outlives::env::RegionBoundPairs;
76use crate::infer::outlives::verify::VerifyBoundCx;
77use crate::infer::resolve::OpportunisticRegionResolver;
78use crate::infer::snapshot::undo_log::UndoLog;
79use crate::infer::{
80    self, GenericKind, InferCtxt, SubregionOrigin, TypeOutlivesConstraint, VerifyBound,
81};
82use crate::traits::{ObligationCause, ObligationCauseCode};
83
84impl<'tcx> InferCtxt<'tcx> {
85    pub fn register_outlives_constraint(
86        &self,
87        ty::OutlivesPredicate(arg, r2): ty::ArgOutlivesPredicate<'tcx>,
88        vis: ty::VisibleForLeakCheck,
89        cause: &ObligationCause<'tcx>,
90    ) {
91        match arg.kind() {
92            ty::GenericArgKind::Lifetime(r1) => {
93                self.register_region_outlives_constraint(ty::OutlivesPredicate(r1, r2), vis, cause);
94            }
95            ty::GenericArgKind::Type(ty1) => {
96                self.register_type_outlives_constraint(ty1, r2, cause);
97            }
98            ty::GenericArgKind::Const(_) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
99        }
100    }
101
102    pub fn register_region_eq_constraint(
103        &self,
104        ty::RegionEqPredicate(r_a, r_b): ty::RegionEqPredicate<'tcx>,
105        vis: ty::VisibleForLeakCheck,
106        cause: &ObligationCause<'tcx>,
107    ) {
108        let origin = SubregionOrigin::from_obligation_cause(cause, || {
109            SubregionOrigin::RelateRegionParamBound(cause.span, None)
110        });
111        self.equate_regions(origin, r_a, r_b, vis);
112    }
113
114    pub fn register_region_outlives_constraint(
115        &self,
116        ty::OutlivesPredicate(r_a, r_b): ty::RegionOutlivesPredicate<'tcx>,
117        vis: ty::VisibleForLeakCheck,
118        cause: &ObligationCause<'tcx>,
119    ) {
120        let origin = SubregionOrigin::from_obligation_cause(cause, || {
121            SubregionOrigin::RelateRegionParamBound(cause.span, None)
122        });
123        // `'a: 'b` ==> `'b <= 'a`
124        self.sub_regions(origin, r_b, r_a, vis);
125    }
126
127    /// Registers that the given region obligation must be resolved
128    /// from within the scope of `body_id`. These regions are enqueued
129    /// and later processed by regionck, when full type information is
130    /// available (see `region_obligations` field for more
131    /// information).
132    #[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("register_type_outlives_constraint_inner",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(132u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["obligation"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let mut inner = self.inner.borrow_mut();
            inner.undo_log.push(UndoLog::PushTypeOutlivesConstraint);
            inner.region_obligations.push(obligation);
        }
    }
}#[instrument(level = "debug", skip(self))]
133    pub fn register_type_outlives_constraint_inner(
134        &self,
135        obligation: TypeOutlivesConstraint<'tcx>,
136    ) {
137        let mut inner = self.inner.borrow_mut();
138        inner.undo_log.push(UndoLog::PushTypeOutlivesConstraint);
139        inner.region_obligations.push(obligation);
140    }
141
142    pub fn register_type_outlives_constraint(
143        &self,
144        sup_type: Ty<'tcx>,
145        sub_region: Region<'tcx>,
146        cause: &ObligationCause<'tcx>,
147    ) {
148        // `is_global` means the type has no params, infer, placeholder, or non-`'static`
149        // free regions. If the type has none of these things, then we can skip registering
150        // this outlives obligation since it has no components which affect lifetime
151        // checking in an interesting way.
152        if sup_type.is_global() {
153            return;
154        }
155
156        {
    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/outlives/obligations.rs:156",
                        "rustc_infer::infer::outlives::obligations",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                        ::tracing_core::__macro_support::Option::Some(156u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                        ::tracing_core::field::FieldSet::new(&["sup_type",
                                        "sub_region", "cause"],
                            ::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(&sup_type)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&sub_region)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&cause) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?sup_type, ?sub_region, ?cause);
157        let origin = SubregionOrigin::from_obligation_cause(cause, || {
158            SubregionOrigin::RelateParamBound(
159                cause.span,
160                sup_type,
161                match cause.code().peel_derives() {
162                    ObligationCauseCode::WhereClause(_, span)
163                    | ObligationCauseCode::WhereClauseInExpr(_, span, ..)
164                    | ObligationCauseCode::OpaqueTypeBound(span, _)
165                        if !span.is_dummy() =>
166                    {
167                        Some(*span)
168                    }
169                    _ => None,
170                },
171            )
172        });
173
174        self.register_type_outlives_constraint_inner(TypeOutlivesConstraint {
175            sup_type,
176            sub_region,
177            origin,
178        });
179    }
180
181    /// Trait queries just want to pass back type obligations "as is"
182    pub fn take_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
183        if !!self.in_snapshot() {
    {
        ::core::panicking::panic_fmt(format_args!("cannot take registered region obligations in a snapshot"));
    }
};assert!(!self.in_snapshot(), "cannot take registered region obligations in a snapshot");
184        std::mem::take(&mut self.inner.borrow_mut().region_obligations)
185    }
186
187    pub fn clone_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
188        self.inner.borrow().region_obligations.clone()
189    }
190
191    pub fn register_region_assumption(&self, assumption: ty::ArgOutlivesPredicate<'tcx>) {
192        let mut inner = self.inner.borrow_mut();
193        inner.undo_log.push(UndoLog::PushRegionAssumption);
194        inner.region_assumptions.push(assumption);
195    }
196
197    pub fn take_registered_region_assumptions(&self) -> Vec<ty::ArgOutlivesPredicate<'tcx>> {
198        if !!self.in_snapshot() {
    {
        ::core::panicking::panic_fmt(format_args!("cannot take registered region assumptions in a snapshot"));
    }
};assert!(!self.in_snapshot(), "cannot take registered region assumptions in a snapshot");
199        std::mem::take(&mut self.inner.borrow_mut().region_assumptions)
200    }
201
202    /// Process the region obligations that must be proven (during
203    /// `regionck`) for the given `body_id`, given information about
204    /// the region bounds in scope and so forth.
205    ///
206    /// See the `region_obligations` field of `InferCtxt` for some
207    /// comments about how this function fits into the overall expected
208    /// flow of the inferencer. The key point is that it is
209    /// invoked after all type-inference variables have been bound --
210    /// right before lexical region resolution.
211    #[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("process_registered_region_obligations",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(211u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::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:
                    Result<(),
                    (PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !!self.in_snapshot() {
                {
                    ::core::panicking::panic_fmt(format_args!("cannot process registered region obligations in a snapshot"));
                }
            };
            for iteration in 0.. {
                let my_region_obligations =
                    self.take_registered_region_obligations();
                if my_region_obligations.is_empty() { break; }
                if !self.tcx.recursion_limit().value_within_limit(iteration) {
                    ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected overflowed when processing region obligations: {0:#?}",
                            my_region_obligations));
                }
                for TypeOutlivesConstraint { sup_type, sub_region, origin } in
                    my_region_obligations {
                    let outlives =
                        ty::Binder::dummy(ty::OutlivesPredicate(sup_type,
                                sub_region));
                    let ty::OutlivesPredicate(sup_type, sub_region) =
                        deeply_normalize_ty(outlives,
                                            origin.clone()).map_err(|NoSolution|
                                            (outlives,
                                                origin.clone()))?.no_bound_vars().expect("started with no bound vars, should end with no bound vars");
                    let (sup_type, sub_region) =
                        (sup_type,
                                sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
                    if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
                            &&
                            outlives_env.higher_ranked_assumptions().contains(&ty::OutlivesPredicate(sup_type.into(),
                                        sub_region)) {
                        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/outlives/obligations.rs:260",
                                            "rustc_infer::infer::outlives::obligations",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                            ::tracing_core::__macro_support::Option::Some(260u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                            ::tracing_core::field::FieldSet::new(&["sup_type",
                                                            "sub_region", "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(&sup_type)
                                                                as &dyn Value)),
                                                    (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                        ::tracing::__macro_support::Option::Some(&debug(&sub_region)
                                                                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 { ; }
                    };
                    let outlives =
                        &mut TypeOutlives::new(self, self.tcx,
                                outlives_env.region_bound_pairs(), None,
                                outlives_env.known_type_outlives());
                    let category = origin.to_constraint_category();
                    outlives.type_must_outlive(origin, sup_type, sub_region,
                        category);
                }
            }
            Ok(())
        }
    }
}#[instrument(level = "debug", skip(self, outlives_env, deeply_normalize_ty))]
212    pub fn process_registered_region_obligations(
213        &self,
214        outlives_env: &OutlivesEnvironment<'tcx>,
215        mut deeply_normalize_ty: impl FnMut(
216            PolyTypeOutlivesPredicate<'tcx>,
217            SubregionOrigin<'tcx>,
218        )
219            -> Result<PolyTypeOutlivesPredicate<'tcx>, NoSolution>,
220    ) -> Result<(), (PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> {
221        assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
222
223        // Must loop since the process of normalizing may itself register region obligations.
224        for iteration in 0.. {
225            let my_region_obligations = self.take_registered_region_obligations();
226            if my_region_obligations.is_empty() {
227                break;
228            }
229
230            if !self.tcx.recursion_limit().value_within_limit(iteration) {
231                // This may actually be reachable. If so, we should convert
232                // this to a proper error/consider whether we should detect
233                // this somewhere else.
234                bug!(
235                    "unexpected overflowed when processing region obligations: {my_region_obligations:#?}"
236                );
237            }
238
239            for TypeOutlivesConstraint { sup_type, sub_region, origin } in my_region_obligations {
240                let outlives = ty::Binder::dummy(ty::OutlivesPredicate(sup_type, sub_region));
241                let ty::OutlivesPredicate(sup_type, sub_region) =
242                    deeply_normalize_ty(outlives, origin.clone())
243                        .map_err(|NoSolution| (outlives, origin.clone()))?
244                        .no_bound_vars()
245                        .expect("started with no bound vars, should end with no bound vars");
246                // `TypeOutlives` is structural, so we should try to opportunistically resolve all
247                // region vids before processing regions, so we have a better chance to match clauses
248                // in our param-env.
249                let (sup_type, sub_region) =
250                    (sup_type, sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
251
252                if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
253                    && outlives_env
254                        .higher_ranked_assumptions()
255                        .contains(&ty::OutlivesPredicate(sup_type.into(), sub_region))
256                {
257                    continue;
258                }
259
260                debug!(?sup_type, ?sub_region, ?origin);
261
262                let outlives = &mut TypeOutlives::new(
263                    self,
264                    self.tcx,
265                    outlives_env.region_bound_pairs(),
266                    None,
267                    outlives_env.known_type_outlives(),
268                );
269                let category = origin.to_constraint_category();
270                outlives.type_must_outlive(origin, sup_type, sub_region, category);
271            }
272        }
273
274        Ok(())
275    }
276}
277
278/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
279/// obligation into a series of `'a: 'b` constraints and "verify"s, as
280/// described on the module comment. The final constraints are emitted
281/// via a "delegate" of type `D` -- this is usually the `infcx`, which
282/// accrues them into the `region_obligations` code, but for NLL we
283/// use something else.
284pub struct TypeOutlives<'cx, 'tcx, D>
285where
286    D: TypeOutlivesDelegate<'tcx>,
287{
288    // See the comments on `process_registered_region_obligations` for the meaning
289    // of these fields.
290    delegate: D,
291    tcx: TyCtxt<'tcx>,
292    verify_bound: VerifyBoundCx<'cx, 'tcx>,
293}
294
295pub trait TypeOutlivesDelegate<'tcx> {
296    fn push_sub_region_constraint(
297        &mut self,
298        origin: SubregionOrigin<'tcx>,
299        a: ty::Region<'tcx>,
300        b: ty::Region<'tcx>,
301        constraint_category: ConstraintCategory<'tcx>,
302    );
303
304    fn push_verify(
305        &mut self,
306        origin: SubregionOrigin<'tcx>,
307        kind: GenericKind<'tcx>,
308        a: ty::Region<'tcx>,
309        bound: VerifyBound<'tcx>,
310    );
311}
312
313impl<'cx, 'tcx, D> TypeOutlives<'cx, 'tcx, D>
314where
315    D: TypeOutlivesDelegate<'tcx>,
316{
317    pub fn new(
318        delegate: D,
319        tcx: TyCtxt<'tcx>,
320        region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
321        implicit_region_bound: Option<ty::Region<'tcx>>,
322        caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
323    ) -> Self {
324        Self {
325            delegate,
326            tcx,
327            verify_bound: VerifyBoundCx::new(
328                tcx,
329                region_bound_pairs,
330                implicit_region_bound,
331                caller_bounds,
332            ),
333        }
334    }
335
336    /// Adds constraints to inference such that `T: 'a` holds (or
337    /// reports an error if it cannot).
338    ///
339    /// # Parameters
340    ///
341    /// - `origin`, the reason we need this constraint
342    /// - `ty`, the type `T`
343    /// - `region`, the region `'a`
344    #[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("type_must_outlive",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(344u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["origin", "ty",
                                                    "region", "category"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
                                                            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(&ty)
                                                            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(&region)
                                                            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(&category)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !!ty.has_escaping_bound_vars() {
                ::core::panicking::panic("assertion failed: !ty.has_escaping_bound_vars()")
            };
            let mut components = ::smallvec::SmallVec::new();
            push_outlives_components(self.tcx, ty, &mut components);
            self.components_must_outlive(origin, &components, region,
                category);
        }
    }
}#[instrument(level = "debug", skip(self))]
345    pub fn type_must_outlive(
346        &mut self,
347        origin: infer::SubregionOrigin<'tcx>,
348        ty: Ty<'tcx>,
349        region: ty::Region<'tcx>,
350        category: ConstraintCategory<'tcx>,
351    ) {
352        assert!(!ty.has_escaping_bound_vars());
353
354        let mut components = smallvec![];
355        push_outlives_components(self.tcx, ty, &mut components);
356        self.components_must_outlive(origin, &components, region, category);
357    }
358
359    fn components_must_outlive(
360        &mut self,
361        origin: infer::SubregionOrigin<'tcx>,
362        components: &[Component<TyCtxt<'tcx>>],
363        region: ty::Region<'tcx>,
364        category: ConstraintCategory<'tcx>,
365    ) {
366        for component in components.iter() {
367            let origin = origin.clone();
368            match component {
369                Component::Region(region1) => {
370                    self.delegate.push_sub_region_constraint(origin, region, *region1, category);
371                }
372                Component::Param(param_ty) => {
373                    self.param_ty_must_outlive(origin, region, *param_ty);
374                }
375                Component::Placeholder(placeholder_ty) => {
376                    self.placeholder_ty_must_outlive(origin, region, *placeholder_ty);
377                }
378                Component::Alias(alias_ty) => self.alias_ty_must_outlive(origin, region, *alias_ty),
379                Component::EscapingAlias(subcomponents) => {
380                    self.components_must_outlive(origin, subcomponents, region, category);
381                }
382                Component::UnresolvedInferenceVariable(v) => {
383                    // Ignore this, we presume it will yield an error later,
384                    // since if a type variable is not resolved by this point
385                    // it never will be.
386                    self.tcx.dcx().span_delayed_bug(
387                        origin.span(),
388                        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("unresolved inference variable in outlives: {0:?}",
                v))
    })format!("unresolved inference variable in outlives: {v:?}"),
389                    );
390                }
391            }
392        }
393    }
394
395    #[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("param_ty_must_outlive",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(395u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["origin", "region",
                                                    "param_ty"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
                                                            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(&region)
                                                            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(&param_ty)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let verify_bound =
                self.verify_bound.param_or_placeholder_bound(param_ty.to_ty(self.tcx));
            self.delegate.push_verify(origin, GenericKind::Param(param_ty),
                region, verify_bound);
        }
    }
}#[instrument(level = "debug", skip(self))]
396    fn param_ty_must_outlive(
397        &mut self,
398        origin: infer::SubregionOrigin<'tcx>,
399        region: ty::Region<'tcx>,
400        param_ty: ty::ParamTy,
401    ) {
402        let verify_bound = self.verify_bound.param_or_placeholder_bound(param_ty.to_ty(self.tcx));
403        self.delegate.push_verify(origin, GenericKind::Param(param_ty), region, verify_bound);
404    }
405
406    #[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("placeholder_ty_must_outlive",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(406u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["origin", "region",
                                                    "placeholder_ty"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
                                                            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(&region)
                                                            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(&placeholder_ty)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let verify_bound =
                self.verify_bound.param_or_placeholder_bound(Ty::new_placeholder(self.tcx,
                        placeholder_ty));
            self.delegate.push_verify(origin,
                GenericKind::Placeholder(placeholder_ty), region,
                verify_bound);
        }
    }
}#[instrument(level = "debug", skip(self))]
407    fn placeholder_ty_must_outlive(
408        &mut self,
409        origin: infer::SubregionOrigin<'tcx>,
410        region: ty::Region<'tcx>,
411        placeholder_ty: ty::PlaceholderType<'tcx>,
412    ) {
413        let verify_bound = self
414            .verify_bound
415            .param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty));
416        self.delegate.push_verify(
417            origin,
418            GenericKind::Placeholder(placeholder_ty),
419            region,
420            verify_bound,
421        );
422    }
423
424    #[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("alias_ty_must_outlive",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(424u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["origin", "region",
                                                    "alias_ty"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
                                                            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(&region)
                                                            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(&alias_ty)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if alias_ty.args.is_empty() { return; }
            if alias_ty.has_non_region_infer() {
                self.tcx.dcx().span_delayed_bug(origin.span(),
                    "an alias has infers during region solving");
                return;
            }
            let trait_bounds: Vec<_> =
                self.verify_bound.declared_bounds_from_definition(alias_ty).collect();
            {
                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/outlives/obligations.rs:463",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(463u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["trait_bounds"],
                                        ::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(&trait_bounds)
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            let approx_env_bounds =
                self.verify_bound.approx_declared_bounds_from_env(alias_ty);
            {
                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/outlives/obligations.rs:469",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(469u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["approx_env_bounds"],
                                        ::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(&approx_env_bounds)
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            let kind = alias_ty.kind;
            if approx_env_bounds.is_empty() && trait_bounds.is_empty() &&
                    (alias_ty.has_infer_regions() ||
                            #[allow(non_exhaustive_omitted_patterns)] match kind {
                                ty::Opaque { .. } => true,
                                _ => false,
                            }) {
                {
                    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/outlives/obligations.rs:490",
                                        "rustc_infer::infer::outlives::obligations",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                        ::tracing_core::__macro_support::Option::Some(490u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                        ::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!("no declared bounds")
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                let opt_variances = self.tcx.opt_alias_variances(kind);
                self.args_must_outlive(alias_ty.args, origin, region,
                    opt_variances);
                return;
            }
            if !trait_bounds.is_empty() &&
                    trait_bounds[1..].iter().map(|r|
                                    Some(*r)).chain(approx_env_bounds.iter().map(|b|
                                    b.map_bound(|b|
                                                b.1).no_bound_vars())).all(|b| b == Some(trait_bounds[0])) {
                let unique_bound = trait_bounds[0];
                {
                    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/outlives/obligations.rs:521",
                                        "rustc_infer::infer::outlives::obligations",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                        ::tracing_core::__macro_support::Option::Some(521u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                        ::tracing_core::field::FieldSet::new(&["unique_bound"],
                                            ::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(&unique_bound)
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                {
                    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/outlives/obligations.rs:522",
                                        "rustc_infer::infer::outlives::obligations",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                        ::tracing_core::__macro_support::Option::Some(522u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                        ::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!("unique declared bound appears in trait ref")
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                let category = origin.to_constraint_category();
                self.delegate.push_sub_region_constraint(origin, region,
                    unique_bound, category);
                return;
            }
            let verify_bound = self.verify_bound.alias_bound(alias_ty);
            {
                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/outlives/obligations.rs:534",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(534u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::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!("alias_must_outlive: pushing {0:?}",
                                                                verify_bound) as &dyn Value))])
                        });
                } else { ; }
            };
            self.delegate.push_verify(origin, GenericKind::Alias(alias_ty),
                region, verify_bound);
        }
    }
}#[instrument(level = "debug", skip(self))]
425    fn alias_ty_must_outlive(
426        &mut self,
427        origin: infer::SubregionOrigin<'tcx>,
428        region: ty::Region<'tcx>,
429        alias_ty: ty::AliasTy<'tcx>,
430    ) {
431        // An optimization for a common case with opaque types.
432        if alias_ty.args.is_empty() {
433            return;
434        }
435
436        if alias_ty.has_non_region_infer() {
437            self.tcx
438                .dcx()
439                .span_delayed_bug(origin.span(), "an alias has infers during region solving");
440            return;
441        }
442
443        // This case is thorny for inference. The fundamental problem is
444        // that there are many cases where we have choice, and inference
445        // doesn't like choice (the current region inference in
446        // particular). :) First off, we have to choose between using the
447        // OutlivesProjectionEnv, OutlivesProjectionTraitDef, and
448        // OutlivesProjectionComponent rules, any one of which is
449        // sufficient. If there are no inference variables involved, it's
450        // not hard to pick the right rule, but if there are, we're in a
451        // bit of a catch 22: if we picked which rule we were going to
452        // use, we could add constraints to the region inference graph
453        // that make it apply, but if we don't add those constraints, the
454        // rule might not apply (but another rule might). For now, we err
455        // on the side of adding too few edges into the graph.
456
457        // Compute the bounds we can derive from the trait definition.
458        // These are guaranteed to apply, no matter the inference
459        // results.
460        let trait_bounds: Vec<_> =
461            self.verify_bound.declared_bounds_from_definition(alias_ty).collect();
462
463        debug!(?trait_bounds);
464
465        // Compute the bounds we can derive from the environment. This
466        // is an "approximate" match -- in some cases, these bounds
467        // may not apply.
468        let approx_env_bounds = self.verify_bound.approx_declared_bounds_from_env(alias_ty);
469        debug!(?approx_env_bounds);
470
471        // If declared bounds list is empty, the only applicable rule is
472        // OutlivesProjectionComponent. If there are inference variables,
473        // then, we can break down the outlives into more primitive
474        // components without adding unnecessary edges.
475        //
476        // If there are *no* inference variables, however, we COULD do
477        // this, but we choose not to, because the error messages are less
478        // good. For example, a requirement like `T::Item: 'r` would be
479        // translated to a requirement that `T: 'r`; when this is reported
480        // to the user, it will thus say "T: 'r must hold so that T::Item:
481        // 'r holds". But that makes it sound like the only way to fix
482        // the problem is to add `T: 'r`, which isn't true. So, if there are no
483        // inference variables, we use a verify constraint instead of adding
484        // edges, which winds up enforcing the same condition.
485        let kind = alias_ty.kind;
486        if approx_env_bounds.is_empty()
487            && trait_bounds.is_empty()
488            && (alias_ty.has_infer_regions() || matches!(kind, ty::Opaque { .. }))
489        {
490            debug!("no declared bounds");
491            let opt_variances = self.tcx.opt_alias_variances(kind);
492            self.args_must_outlive(alias_ty.args, origin, region, opt_variances);
493            return;
494        }
495
496        // If we found a unique bound `'b` from the trait, and we
497        // found nothing else from the environment, then the best
498        // action is to require that `'b: 'r`, so do that.
499        //
500        // This is best no matter what rule we use:
501        //
502        // - OutlivesProjectionEnv: these would translate to the requirement that `'b:'r`
503        // - OutlivesProjectionTraitDef: these would translate to the requirement that `'b:'r`
504        // - OutlivesProjectionComponent: this would require `'b:'r`
505        //   in addition to other conditions
506        if !trait_bounds.is_empty()
507            && trait_bounds[1..]
508                .iter()
509                .map(|r| Some(*r))
510                .chain(
511                    // NB: The environment may contain `for<'a> T: 'a` style bounds.
512                    // In that case, we don't know if they are equal to the trait bound
513                    // or not (since we don't *know* whether the environment bound even applies),
514                    // so just map to `None` here if there are bound vars, ensuring that
515                    // the call to `all` will fail below.
516                    approx_env_bounds.iter().map(|b| b.map_bound(|b| b.1).no_bound_vars()),
517                )
518                .all(|b| b == Some(trait_bounds[0]))
519        {
520            let unique_bound = trait_bounds[0];
521            debug!(?unique_bound);
522            debug!("unique declared bound appears in trait ref");
523            let category = origin.to_constraint_category();
524            self.delegate.push_sub_region_constraint(origin, region, unique_bound, category);
525            return;
526        }
527
528        // Fallback to verifying after the fact that there exists a
529        // declared bound, or that all the components appearing in the
530        // projection outlive; in some cases, this may add insufficient
531        // edges into the inference graph, leading to inference failures
532        // even though a satisfactory solution exists.
533        let verify_bound = self.verify_bound.alias_bound(alias_ty);
534        debug!("alias_must_outlive: pushing {:?}", verify_bound);
535        self.delegate.push_verify(origin, GenericKind::Alias(alias_ty), region, verify_bound);
536    }
537
538    #[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("args_must_outlive",
                                    "rustc_infer::infer::outlives::obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(538u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
                                    ::tracing_core::field::FieldSet::new(&["args", "origin",
                                                    "region", "opt_variances"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            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(&origin)
                                                            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(&region)
                                                            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(&opt_variances)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let constraint = origin.to_constraint_category();
            for (index, arg) in args.iter().enumerate() {
                match arg.kind() {
                    GenericArgKind::Lifetime(lt) => {
                        let variance =
                            if let Some(variances) = opt_variances {
                                variances[index]
                            } else { ty::Invariant };
                        if variance == ty::Invariant {
                            self.delegate.push_sub_region_constraint(origin.clone(),
                                region, lt, constraint);
                        }
                    }
                    GenericArgKind::Type(ty) => {
                        self.type_must_outlive(origin.clone(), ty, region,
                            constraint);
                    }
                    GenericArgKind::Const(_) => {}
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
539    fn args_must_outlive(
540        &mut self,
541        args: GenericArgsRef<'tcx>,
542        origin: infer::SubregionOrigin<'tcx>,
543        region: ty::Region<'tcx>,
544        opt_variances: Option<&[ty::Variance]>,
545    ) {
546        let constraint = origin.to_constraint_category();
547        for (index, arg) in args.iter().enumerate() {
548            match arg.kind() {
549                GenericArgKind::Lifetime(lt) => {
550                    let variance = if let Some(variances) = opt_variances {
551                        variances[index]
552                    } else {
553                        ty::Invariant
554                    };
555                    if variance == ty::Invariant {
556                        self.delegate.push_sub_region_constraint(
557                            origin.clone(),
558                            region,
559                            lt,
560                            constraint,
561                        );
562                    }
563                }
564                GenericArgKind::Type(ty) => {
565                    self.type_must_outlive(origin.clone(), ty, region, constraint);
566                }
567                GenericArgKind::Const(_) => {
568                    // Const parameters don't impose constraints.
569                }
570            }
571        }
572    }
573}
574
575impl<'cx, 'tcx> TypeOutlivesDelegate<'tcx> for &'cx InferCtxt<'tcx> {
576    fn push_sub_region_constraint(
577        &mut self,
578        origin: SubregionOrigin<'tcx>,
579        a: ty::Region<'tcx>,
580        b: ty::Region<'tcx>,
581        _constraint_category: ConstraintCategory<'tcx>,
582    ) {
583        // We don't do leak check in lexical region resolution
584        self.sub_regions(origin, a, b, ty::VisibleForLeakCheck::Unreachable)
585    }
586
587    fn push_verify(
588        &mut self,
589        origin: SubregionOrigin<'tcx>,
590        kind: GenericKind<'tcx>,
591        a: ty::Region<'tcx>,
592        bound: VerifyBound<'tcx>,
593    ) {
594        self.verify_generic_bound(origin, kind, a, bound)
595    }
596}