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
85                    .insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
86            }
87        }
88
89        if predicates_added.is_empty() {
90            // We've reached a fixed point.
91            break;
92        } else if !tcx.recursion_limit().value_within_limit(i) {
93            let msg = if let &[id] = &predicates_added[..] {
94                ::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),)
95            } else {
96                "overflow computing implied lifetime bounds".to_string()
97            };
98            tcx.dcx()
99                .struct_span_fatal(
100                    predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
101                    msg,
102                )
103                .emit();
104        }
105    }
106
107    global_inferred_outlives
108}
109
110fn insert_required_predicates_to_be_wf<'tcx>(
111    tcx: TyCtxt<'tcx>,
112    ty: Ty<'tcx>,
113    span: Span,
114    global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
115    required_predicates: &mut RequiredPredicates<'tcx>,
116    explicit_map: &mut ExplicitPredicatesMap<'tcx>,
117) {
118    for arg in ty.walk() {
119        let leaf_ty = match arg.kind() {
120            GenericArgKind::Type(ty) => ty,
121
122            // No predicates from lifetimes or constants, except potentially
123            // constants' types, but `walk` will get to them as well.
124            GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
125        };
126
127        match *leaf_ty.kind() {
128            ty::Ref(region, rty, _) => {
129                // The type is `&'a T` which means that we will have
130                // a predicate requirement of `T: 'a` (`T` outlives `'a`).
131                //
132                // We also want to calculate potential predicates for the `T`.
133                {
    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:133",
                        "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(133u32),
                        ::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");
134                insert_outlives_predicate(tcx, rty.into(), region, span, required_predicates);
135            }
136
137            ty::Adt(def, args) => {
138                // For ADTs (structs/enums/unions), we check inferred and explicit predicates.
139                {
    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:139",
                        "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(139u32),
                        ::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");
140                check_inferred_predicates(
141                    tcx,
142                    def.did(),
143                    args,
144                    global_inferred_outlives,
145                    required_predicates,
146                );
147                check_explicit_predicates(
148                    tcx,
149                    def.did(),
150                    args,
151                    required_predicates,
152                    explicit_map,
153                    IgnorePredicatesReferencingSelf::No,
154                );
155            }
156
157            ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
158                // This corresponds to a type like `Type<'a, T>`.
159                // We check inferred and explicit predicates.
160                {
    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:160",
                        "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(160u32),
                        ::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");
161                check_inferred_predicates(
162                    tcx,
163                    def_id,
164                    args,
165                    global_inferred_outlives,
166                    required_predicates,
167                );
168                check_explicit_predicates(
169                    tcx,
170                    def_id,
171                    args,
172                    required_predicates,
173                    explicit_map,
174                    IgnorePredicatesReferencingSelf::No,
175                );
176            }
177
178            ty::Dynamic(obj, ..) => {
179                // This corresponds to `dyn Trait<..>`. In this case, we should
180                // use the explicit predicates as well.
181                {
    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:181",
                        "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(181u32),
                        ::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");
182                if let Some(trait_ref) = obj.principal() {
183                    let args = trait_ref
184                        .with_self_ty(tcx, tcx.types.trait_object_dummy_self)
185                        .skip_binder()
186                        .args;
187                    // We skip predicates that reference the `Self` type parameter since we don't
188                    // want to leak the dummy Self to the predicates map.
189                    //
190                    // While filtering out bounds like `Self: 'a` as in `trait Trait<'a, T>: 'a {}`
191                    // doesn't matter since they can't affect the lifetime / type parameters anyway,
192                    // for bounds like `Self::AssocTy: 'b` which we of course currently also ignore
193                    // (see also #54467) it might conceivably be better to extract the binding
194                    // `AssocTy = U` from the trait object type (which must exist) and thus infer
195                    // an outlives requirement that `U: 'b`.
196                    check_explicit_predicates(
197                        tcx,
198                        trait_ref.def_id(),
199                        args,
200                        required_predicates,
201                        explicit_map,
202                        IgnorePredicatesReferencingSelf::Yes,
203                    );
204                }
205            }
206
207            ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => {
208                // This corresponds to a type like `<() as Trait<'a, T>>::Type`.
209                // We only use the explicit predicates of the trait but
210                // not the ones of the associated type itself.
211                {
    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:211",
                        "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(211u32),
                        ::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");
212                check_explicit_predicates(
213                    tcx,
214                    tcx.parent(def_id),
215                    args,
216                    required_predicates,
217                    explicit_map,
218                    IgnorePredicatesReferencingSelf::No,
219                );
220            }
221
222            // FIXME(inherent_associated_types): Use the explicit predicates from the parent impl.
223            ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {}
224
225            _ => {}
226        }
227    }
228}
229
230/// Check the explicit predicates declared on the type.
231///
232/// ### Example
233///
234/// ```ignore (illustrative)
235/// struct Outer<'a, T> {
236///     field: Inner<T>,
237/// }
238///
239/// struct Inner<U> where U: 'static, U: Outer {
240///     // ...
241/// }
242/// ```
243/// Here, we should fetch the explicit predicates, which
244/// will give us `U: 'static` and `U: Outer`. The latter we
245/// can ignore, but we will want to process `U: 'static`,
246/// applying the instantiation as above.
247#[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(247u32),
                                    ::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:261",
                                        "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(261u32),
                                        ::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:266",
                                            "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(266u32),
                                            ::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:272",
                                        "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(272u32),
                                        ::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))]
248fn check_explicit_predicates<'tcx>(
249    tcx: TyCtxt<'tcx>,
250    def_id: DefId,
251    args: &[GenericArg<'tcx>],
252    required_predicates: &mut RequiredPredicates<'tcx>,
253    explicit_map: &mut ExplicitPredicatesMap<'tcx>,
254    ignore_preds_refing_self: IgnorePredicatesReferencingSelf,
255) {
256    let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
257
258    for (&predicate @ ty::OutlivesPredicate(arg, _), &span) in
259        explicit_predicates.as_ref().skip_binder()
260    {
261        debug!(?predicate);
262
263        if let IgnorePredicatesReferencingSelf::Yes = ignore_preds_refing_self
264            && arg.walk().any(|arg| arg == tcx.types.self_param.into())
265        {
266            debug!("ignoring predicate since it references `Self`");
267            continue;
268        }
269
270        let predicate @ ty::OutlivesPredicate(arg, region) =
271            explicit_predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip();
272        debug!(?predicate);
273
274        insert_outlives_predicate(tcx, arg, region, span, required_predicates);
275    }
276}
277
278#[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)]
279enum IgnorePredicatesReferencingSelf {
280    Yes,
281    No,
282}
283
284/// Check the inferred predicates of the type.
285///
286/// ### Example
287///
288/// ```ignore (illustrative)
289/// struct Outer<'a, T> {
290///     outer: Inner<'a, T>,
291/// }
292///
293/// struct Inner<'b, U> {
294///     inner: &'b U,
295/// }
296/// ```
297///
298/// Here, when processing the type of field `outer`, we would request the
299/// set of implicit predicates computed for `Inner` thus far. This will
300/// initially come back empty, but in next round we will get `U: 'b`.
301/// We then apply the instantiation `['b => 'a, U => T]` and thus get the
302/// requirement that `T: 'a` holds for `Outer`.
303fn check_inferred_predicates<'tcx>(
304    tcx: TyCtxt<'tcx>,
305    def_id: DefId,
306    args: ty::GenericArgsRef<'tcx>,
307    global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
308    required_predicates: &mut RequiredPredicates<'tcx>,
309) {
310    // Load the current set of inferred and explicit predicates from `global_inferred_outlives`
311    // and filter the ones that are `TypeOutlives`.
312
313    let Some(predicates) = global_inferred_outlives.get(&def_id) else {
314        return;
315    };
316
317    for (&predicate, &span) in predicates.as_ref().skip_binder() {
318        // `predicate` is `U: 'b` in the example above.
319        // So apply the instantiation to get `T: 'a`.
320        let ty::OutlivesPredicate(arg, region) =
321            predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip();
322        insert_outlives_predicate(tcx, arg, region, span, required_predicates);
323    }
324}