Skip to main content

rustc_hir_analysis/outlives/
implicit_infer.rs

1use rustc_data_structures::fx::FxIndexMap;
2use rustc_hir::def::DefKind;
3use rustc_hir::def_id::DefId;
4use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};
5use rustc_span::Span;
6use tracing::debug;
7
8use super::explicit::ExplicitPredicatesMap;
9use super::utils::*;
10
11/// Infer outlives-predicates for the items in the local crate.
12pub(super) fn infer_predicates(
13    tcx: TyCtxt<'_>,
14) -> FxIndexMap<DefId, ty::EarlyBinder<'_, RequiredPredicates<'_>>> {
15    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:15",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(15u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("infer_predicates")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("infer_predicates");
16
17    let mut explicit_map = ExplicitPredicatesMap::new();
18
19    let mut global_inferred_outlives = FxIndexMap::default();
20
21    // If new predicates were added then we need to re-calculate
22    // all crates since there could be new implied predicates.
23    for i in 0.. {
24        let mut predicates_added = ::alloc::vec::Vec::new()vec![];
25
26        // Visit all the crates and infer predicates
27        for id in tcx.hir_free_items() {
28            let item_did = id.owner_id;
29
30            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:30",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(30u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("InferVisitor::visit_item(item={0:?})",
                                                    item_did) as &dyn Value))])
            });
    } else { ; }
};debug!("InferVisitor::visit_item(item={:?})", item_did);
31
32            let mut item_required_predicates = RequiredPredicates::default();
33            match tcx.def_kind(item_did) {
34                DefKind::Union | DefKind::Enum | DefKind::Struct => {
35                    let adt_def = tcx.adt_def(item_did.to_def_id());
36
37                    // Iterate over all fields in item_did
38                    for field_def in adt_def.all_fields() {
39                        // Calculating the predicate requirements necessary
40                        // for item_did.
41                        //
42                        // For field of type &'a T (reference) or Adt
43                        // (struct/enum/union) there will be outlive
44                        // requirements for adt_def.
45                        let field_ty =
46                            tcx.type_of(field_def.did).instantiate_identity().skip_norm_wip();
47                        let field_span = tcx.def_span(field_def.did);
48                        insert_required_predicates_to_be_wf(
49                            tcx,
50                            field_ty,
51                            field_span,
52                            &global_inferred_outlives,
53                            &mut item_required_predicates,
54                            &mut explicit_map,
55                        );
56                    }
57                }
58
59                DefKind::TyAlias if tcx.type_alias_is_lazy(item_did) => {
60                    insert_required_predicates_to_be_wf(
61                        tcx,
62                        tcx.type_of(item_did).instantiate_identity().skip_norm_wip(),
63                        tcx.def_span(item_did),
64                        &global_inferred_outlives,
65                        &mut item_required_predicates,
66                        &mut explicit_map,
67                    );
68                }
69
70                _ => {}
71            };
72
73            // If new predicates were added (`local_predicate_map` has more
74            // predicates than the `global_inferred_outlives`), the new predicates
75            // might result in implied predicates for their parent types.
76            // Therefore mark `predicates_added` as true and which will ensure
77            // we walk the crates again and re-calculate predicates for all
78            // items.
79            let item_predicates_len: usize = global_inferred_outlives
80                .get(&item_did.to_def_id())
81                .map_or(0, |p| p.as_ref().skip_binder().len());
82            if item_required_predicates.len() > item_predicates_len {
83                predicates_added.push(item_did);
84                global_inferred_outlives.insert(
85                    item_did.to_def_id(),
86                    ty::EarlyBinder::bind_iter(item_required_predicates),
87                );
88            }
89        }
90
91        if predicates_added.is_empty() {
92            // We've reached a fixed point.
93            break;
94        } else if !tcx.recursion_limit().value_within_limit(i) {
95            let msg = if let &[id] = &predicates_added[..] {
96                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("overflow computing implied lifetime bounds for `{0}`",
                tcx.def_path_str(id)))
    })format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)
97            } else {
98                "overflow computing implied lifetime bounds".to_string()
99            };
100            tcx.dcx()
101                .struct_span_fatal(
102                    predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
103                    msg,
104                )
105                .emit();
106        }
107    }
108
109    global_inferred_outlives
110}
111
112fn insert_required_predicates_to_be_wf<'tcx>(
113    tcx: TyCtxt<'tcx>,
114    ty: Ty<'tcx>,
115    span: Span,
116    global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
117    required_predicates: &mut RequiredPredicates<'tcx>,
118    explicit_map: &mut ExplicitPredicatesMap<'tcx>,
119) {
120    for arg in ty.walk() {
121        let leaf_ty = match arg.kind() {
122            GenericArgKind::Type(ty) => ty,
123
124            // No predicates from lifetimes or constants, except potentially
125            // constants' types, but `walk` will get to them as well.
126            GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
127        };
128
129        match *leaf_ty.kind() {
130            ty::Ref(region, rty, _) => {
131                // The type is `&'a T` which means that we will have
132                // a predicate requirement of `T: 'a` (`T` outlives `'a`).
133                //
134                // We also want to calculate potential predicates for the `T`.
135                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:135",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(135u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("Ref")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("Ref");
136                insert_outlives_predicate(tcx, rty.into(), region, span, required_predicates);
137            }
138
139            ty::Adt(def, args) => {
140                // For ADTs (structs/enums/unions), we check inferred and explicit predicates.
141                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:141",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(141u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("Adt")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("Adt");
142                check_inferred_predicates(
143                    tcx,
144                    def.did(),
145                    args,
146                    global_inferred_outlives,
147                    required_predicates,
148                );
149                check_explicit_predicates(
150                    tcx,
151                    def.did(),
152                    args,
153                    required_predicates,
154                    explicit_map,
155                    IgnorePredicatesReferencingSelf::No,
156                );
157            }
158
159            ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
160                // This corresponds to a type like `Type<'a, T>`.
161                // We check inferred and explicit predicates.
162                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:162",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(162u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("Free")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("Free");
163                check_inferred_predicates(
164                    tcx,
165                    def_id,
166                    args,
167                    global_inferred_outlives,
168                    required_predicates,
169                );
170                check_explicit_predicates(
171                    tcx,
172                    def_id,
173                    args,
174                    required_predicates,
175                    explicit_map,
176                    IgnorePredicatesReferencingSelf::No,
177                );
178            }
179
180            ty::Dynamic(obj, ..) => {
181                // This corresponds to `dyn Trait<..>`. In this case, we should
182                // use the explicit predicates as well.
183                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:183",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(183u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("Dynamic")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("Dynamic");
184                if let Some(trait_ref) = obj.principal() {
185                    let args = trait_ref
186                        .with_self_ty(tcx, tcx.types.trait_object_dummy_self)
187                        .skip_binder()
188                        .args;
189                    // We skip predicates that reference the `Self` type parameter since we don't
190                    // want to leak the dummy Self to the predicates map.
191                    //
192                    // While filtering out bounds like `Self: 'a` as in `trait Trait<'a, T>: 'a {}`
193                    // doesn't matter since they can't affect the lifetime / type parameters anyway,
194                    // for bounds like `Self::AssocTy: 'b` which we of course currently also ignore
195                    // (see also #54467) it might conceivably be better to extract the binding
196                    // `AssocTy = U` from the trait object type (which must exist) and thus infer
197                    // an outlives requirement that `U: 'b`.
198                    check_explicit_predicates(
199                        tcx,
200                        trait_ref.def_id(),
201                        args,
202                        required_predicates,
203                        explicit_map,
204                        IgnorePredicatesReferencingSelf::Yes,
205                    );
206                }
207            }
208
209            ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => {
210                // This corresponds to a type like `<() as Trait<'a, T>>::Type`.
211                // We only use the explicit predicates of the trait but
212                // not the ones of the associated type itself.
213                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:213",
                        "rustc_hir_analysis::outlives::implicit_infer",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                        ::tracing_core::__macro_support::Option::Some(213u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                        ::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!("Projection")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("Projection");
214                check_explicit_predicates(
215                    tcx,
216                    tcx.parent(def_id),
217                    args,
218                    required_predicates,
219                    explicit_map,
220                    IgnorePredicatesReferencingSelf::No,
221                );
222            }
223
224            // FIXME(inherent_associated_types): Use the explicit predicates from the parent impl.
225            ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {}
226
227            _ => {}
228        }
229    }
230}
231
232/// Check the explicit predicates declared on the type.
233///
234/// ### Example
235///
236/// ```ignore (illustrative)
237/// struct Outer<'a, T> {
238///     field: Inner<T>,
239/// }
240///
241/// struct Inner<U> where U: 'static, U: Outer {
242///     // ...
243/// }
244/// ```
245/// Here, we should fetch the explicit predicates, which
246/// will give us `U: 'static` and `U: Outer`. The latter we
247/// can ignore, but we will want to process `U: 'static`,
248/// applying the instantiation as above.
249#[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("check_explicit_predicates",
                                    "rustc_hir_analysis::outlives::implicit_infer",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                                    ::tracing_core::__macro_support::Option::Some(249u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                                    ::tracing_core::field::FieldSet::new(&["def_id", "args",
                                                    "required_predicates", "explicit_map",
                                                    "ignore_preds_refing_self"],
                                        ::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(&def_id)
                                                            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(&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(&required_predicates)
                                                            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(&explicit_map)
                                                            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(&ignore_preds_refing_self)
                                                            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 explicit_predicates =
                explicit_map.explicit_predicates_of(tcx, def_id);
            for (&predicate @ ty::OutlivesPredicate(arg, _), &span) in
                explicit_predicates.as_ref().skip_binder() {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:263",
                                        "rustc_hir_analysis::outlives::implicit_infer",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                                        ::tracing_core::__macro_support::Option::Some(263u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                                        ::tracing_core::field::FieldSet::new(&["predicate"],
                                            ::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(&predicate)
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                if let IgnorePredicatesReferencingSelf::Yes =
                            ignore_preds_refing_self &&
                        arg.walk().any(|arg| arg == tcx.types.self_param.into()) {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:268",
                                            "rustc_hir_analysis::outlives::implicit_infer",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                                            ::tracing_core::__macro_support::Option::Some(268u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                                            ::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!("ignoring predicate since it references `Self`")
                                                                as &dyn Value))])
                                });
                        } else { ; }
                    };
                    continue;
                }
                let predicate @ ty::OutlivesPredicate(arg, region) =
                    explicit_predicates.rebind(predicate).instantiate(tcx,
                            args).skip_norm_wip();
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:274",
                                        "rustc_hir_analysis::outlives::implicit_infer",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
                                        ::tracing_core::__macro_support::Option::Some(274u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
                                        ::tracing_core::field::FieldSet::new(&["predicate"],
                                            ::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(&predicate)
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                insert_outlives_predicate(tcx, arg, region, span,
                    required_predicates);
            }
        }
    }
}#[tracing::instrument(level = "debug", skip(tcx))]
250fn check_explicit_predicates<'tcx>(
251    tcx: TyCtxt<'tcx>,
252    def_id: DefId,
253    args: &[GenericArg<'tcx>],
254    required_predicates: &mut RequiredPredicates<'tcx>,
255    explicit_map: &mut ExplicitPredicatesMap<'tcx>,
256    ignore_preds_refing_self: IgnorePredicatesReferencingSelf,
257) {
258    let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
259
260    for (&predicate @ ty::OutlivesPredicate(arg, _), &span) in
261        explicit_predicates.as_ref().skip_binder()
262    {
263        debug!(?predicate);
264
265        if let IgnorePredicatesReferencingSelf::Yes = ignore_preds_refing_self
266            && arg.walk().any(|arg| arg == tcx.types.self_param.into())
267        {
268            debug!("ignoring predicate since it references `Self`");
269            continue;
270        }
271
272        let predicate @ ty::OutlivesPredicate(arg, region) =
273            explicit_predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip();
274        debug!(?predicate);
275
276        insert_outlives_predicate(tcx, arg, region, span, required_predicates);
277    }
278}
279
280#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IgnorePredicatesReferencingSelf {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                IgnorePredicatesReferencingSelf::Yes => "Yes",
                IgnorePredicatesReferencingSelf::No => "No",
            })
    }
}Debug)]
281enum IgnorePredicatesReferencingSelf {
282    Yes,
283    No,
284}
285
286/// Check the inferred predicates of the type.
287///
288/// ### Example
289///
290/// ```ignore (illustrative)
291/// struct Outer<'a, T> {
292///     outer: Inner<'a, T>,
293/// }
294///
295/// struct Inner<'b, U> {
296///     inner: &'b U,
297/// }
298/// ```
299///
300/// Here, when processing the type of field `outer`, we would request the
301/// set of implicit predicates computed for `Inner` thus far. This will
302/// initially come back empty, but in next round we will get `U: 'b`.
303/// We then apply the instantiation `['b => 'a, U => T]` and thus get the
304/// requirement that `T: 'a` holds for `Outer`.
305fn check_inferred_predicates<'tcx>(
306    tcx: TyCtxt<'tcx>,
307    def_id: DefId,
308    args: ty::GenericArgsRef<'tcx>,
309    global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
310    required_predicates: &mut RequiredPredicates<'tcx>,
311) {
312    // Load the current set of inferred and explicit predicates from `global_inferred_outlives`
313    // and filter the ones that are `TypeOutlives`.
314
315    let Some(predicates) = global_inferred_outlives.get(&def_id) else {
316        return;
317    };
318
319    for (&predicate, &span) in predicates.as_ref().skip_binder() {
320        // `predicate` is `U: 'b` in the example above.
321        // So apply the instantiation to get `T: 'a`.
322        let ty::OutlivesPredicate(arg, region) =
323            predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip();
324        insert_outlives_predicate(tcx, arg, region, span, required_predicates);
325    }
326}