Skip to main content

rustc_hir_analysis/collect/
clauses_of.rs

1use std::assert_matches;
2
3use hir::Node;
4use rustc_data_structures::fx::FxIndexSet;
5use rustc_hir as hir;
6use rustc_hir::def::DefKind;
7use rustc_hir::def_id::{DefId, LocalDefId};
8use rustc_hir::find_attr;
9use rustc_middle::ty::{
10    self, GenericClauses, ImplTraitInTraitData, Ty, TyCtxt, TypeVisitable, TypeVisitor, Upcast,
11};
12use rustc_span::{DUMMY_SP, Ident, Span, bug, span_bug};
13use tracing::{debug, instrument, trace};
14
15use super::item_bounds::explicit_item_bounds_with_filter;
16use crate::collect::ItemCtxt;
17use crate::constrained_generic_params as cgp;
18use crate::delegation::inherit_clauses_for_delegation_item;
19use crate::hir_ty_lowering::{
20    HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter,
21    RegionInferReason,
22};
23
24/// Returns a list of all type clauses (explicit and implicit) for the definition with
25/// ID `def_id`. This includes all clauses returned by `explicit_clauses_of`, plus
26/// inferred constraints concerning which regions outlive other regions.
27{}
#[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("clauses_of",
                                    "rustc_hir_analysis::collect::clauses_of",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                    ::tracing_core::__macro_support::Option::Some(27u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("def_id");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                            as &dyn ::tracing::field::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: ty::GenericClauses<'_> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let mut result = tcx.explicit_clauses_of(def_id);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:30",
                                    "rustc_hir_analysis::collect::clauses_of",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                    ::tracing_core::__macro_support::Option::Some(30u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                    ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of: explicit_clauses_of({0:?}) = {1:?}",
                                                                def_id, result) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let inferred_outlives = tcx.inferred_outlives_of(def_id);
            if !inferred_outlives.is_empty() {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:34",
                                        "rustc_hir_analysis::collect::clauses_of",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                        ::tracing_core::__macro_support::Option::Some(34u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                        ::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};
                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of: inferred_outlives_of({0:?}) = {1:?}",
                                                                    def_id, inferred_outlives) as
                                                            &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                let inferred_outlives_iter =
                    inferred_outlives.iter().map(|(clause, span)|
                            ((*clause).upcast(tcx), *span));
                if result.clauses.is_empty() {
                    result.clauses =
                        tcx.arena.alloc_from_iter(inferred_outlives_iter);
                } else {
                    result.clauses =
                        tcx.arena.alloc_from_iter(result.clauses.into_iter().copied().chain(inferred_outlives_iter));
                }
            }
            if tcx.is_trait(def_id) {
                let span = DUMMY_SP;
                result.clauses =
                    tcx.arena.alloc_from_iter(result.clauses.iter().copied().chain(std::iter::once((ty::TraitRef::identity(tcx,
                                            def_id).upcast(tcx), span))));
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:75",
                                    "rustc_hir_analysis::collect::clauses_of",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                    ::tracing_core::__macro_support::Option::Some(75u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                    ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of({0:?}) = {1:?}",
                                                                def_id, result) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            result
        }
    }
}#[instrument(level = "debug", skip(tcx))]
28pub(super) fn clauses_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericClauses<'_> {
29    let mut result = tcx.explicit_clauses_of(def_id);
30    debug!("clauses_of: explicit_clauses_of({:?}) = {:?}", def_id, result);
31
32    let inferred_outlives = tcx.inferred_outlives_of(def_id);
33    if !inferred_outlives.is_empty() {
34        debug!("clauses_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,);
35        let inferred_outlives_iter =
36            inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
37        if result.clauses.is_empty() {
38            result.clauses = tcx.arena.alloc_from_iter(inferred_outlives_iter);
39        } else {
40            result.clauses = tcx
41                .arena
42                .alloc_from_iter(result.clauses.into_iter().copied().chain(inferred_outlives_iter));
43        }
44    }
45
46    if tcx.is_trait(def_id) {
47        // For traits, add `Self: Trait` clause. This is
48        // not part of the clauses that a user writes, but it
49        // is something that one must prove in order to invoke a
50        // method or project an associated type.
51        //
52        // In the chalk setup, this clause is not part of the
53        // "clauses" for a trait item. But it is useful in
54        // rustc because if you directly (e.g.) invoke a trait
55        // method like `Trait::method(...)`, you must naturally
56        // prove that the trait applies to the types that were
57        // used, and adding the clause into this list ensures
58        // that this is done.
59        //
60        // We use a DUMMY_SP here as a way to signal trait bounds that come
61        // from the trait itself that *shouldn't* be shown as the source of
62        // an obligation and instead be skipped. Otherwise we'd use
63        // `tcx.def_span(def_id);`
64        let span = DUMMY_SP;
65
66        result.clauses = tcx.arena.alloc_from_iter(
67            result
68                .clauses
69                .iter()
70                .copied()
71                .chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
72        );
73    }
74
75    debug!("clauses_of({:?}) = {:?}", def_id, result);
76    result
77}
78
79/// Returns a list of user-specified type clauses for the definition with ID `def_id`.
80/// N.B., this does not include any implied/inferred constraints.
81{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::TRACE <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("gather_explicit_clauses_of",
                                "rustc_hir_analysis::collect::clauses_of",
                                ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                ::tracing_core::__macro_support::Option::Some(81u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: ty::GenericClauses<'_> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        use rustc_hir::*;
                        match tcx.opt_rpitit_info(def_id.to_def_id()) {
                            Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
                                let mut clauses = Vec::new();
                                let identity_args =
                                    ty::GenericArgs::identity_for_item(tcx, def_id);
                                clauses.extend(tcx.explicit_clauses_of(fn_def_id).instantiate_own(tcx,
                                            identity_args).map(|(c, s)| (c.skip_norm_wip(), s)));
                                compute_bidirectional_outlives_clauses(tcx,
                                    &tcx.generics_of(def_id.to_def_id()).own_params[tcx.generics_of(fn_def_id).own_params.len()..],
                                    &mut clauses);
                                return ty::GenericClauses {
                                        parent: Some(tcx.local_parent(def_id).to_def_id()),
                                        clauses: tcx.arena.alloc_from_iter(clauses),
                                    };
                            }
                            Some(ImplTraitInTraitData::Impl { fn_def_id }) => {
                                let trait_item_def_id = tcx.trait_item_of(def_id).unwrap();
                                let trait_assoc_clauses =
                                    tcx.explicit_clauses_of(trait_item_def_id);
                                let impl_assoc_identity_args =
                                    ty::GenericArgs::identity_for_item(tcx, def_id);
                                let impl_def_id = tcx.parent(fn_def_id);
                                let impl_trait_ref_args =
                                    tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args;
                                let impl_assoc_args =
                                    impl_assoc_identity_args.rebase_onto(tcx, impl_def_id,
                                        impl_trait_ref_args);
                                let impl_clauses =
                                    trait_assoc_clauses.instantiate_own(tcx,
                                            impl_assoc_args).map(|(c, s)| (c.skip_norm_wip(), s));
                                return ty::GenericClauses {
                                        parent: Some(impl_def_id),
                                        clauses: tcx.arena.alloc_from_iter(impl_clauses),
                                    };
                            }
                            None => {}
                        }
                        let hir_id = tcx.local_def_id_to_hir_id(def_id);
                        let node = tcx.hir_node(hir_id);
                        if let Some(sig) = node.fn_sig() &&
                                let Some(sig_id) = sig.decl.opt_delegation_sig_id() {
                            return inherit_clauses_for_delegation_item(tcx, def_id,
                                    sig_id);
                        }
                        let mut is_trait = None;
                        let mut is_default_impl_trait = None;
                        let icx = ItemCtxt::new(tcx, def_id);
                        const NO_GENERICS: &hir::Generics<'_> =
                            hir::Generics::empty();
                        let mut clauses: FxIndexSet<(ty::Clause<'_>, Span)> =
                            FxIndexSet::default();
                        let hir_generics = node.generics().unwrap_or(NO_GENERICS);
                        if let Node::Item(item) = node {
                            match item.kind {
                                ItemKind::Impl(impl_) => {
                                    if let Some(of_trait) = impl_.of_trait &&
                                            of_trait.defaultness.is_default() {
                                        is_default_impl_trait =
                                            Some(ty::Binder::dummy(tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip()));
                                    }
                                }
                                ItemKind::Trait { bounds: self_bounds, .. } |
                                    ItemKind::TraitAlias(_, _, _, self_bounds) => {
                                    is_trait = Some((self_bounds, item.span));
                                }
                                _ => {}
                            }
                        };
                        let generics = tcx.generics_of(def_id);
                        if let Some((self_bounds, span)) = is_trait {
                            let mut bounds = Vec::new();
                            icx.lowerer().lower_bounds(tcx.types.self_param,
                                self_bounds, &mut bounds, ty::List::empty(),
                                PredicateFilter::All,
                                OverlappingAsssocItemConstraints::Allowed);
                            icx.lowerer().add_implicit_sizedness_bounds(&mut bounds,
                                tcx.types.self_param, self_bounds,
                                ImpliedBoundsContext::TraitDef(def_id), span);
                            icx.lowerer().add_default_traits(&mut bounds,
                                tcx.types.self_param, self_bounds,
                                ImpliedBoundsContext::TraitDef(def_id), span);
                            clauses.extend(bounds);
                        }
                        if let Some(trait_ref) = is_default_impl_trait {
                            clauses.insert((trait_ref.upcast(tcx),
                                    tcx.def_span(def_id)));
                        }
                        for param in hir_generics.params {
                            match param.kind {
                                GenericParamKind::Lifetime { .. } => (),
                                GenericParamKind::Type { .. } => {
                                    let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
                                    let mut bounds = Vec::new();
                                    icx.lowerer().add_implicit_sizedness_bounds(&mut bounds,
                                        param_ty, &[],
                                        ImpliedBoundsContext::TyParam(param.def_id,
                                            hir_generics.predicates), param.span);
                                    icx.lowerer().add_default_traits(&mut bounds, param_ty, &[],
                                        ImpliedBoundsContext::TyParam(param.def_id,
                                            hir_generics.predicates), param.span);
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:251",
                                                            "rustc_hir_analysis::collect::clauses_of",
                                                            ::tracing::Level::TRACE,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(251u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("bounds")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("bounds");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::TRACE <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::TRACE <=
                                                        ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    clauses.extend(bounds);
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:253",
                                                            "rustc_hir_analysis::collect::clauses_of",
                                                            ::tracing::Level::TRACE,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(253u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("clauses")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("clauses");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::TRACE <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::TRACE <=
                                                        ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                }
                                hir::GenericParamKind::Const { .. } => {
                                    let param_def_id = param.def_id.to_def_id();
                                    let ct_ty =
                                        tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip();
                                    let ct =
                                        icx.lowerer().lower_const_param(param_def_id, param.hir_id);
                                    clauses.insert((ty::ClauseKind::ConstArgHasType(ct,
                                                    ct_ty).upcast(tcx), param.span));
                                }
                            }
                        }
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:265",
                                                "rustc_hir_analysis::collect::clauses_of",
                                                ::tracing::Level::TRACE,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                ::tracing_core::__macro_support::Option::Some(265u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("clauses")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("clauses");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::TRACE <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::TRACE <=
                                            ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        for predicate in hir_generics.predicates {
                            where_predicate_clauses(&icx, predicate, &mut clauses);
                        }
                        if tcx.features().generic_const_exprs() {
                            clauses.extend(const_evaluatable_clauses_of(tcx, def_id,
                                    &clauses));
                        }
                        let attrs =
                            tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
                        let allow_unstable_feature_attr =
                            {
                                        'done:
                                            {
                                            for i in attrs {
                                                #[allow(unused_imports)]
                                                use ::rustc_attr_ir::AttributeKind::*;
                                                let i: &::rustc_attr_ir::Attribute = i;
                                                match i {
                                                    ::rustc_attr_ir::Attribute::Parsed(UnstableFeatureBound(i))
                                                        => {
                                                        break 'done Some(i);
                                                    }
                                                    ::rustc_attr_ir::Attribute::Unparsed(..) =>
                                                        {}
                                                        #[deny(unreachable_patterns)]
                                                        _ => {}
                                                }
                                            }
                                            None
                                        }
                                    }.map(|i| i.as_slice()).unwrap_or_default();
                        for (feat_name, span) in allow_unstable_feature_attr {
                            clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx),
                                    *span));
                        }
                        let mut clauses: Vec<_> = clauses.into_iter().collect();
                        if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. })
                                = node {
                            let self_ty =
                                tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
                            let trait_ref =
                                impl_.of_trait.is_some().then(||
                                        tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip());
                            cgp::setup_constraining_clauses(tcx, &mut clauses,
                                trait_ref,
                                &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref));
                        }
                        if let Node::OpaqueTy(..) = node {
                            compute_bidirectional_outlives_clauses(tcx,
                                &generics.own_params, &mut clauses);
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:312",
                                                    "rustc_hir_analysis::collect::clauses_of",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(312u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                    ::tracing_core::field::FieldSet::new(&[{
                                                                        const NAME:
                                                                            ::tracing::__macro_support::FieldName<{
                                                                                ::tracing::__macro_support::FieldName::len("clauses")
                                                                            }> =
                                                                            ::tracing::__macro_support::FieldName::new("clauses");
                                                                        NAME.as_str()
                                                                    }], ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                        }
                        ty::GenericClauses {
                            parent: generics.parent,
                            clauses: tcx.arena.alloc_from_iter(clauses),
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:81",
                        "rustc_hir_analysis::collect::clauses_of",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(81u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "trace", skip(tcx), ret)]
82fn gather_explicit_clauses_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericClauses<'_> {
83    use rustc_hir::*;
84
85    match tcx.opt_rpitit_info(def_id.to_def_id()) {
86        Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
87            let mut clauses = Vec::new();
88
89            // RPITITs should inherit the clauses of their parent. This is
90            // both to ensure that the RPITITs are only instantiated when the
91            // parent clauses would hold, and also so that the param-env
92            // inherits these clauses as assumptions.
93            let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
94            clauses.extend(
95                tcx.explicit_clauses_of(fn_def_id)
96                    .instantiate_own(tcx, identity_args)
97                    .map(|(c, s)| (c.skip_norm_wip(), s)),
98            );
99
100            // We also install bidirectional outlives clauses for the RPITIT
101            // to keep the duplicates lifetimes from opaque lowering in sync.
102            // We only need to compute bidirectional outlives for the duplicated
103            // opaque lifetimes, which explains the slicing below.
104            compute_bidirectional_outlives_clauses(
105                tcx,
106                &tcx.generics_of(def_id.to_def_id()).own_params
107                    [tcx.generics_of(fn_def_id).own_params.len()..],
108                &mut clauses,
109            );
110
111            return ty::GenericClauses {
112                parent: Some(tcx.local_parent(def_id).to_def_id()),
113                clauses: tcx.arena.alloc_from_iter(clauses),
114            };
115        }
116
117        Some(ImplTraitInTraitData::Impl { fn_def_id }) => {
118            let trait_item_def_id = tcx.trait_item_of(def_id).unwrap();
119            let trait_assoc_clauses = tcx.explicit_clauses_of(trait_item_def_id);
120
121            let impl_assoc_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
122            let impl_def_id = tcx.parent(fn_def_id);
123            let impl_trait_ref_args =
124                tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args;
125
126            let impl_assoc_args =
127                impl_assoc_identity_args.rebase_onto(tcx, impl_def_id, impl_trait_ref_args);
128
129            let impl_clauses = trait_assoc_clauses
130                .instantiate_own(tcx, impl_assoc_args)
131                .map(|(c, s)| (c.skip_norm_wip(), s));
132
133            return ty::GenericClauses {
134                parent: Some(impl_def_id),
135                clauses: tcx.arena.alloc_from_iter(impl_clauses),
136            };
137        }
138
139        None => {}
140    }
141
142    let hir_id = tcx.local_def_id_to_hir_id(def_id);
143    let node = tcx.hir_node(hir_id);
144
145    if let Some(sig) = node.fn_sig()
146        && let Some(sig_id) = sig.decl.opt_delegation_sig_id()
147    {
148        return inherit_clauses_for_delegation_item(tcx, def_id, sig_id);
149    }
150
151    let mut is_trait = None;
152    let mut is_default_impl_trait = None;
153
154    let icx = ItemCtxt::new(tcx, def_id);
155
156    const NO_GENERICS: &hir::Generics<'_> = hir::Generics::empty();
157
158    // We use an `IndexSet` to preserve order of insertion.
159    // Preserving the order of insertion is important here so as not to break UI tests.
160    let mut clauses: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default();
161
162    let hir_generics = node.generics().unwrap_or(NO_GENERICS);
163    if let Node::Item(item) = node {
164        match item.kind {
165            ItemKind::Impl(impl_) => {
166                if let Some(of_trait) = impl_.of_trait
167                    && of_trait.defaultness.is_default()
168                {
169                    is_default_impl_trait = Some(ty::Binder::dummy(
170                        tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip(),
171                    ));
172                }
173            }
174            ItemKind::Trait { bounds: self_bounds, .. }
175            | ItemKind::TraitAlias(_, _, _, self_bounds) => {
176                is_trait = Some((self_bounds, item.span));
177            }
178            _ => {}
179        }
180    };
181
182    let generics = tcx.generics_of(def_id);
183
184    // Below we'll consider the bounds on the type parameters (including `Self`)
185    // and the explicit where-clauses, but to get the full set of clauses
186    // on a trait we must also consider the bounds that follow the trait's name,
187    // like `trait Foo: A + B + C`.
188    if let Some((self_bounds, span)) = is_trait {
189        let mut bounds = Vec::new();
190        icx.lowerer().lower_bounds(
191            tcx.types.self_param,
192            self_bounds,
193            &mut bounds,
194            ty::List::empty(),
195            PredicateFilter::All,
196            OverlappingAsssocItemConstraints::Allowed,
197        );
198        icx.lowerer().add_implicit_sizedness_bounds(
199            &mut bounds,
200            tcx.types.self_param,
201            self_bounds,
202            ImpliedBoundsContext::TraitDef(def_id),
203            span,
204        );
205        icx.lowerer().add_default_traits(
206            &mut bounds,
207            tcx.types.self_param,
208            self_bounds,
209            ImpliedBoundsContext::TraitDef(def_id),
210            span,
211        );
212        clauses.extend(bounds);
213    }
214
215    // In default impls, we can assume that the self type implements
216    // the trait. So in:
217    //
218    //     default impl Foo for Bar { .. }
219    //
220    // we add a default where clause `Bar: Foo`. We do a similar thing for traits
221    // (see below). Recall that a default impl is not itself an impl, but rather a
222    // set of defaults that can be incorporated into another impl.
223    if let Some(trait_ref) = is_default_impl_trait {
224        clauses.insert((trait_ref.upcast(tcx), tcx.def_span(def_id)));
225    }
226
227    // Add implicit clauses that should be treated as if the user has written them,
228    // including the implicit `T: Sized` for all generic parameters, and `ConstArgHasType`
229    // for const params.
230    for param in hir_generics.params {
231        match param.kind {
232            GenericParamKind::Lifetime { .. } => (),
233            GenericParamKind::Type { .. } => {
234                let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
235                let mut bounds = Vec::new();
236                // Implicit bounds are added to type params unless a `?Trait` bound is found
237                icx.lowerer().add_implicit_sizedness_bounds(
238                    &mut bounds,
239                    param_ty,
240                    &[],
241                    ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
242                    param.span,
243                );
244                icx.lowerer().add_default_traits(
245                    &mut bounds,
246                    param_ty,
247                    &[],
248                    ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
249                    param.span,
250                );
251                trace!(?bounds);
252                clauses.extend(bounds);
253                trace!(?clauses);
254            }
255            hir::GenericParamKind::Const { .. } => {
256                let param_def_id = param.def_id.to_def_id();
257                let ct_ty = tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip();
258                let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
259                clauses
260                    .insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
261            }
262        }
263    }
264
265    trace!(?clauses);
266    // Add inline `<T: Foo>` bounds and bounds in the where clause.
267    for predicate in hir_generics.predicates {
268        where_predicate_clauses(&icx, predicate, &mut clauses);
269    }
270
271    if tcx.features().generic_const_exprs() {
272        clauses.extend(const_evaluatable_clauses_of(tcx, def_id, &clauses));
273    }
274
275    let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
276    // FIXME(staged_api): We might want to look at the normal stability attributes too but
277    // first we would need a way to let std/core use APIs with unstable feature bounds from
278    // within stable APIs.
279    let allow_unstable_feature_attr =
280        find_attr!(attrs, UnstableFeatureBound(i) => i).map(|i| i.as_slice()).unwrap_or_default();
281
282    for (feat_name, span) in allow_unstable_feature_attr {
283        clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span));
284    }
285
286    let mut clauses: Vec<_> = clauses.into_iter().collect();
287
288    // Subtle: before we store the clauses into the tcx, we
289    // sort them so that clauses like `T: Foo<Item=U>` come
290    // before uses of `U`. This avoids false ambiguity errors
291    // in trait checking. See `setup_constraining_clauses`
292    // for details.
293    if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node {
294        let self_ty = tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
295        let trait_ref = impl_
296            .of_trait
297            .is_some()
298            .then(|| tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip());
299        cgp::setup_constraining_clauses(
300            tcx,
301            &mut clauses,
302            trait_ref,
303            &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref),
304        );
305    }
306
307    // Opaque types duplicate some of their generic parameters.
308    // We create bi-directional Outlives clauses between the original
309    // and the duplicated parameter, to ensure that they do not get out of sync.
310    if let Node::OpaqueTy(..) = node {
311        compute_bidirectional_outlives_clauses(tcx, &generics.own_params, &mut clauses);
312        debug!(?clauses);
313    }
314
315    ty::GenericClauses { parent: generics.parent, clauses: tcx.arena.alloc_from_iter(clauses) }
316}
317
318pub(super) fn where_predicate_clauses<'tcx>(
319    icx: &ItemCtxt<'tcx>,
320    predicate: &hir::WherePredicate<'_>,
321    clauses: &mut FxIndexSet<(ty::Clause<'tcx>, Span)>,
322) {
323    let tcx = icx.tcx;
324    match predicate.kind {
325        hir::WherePredicateKind::BoundPredicate(bound_pred) => {
326            let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
327            let bound_vars = tcx.late_bound_vars(predicate.hir_id);
328
329            // This is a `where Ty:` (sic!).
330            if bound_pred.bounds.is_empty() {
331                if let ty::Param(_) = ty.kind() {
332                    // We can skip the predicate because type parameters are trivially WF.
333                } else {
334                    // Keep the type around in a dummy predicate. That way, it's not a complete
335                    // noop (see #53696) and `Ty` is still checked for WF.
336
337                    let span = bound_pred.bounded_ty.span;
338                    let clause = ty::Binder::bind_with_vars(
339                        ty::ClauseKind::WellFormed(ty.into()),
340                        bound_vars,
341                    );
342                    clauses.insert((clause.upcast(tcx), span));
343                }
344            }
345
346            let mut bounds = Vec::new();
347            icx.lowerer().lower_bounds(
348                ty,
349                bound_pred.bounds,
350                &mut bounds,
351                bound_vars,
352                PredicateFilter::All,
353                OverlappingAsssocItemConstraints::Allowed,
354            );
355            clauses.extend(bounds);
356        }
357
358        hir::WherePredicateKind::RegionPredicate(region_pred) => {
359            let r1 = icx
360                .lowerer()
361                .lower_lifetime(region_pred.lifetime, RegionInferReason::RegionPredicate);
362            clauses.extend(region_pred.bounds.iter().map(|bound| {
363                let (r2, span) = match bound {
364                    hir::GenericBound::Outlives(lt) => (
365                        icx.lowerer().lower_lifetime(lt, RegionInferReason::RegionPredicate),
366                        lt.ident.span,
367                    ),
368                    bound => {
369                        bug_impl(Some(bound.span()),
    format_args!("lifetime param bounds must be outlives, but found {0:?}",
        bound), Location::caller())span_bug!(
370                            bound.span(),
371                            "lifetime param bounds must be outlives, but found {bound:?}"
372                        )
373                    }
374                };
375                let clause = ty::ClauseKind::RegionOutlives(ty::OutlivesClause(r1, r2)).upcast(tcx);
376                (clause, span)
377            }))
378        }
379    }
380}
381
382/// Opaques have duplicated lifetimes and we need to compute bidirectional outlives clauses to
383/// enforce that these lifetimes stay in sync.
384fn compute_bidirectional_outlives_clauses<'tcx>(
385    tcx: TyCtxt<'tcx>,
386    opaque_own_params: &[ty::GenericParamDef],
387    clauses: &mut Vec<(ty::Clause<'tcx>, Span)>,
388) {
389    for param in opaque_own_params {
390        let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
391        if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
392            let dup_lifetime = ty::Region::new_early_param(
393                tcx,
394                ty::EarlyParamRegion { index: param.index, name: param.name },
395            );
396            let span = tcx.def_span(param.def_id);
397            clauses.push((
398                ty::ClauseKind::RegionOutlives(ty::OutlivesClause(orig_lifetime, dup_lifetime))
399                    .upcast(tcx),
400                span,
401            ));
402            clauses.push((
403                ty::ClauseKind::RegionOutlives(ty::OutlivesClause(dup_lifetime, orig_lifetime))
404                    .upcast(tcx),
405                span,
406            ));
407        }
408    }
409}
410
411{}
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("const_evaluatable_clauses_of",
                                "rustc_hir_analysis::collect::clauses_of",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                ::tracing_core::__macro_support::Option::Some(411u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                FxIndexSet<(ty::Clause<'tcx>, Span)> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        struct ConstCollector<'tcx> {
                            tcx: TyCtxt<'tcx>,
                            clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>,
                        }
                        fn is_const_param_default(tcx: TyCtxt<'_>,
                            kind: ty::AliasConstKind<'_>) -> bool {
                            let ty::AliasConstKind::Anon { def_id } =
                                kind else { return false };
                            let Some(local) = def_id.as_local() else { return false };
                            let hir_id = tcx.local_def_id_to_hir_id(local);
                            let (_, parent_node) =
                                tcx.hir_parent_iter(hir_id).skip_while(|(_, n)|
                                                #[allow(non_exhaustive_omitted_patterns)] match n {
                                                    Node::ConstArg(..) => true,
                                                    _ => false,
                                                }).next().unwrap();

                            #[allow(non_exhaustive_omitted_patterns)]
                            match parent_node {
                                Node::GenericParam(hir::GenericParam {
                                    kind: hir::GenericParamKind::Const { .. }, .. }) => true,
                                _ => false,
                            }
                        }
                        impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for
                            ConstCollector<'tcx> {
                            fn visit_const(&mut self, c: ty::Const<'tcx>) {
                                if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
                                    if is_const_param_default(self.tcx, alias_const.kind) {
                                        return;
                                    }
                                    if alias_const.kind.is_direct_const(self.tcx) { return; }
                                    let span = alias_const.kind.def_span(self.tcx);
                                    self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx),
                                            span));
                                }
                            }
                        }
                        let hir_id = tcx.local_def_id_to_hir_id(def_id);
                        let node = tcx.hir_node(hir_id);
                        let mut collector =
                            ConstCollector { tcx, clauses: FxIndexSet::default() };
                        for (clause, _sp) in clauses {
                            clause.visit_with(&mut collector);
                        }
                        if let hir::Node::Item(item) = node &&
                                let hir::ItemKind::Impl(impl_) = item.kind {
                            if impl_.of_trait.is_some() {
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:476",
                                                        "rustc_hir_analysis::collect::clauses_of",
                                                        ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(476u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                        ::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};
                                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit impl trait_ref")
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                let trait_ref = tcx.impl_trait_ref(def_id);
                                trait_ref.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
                            }
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:481",
                                                    "rustc_hir_analysis::collect::clauses_of",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(481u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit self_ty")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            let self_ty = tcx.type_of(def_id);
                            self_ty.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
                        }
                        if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:487",
                                                    "rustc_hir_analysis::collect::clauses_of",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(487u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit fn sig")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            let fn_sig = tcx.fn_sig(def_id);
                            let fn_sig = fn_sig.instantiate_identity().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 /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:490",
                                                    "rustc_hir_analysis::collect::clauses_of",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(490u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                                    ::tracing_core::field::FieldSet::new(&[{
                                                                        const NAME:
                                                                            ::tracing::__macro_support::FieldName<{
                                                                                ::tracing::__macro_support::FieldName::len("fn_sig")
                                                                            }> =
                                                                            ::tracing::__macro_support::FieldName::new("fn_sig");
                                                                        NAME.as_str()
                                                                    }], ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            fn_sig.visit_with(&mut collector);
                        }
                        collector.clauses
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:411",
                        "rustc_hir_analysis::collect::clauses_of",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(411u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(tcx, clauses), ret)]
412fn const_evaluatable_clauses_of<'tcx>(
413    tcx: TyCtxt<'tcx>,
414    def_id: LocalDefId,
415    clauses: &FxIndexSet<(ty::Clause<'tcx>, Span)>,
416) -> FxIndexSet<(ty::Clause<'tcx>, Span)> {
417    struct ConstCollector<'tcx> {
418        tcx: TyCtxt<'tcx>,
419        clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>,
420    }
421
422    fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool {
423        let ty::AliasConstKind::Anon { def_id } = kind else { return false };
424        let Some(local) = def_id.as_local() else { return false };
425
426        let hir_id = tcx.local_def_id_to_hir_id(local);
427        let (_, parent_node) = tcx
428            .hir_parent_iter(hir_id)
429            .skip_while(|(_, n)| matches!(n, Node::ConstArg(..)))
430            .next()
431            .unwrap();
432        matches!(
433            parent_node,
434            Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { .. }, .. })
435        )
436    }
437
438    impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
439        fn visit_const(&mut self, c: ty::Const<'tcx>) {
440            if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
441                if is_const_param_default(self.tcx, alias_const.kind) {
442                    // Do not look into const param defaults,
443                    // these get checked when they are actually instantiated.
444                    //
445                    // We do not want the following to error:
446                    //
447                    //     struct Foo<const N: usize, const M: usize = { N + 1 }>;
448                    //     struct Bar<const N: usize>(Foo<N, 3>);
449                    return;
450                }
451
452                // Skip type consts as mGCA doesn't support evaluatable clauses.
453                if alias_const.kind.is_direct_const(self.tcx) {
454                    return;
455                }
456
457                let span = alias_const.kind.def_span(self.tcx);
458                self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span));
459            }
460        }
461    }
462
463    let hir_id = tcx.local_def_id_to_hir_id(def_id);
464    let node = tcx.hir_node(hir_id);
465
466    let mut collector = ConstCollector { tcx, clauses: FxIndexSet::default() };
467
468    for (clause, _sp) in clauses {
469        clause.visit_with(&mut collector);
470    }
471
472    if let hir::Node::Item(item) = node
473        && let hir::ItemKind::Impl(impl_) = item.kind
474    {
475        if impl_.of_trait.is_some() {
476            debug!("visit impl trait_ref");
477            let trait_ref = tcx.impl_trait_ref(def_id);
478            trait_ref.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
479        }
480
481        debug!("visit self_ty");
482        let self_ty = tcx.type_of(def_id);
483        self_ty.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
484    }
485
486    if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
487        debug!("visit fn sig");
488        let fn_sig = tcx.fn_sig(def_id);
489        let fn_sig = fn_sig.instantiate_identity().skip_norm_wip();
490        debug!(?fn_sig);
491        fn_sig.visit_with(&mut collector);
492    }
493
494    collector.clauses
495}
496
497pub(super) fn trait_explicit_clauses_and_bounds(
498    tcx: TyCtxt<'_>,
499    def_id: LocalDefId,
500) -> ty::GenericClauses<'_> {
501    {
    match (&tcx.def_kind(def_id), &DefKind::Trait) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
502    gather_explicit_clauses_of(tcx, def_id)
503}
504
505pub(super) fn explicit_clauses_of<'tcx>(
506    tcx: TyCtxt<'tcx>,
507    def_id: LocalDefId,
508) -> ty::GenericClauses<'tcx> {
509    let def_kind = tcx.def_kind(def_id);
510    if let DefKind::Trait = def_kind {
511        // Remove bounds on associated types from the clauses, they will be
512        // returned by `explicit_item_bounds`.
513        let clauses_and_bounds = tcx.trait_explicit_clauses_and_bounds(def_id);
514        let trait_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
515
516        let is_assoc_item_ty = |ty: Ty<'tcx>| {
517            // For a predicate from a where clause to become a bound on an
518            // associated type:
519            // * It must use the identity args of the item.
520            //   * We're in the scope of the trait, so we can't name any
521            //     parameters of the GAT. That means that all we need to
522            //     check are that the args of the projection are the
523            //     identity args of the trait.
524            // * It must be an associated type for this trait (*not* a
525            //   supertrait).
526            if let &ty::Alias(
527                _,
528                ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, args, .. },
529            ) = ty.kind()
530            {
531                args == trait_identity_args
532                    // FIXME(return_type_notation): This check should be more robust
533                    && !tcx.is_impl_trait_in_trait(projection_def_id)
534                    && tcx.parent(projection_def_id) == def_id.to_def_id()
535            } else {
536                false
537            }
538        };
539
540        let clauses: Vec<_> = clauses_and_bounds
541            .clauses
542            .iter()
543            .copied()
544            .filter(|(clause, _)| match clause.kind().skip_binder() {
545                ty::ClauseKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
546                ty::ClauseKind::Projection(proj) => {
547                    !is_assoc_item_ty(proj.projection_term.self_ty())
548                }
549                ty::ClauseKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
550                _ => true,
551            })
552            .collect();
553        if clauses.len() == clauses_and_bounds.clauses.len() {
554            clauses_and_bounds
555        } else {
556            ty::GenericClauses {
557                parent: clauses_and_bounds.parent,
558                clauses: tcx.arena.alloc_slice(&clauses),
559            }
560        }
561    } else {
562        if def_kind == DefKind::AnonConst
563            && tcx.features().generic_const_exprs()
564            && let Some(defaulted_param_def_id) =
565                tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
566        {
567            // In `generics_of` we set the generics' parent to be our parent's parent which means that
568            // we lose out on the clauses of our actual parent if we dont return those clauses here.
569            // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
570            //
571            // struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait;
572            //        ^^^                     ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling
573            //        ^^^                                             explicit_clauses_of on
574            //        parent item we dont have set as the
575            //        parent of generics returned by `generics_of`
576            //
577            // In the above code we want the anon const to have clauses in its param env for `T: Trait`
578            // and we would be calling `explicit_clauses_of(Foo)` here
579            let parent_def_id = tcx.local_parent(def_id);
580            let parent_clauses = tcx.explicit_clauses_of(parent_def_id);
581
582            // If we dont filter out `ConstArgHasType` clauses then every single defaulted const parameter
583            // will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
584            // to #106994 is implemented.
585            let filtered_clauses = parent_clauses
586                .clauses
587                .into_iter()
588                .filter(|(clause, _)| {
589                    if let ty::ClauseKind::ConstArgHasType(ct, _) = clause.kind().skip_binder() {
590                        match ct.kind() {
591                            ty::ConstKind::Param(param_const) => {
592                                let defaulted_param_idx = tcx
593                                    .generics_of(parent_def_id)
594                                    .param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
595                                param_const.index < defaulted_param_idx
596                            }
597                            _ => {
598                                bug_impl(None,
    format_args!("`ConstArgHasType` in `clauses_of` that isn\'t a `Param` const"),
    Location::caller())bug!("`ConstArgHasType` in `clauses_of` that isn't a `Param` const")
599                            }
600                        }
601                    } else {
602                        true
603                    }
604                })
605                .cloned();
606            return GenericClauses {
607                parent: parent_clauses.parent,
608                clauses: { tcx.arena.alloc_from_iter(filtered_clauses) },
609            };
610        }
611        gather_explicit_clauses_of(tcx, def_id)
612    }
613}
614
615/// Ensures that the super-clauses of the trait with a `DefId`
616/// of `trait_def_id` are lowered and stored. This also ensures that
617/// the transitive super-clauses are lowered.
618pub(super) fn explicit_super_clauses_of<'tcx>(
619    tcx: TyCtxt<'tcx>,
620    trait_def_id: LocalDefId,
621) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
622    implied_clauses_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
623}
624
625pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
626    tcx: TyCtxt<'tcx>,
627    (trait_def_id, assoc_ident): (DefId, Ident),
628) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
629    implied_clauses_with_filter(
630        tcx,
631        trait_def_id,
632        PredicateFilter::SelfTraitThatDefines(assoc_ident),
633    )
634}
635
636pub(super) fn explicit_implied_clauses_of<'tcx>(
637    tcx: TyCtxt<'tcx>,
638    trait_def_id: LocalDefId,
639) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
640    implied_clauses_with_filter(
641        tcx,
642        trait_def_id.to_def_id(),
643        if tcx.is_trait_alias(trait_def_id.to_def_id()) {
644            PredicateFilter::All
645        } else {
646            PredicateFilter::SelfAndAssociatedTypeBounds
647        },
648    )
649}
650
651/// Ensures that the super-clauses of the trait with a `DefId`
652/// of `trait_def_id` are lowered and stored. This also ensures that
653/// the transitive super-clauses are lowered.
654pub(super) fn implied_clauses_with_filter<'tcx>(
655    tcx: TyCtxt<'tcx>,
656    trait_def_id: DefId,
657    filter: PredicateFilter,
658) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
659    let Some(trait_def_id) = trait_def_id.as_local() else {
660        // if `assoc_ident` is None, then the query should've been redirected to an
661        // external provider
662        {
    match filter {
        PredicateFilter::SelfTraitThatDefines(_) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "PredicateFilter::SelfTraitThatDefines(_)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(filter, PredicateFilter::SelfTraitThatDefines(_));
663        return tcx.explicit_super_clauses_of(trait_def_id);
664    };
665
666    let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else {
667        bug_impl(None,
    format_args!("trait_def_id {0:?} is not an item", trait_def_id),
    Location::caller());bug!("trait_def_id {trait_def_id:?} is not an item");
668    };
669
670    let (generics, superbounds) = match item.kind {
671        hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits),
672        hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
673        _ => bug_impl(Some(item.span), format_args!("super_clauses invoked on non-trait"),
    Location::caller())span_bug!(item.span, "super_clauses invoked on non-trait"),
674    };
675
676    let icx = ItemCtxt::new(tcx, trait_def_id);
677
678    let self_param_ty = tcx.types.self_param;
679    let mut bounds = Vec::new();
680    icx.lowerer().lower_bounds(
681        self_param_ty,
682        superbounds,
683        &mut bounds,
684        ty::List::empty(),
685        filter,
686        OverlappingAsssocItemConstraints::Allowed,
687    );
688    match filter {
689        PredicateFilter::All
690        | PredicateFilter::SelfOnly
691        | PredicateFilter::SelfTraitThatDefines(_)
692        | PredicateFilter::SelfAndAssociatedTypeBounds => {
693            icx.lowerer().add_implicit_sizedness_bounds(
694                &mut bounds,
695                self_param_ty,
696                superbounds,
697                ImpliedBoundsContext::TraitDef(trait_def_id),
698                item.span,
699            );
700            icx.lowerer().add_default_traits(
701                &mut bounds,
702                self_param_ty,
703                superbounds,
704                ImpliedBoundsContext::TraitDef(trait_def_id),
705                item.span,
706            );
707        }
708        //`ConstIfConst` is only interested in `[const]` bounds.
709        PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
710    }
711
712    let where_bounds_that_match =
713        icx.probe_ty_param_bounds_in_generics(generics, item.owner_id.def_id, filter);
714
715    // Combine the two lists to form the complete set of superbounds:
716    let implied_bounds =
717        &*tcx.arena.alloc_from_iter(bounds.into_iter().chain(where_bounds_that_match));
718    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:718",
                        "rustc_hir_analysis::collect::clauses_of",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(718u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("implied_bounds")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("implied_bounds");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&implied_bounds)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?implied_bounds);
719
720    // Now require that immediate supertraits are lowered, which will, in
721    // turn, reach indirect supertraits, so we detect cycles now instead of
722    // overflowing during elaboration. Same for implied predicates, which
723    // make sure we walk into associated type bounds.
724    match filter {
725        PredicateFilter::SelfOnly => {
726            for &(clause, span) in implied_bounds {
727                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:727",
                        "rustc_hir_analysis::collect::clauses_of",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(727u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("superbound: {0:?}",
                                                    clause) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("superbound: {:?}", clause);
728                if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
729                    && bound.polarity == ty::ClausePolarity::Positive
730                {
731                    tcx.at(span).explicit_super_clauses_of(bound.def_id());
732                }
733            }
734        }
735        PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
736            for &(clause, span) in implied_bounds {
737                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:737",
                        "rustc_hir_analysis::collect::clauses_of",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(737u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("superbound: {0:?}",
                                                    clause) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("superbound: {:?}", clause);
738                if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
739                    && bound.polarity == ty::ClausePolarity::Positive
740                {
741                    tcx.at(span).explicit_implied_clauses_of(bound.def_id());
742                }
743            }
744        }
745        _ => {}
746    }
747
748    assert_only_contains_clauses_from(filter, implied_bounds, tcx.types.self_param);
749
750    ty::EarlyBinder::bind_iter(implied_bounds)
751}
752
753// Make sure when elaborating supertraits, probing for associated types, etc.,
754// we really truly are elaborating clauses that have `ty` as their self type.
755// This is very important since downstream code relies on this being correct.
756pub(super) fn assert_only_contains_clauses_from<'tcx>(
757    filter: PredicateFilter,
758    bounds: &'tcx [(ty::Clause<'tcx>, Span)],
759    ty: Ty<'tcx>,
760) {
761    if !truecfg!(debug_assertions) {
762        return;
763    }
764
765    match filter {
766        PredicateFilter::SelfOnly => {
767            for (clause, _) in bounds {
768                match clause.kind().skip_binder() {
769                    ty::ClauseKind::Trait(trait_predicate) => {
770                        {
    match (&trait_predicate.self_ty(), &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
771                            trait_predicate.self_ty(),
772                            ty,
773                            "expected `Self` predicate when computing \
774                            `{filter:?}` implied bounds: {clause:?}"
775                        );
776                    }
777                    ty::ClauseKind::Projection(projection_predicate) => {
778                        {
    match (&projection_predicate.self_ty(), &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
779                            projection_predicate.self_ty(),
780                            ty,
781                            "expected `Self` predicate when computing \
782                            `{filter:?}` implied bounds: {clause:?}"
783                        );
784                    }
785                    ty::ClauseKind::TypeOutlives(outlives_clause) => {
786                        {
    match (&outlives_clause.0, &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
787                            outlives_clause.0, ty,
788                            "expected `Self` clause when computing \
789                            `{filter:?}` implied bounds: {clause:?}"
790                        );
791                    }
792                    ty::ClauseKind::HostEffect(host_effect_clause) => {
793                        {
    match (&host_effect_clause.self_ty(), &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
794                            host_effect_clause.self_ty(),
795                            ty,
796                            "expected `Self` clause when computing \
797                            `{filter:?}` implied bounds: {clause:?}"
798                        );
799                    }
800
801                    ty::ClauseKind::RegionOutlives(_)
802                    | ty::ClauseKind::ConstArgHasType(_, _)
803                    | ty::ClauseKind::WellFormed(_)
804                    | ty::ClauseKind::UnstableFeature(_)
805                    | ty::ClauseKind::ConstEvaluatable(_) => {
806                        bug_impl(None,
    format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
        filter, clause), Location::caller());bug!(
807                            "unexpected non-`Self` predicate when computing \
808                            `{filter:?}` implied bounds: {clause:?}"
809                        );
810                    }
811                }
812            }
813        }
814        PredicateFilter::SelfTraitThatDefines(_) => {
815            for (clause, _) in bounds {
816                match clause.kind().skip_binder() {
817                    ty::ClauseKind::Trait(trait_predicate) => {
818                        {
    match (&trait_predicate.self_ty(), &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
819                            trait_predicate.self_ty(),
820                            ty,
821                            "expected `Self` predicate when computing \
822                            `{filter:?}` implied bounds: {clause:?}"
823                        );
824                    }
825
826                    ty::ClauseKind::Projection(_)
827                    | ty::ClauseKind::TypeOutlives(_)
828                    | ty::ClauseKind::RegionOutlives(_)
829                    | ty::ClauseKind::ConstArgHasType(_, _)
830                    | ty::ClauseKind::WellFormed(_)
831                    | ty::ClauseKind::ConstEvaluatable(_)
832                    | ty::ClauseKind::UnstableFeature(_)
833                    | ty::ClauseKind::HostEffect(..) => {
834                        bug_impl(None,
    format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
        filter, clause), Location::caller());bug!(
835                            "unexpected non-`Self` predicate when computing \
836                            `{filter:?}` implied bounds: {clause:?}"
837                        );
838                    }
839                }
840            }
841        }
842        PredicateFilter::ConstIfConst => {
843            for (clause, _) in bounds {
844                match clause.kind().skip_binder() {
845                    ty::ClauseKind::HostEffect(ty::HostEffectClause {
846                        trait_ref: _,
847                        constness: ty::BoundConstness::Maybe,
848                    }) => {}
849                    _ => {
850                        bug_impl(None,
    format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
        filter, clause), Location::caller());bug!(
851                            "unexpected non-`HostEffect` clause when computing \
852                            `{filter:?}` implied bounds: {clause:?}"
853                        );
854                    }
855                }
856            }
857        }
858        PredicateFilter::SelfConstIfConst => {
859            for (clause, _) in bounds {
860                match clause.kind().skip_binder() {
861                    ty::ClauseKind::HostEffect(host_clause) => {
862                        {
    match (&host_clause.constness, &ty::BoundConstness::Maybe) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `[const]` clause when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
863                            host_clause.constness,
864                            ty::BoundConstness::Maybe,
865                            "expected `[const]` clause when computing `{filter:?}` \
866                            implied bounds: {clause:?}",
867                        );
868                        {
    match (&host_clause.trait_ref.self_ty(), &ty) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val,
                    ::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
                            filter, clause)));
            }
        }
    }
};assert_eq!(
869                            host_clause.trait_ref.self_ty(),
870                            ty,
871                            "expected `Self` clause when computing `{filter:?}` \
872                            implied bounds: {clause:?}"
873                        );
874                    }
875                    _ => {
876                        bug_impl(None,
    format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
        filter, clause), Location::caller());bug!(
877                            "unexpected non-`HostEffect` clause when computing \
878                            `{filter:?}` implied bounds: {clause:?}"
879                        );
880                    }
881                }
882            }
883        }
884        PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {}
885    }
886}
887
888/// Returns the clauses defined on `item_def_id` of the form
889/// `X: Foo` where `X` is the type parameter `def_id`.
890{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("type_param_clauses",
                                    "rustc_hir_analysis::collect::clauses_of",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                    ::tracing_core::__macro_support::Option::Some(890u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item_def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("assoc_ident")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("assoc_ident");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
                                                            as &dyn ::tracing::field::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:
                    ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
                Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) =>
                    {
                    return tcx.type_param_clauses((opaque_def_id.expect_local(),
                                def_id, assoc_ident));
                }
                Some(ty::ImplTraitInTraitData::Impl { .. }) => {
                    {
                        ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                format_args!("should not be lowering bounds on RPITIT in impl")));
                    }
                }
                None => {}
            }
            let param_id = tcx.local_def_id_to_hir_id(def_id);
            let param_owner = tcx.hir_ty_param_owner(def_id);
            let parent =
                if item_def_id == param_owner {
                    None
                } else {
                    tcx.generics_of(item_def_id).parent.map(|def_id|
                            def_id.expect_local())
                };
            let result =
                if let Some(parent) = parent {
                    let icx = ItemCtxt::new(tcx, parent);
                    icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
                } else { ty::EarlyBinder::bind_iter(&[] as &[_]) };
            let mut extend = None;
            let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
            let hir_node = tcx.hir_node(item_hir_id);
            let Some(hir_generics) =
                hir_node.generics() else { return result; };
            if let Node::Item(item) = hir_node &&
                        let hir::ItemKind::Trait { .. } = item.kind &&
                    param_id == item_hir_id {
                let identity_trait_ref =
                    ty::TraitRef::identity(tcx, item_def_id.to_def_id());
                extend = Some((identity_trait_ref.upcast(tcx), item.span));
            }
            let icx = ItemCtxt::new(tcx, item_def_id);
            let extra_clauses =
                extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics(hir_generics,
                        def_id,
                        PredicateFilter::SelfTraitThatDefines(assoc_ident)));
            let bounds =
                &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses));
            let self_ty =
                match tcx.def_kind(def_id) {
                    DefKind::TyParam =>
                        Ty::new_param(tcx,
                            tcx.generics_of(item_def_id).param_def_id_to_index(tcx,
                                    def_id.to_def_id()).expect("expected generic param to be owned by item"),
                            tcx.item_name(def_id.to_def_id())),
                    DefKind::Trait | DefKind::TraitAlias =>
                        tcx.types.self_param,
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                };
            assert_only_contains_clauses_from(PredicateFilter::SelfTraitThatDefines(assoc_ident),
                bounds, self_ty);
            ty::EarlyBinder::bind_iter(bounds)
        }
    }
}#[instrument(level = "trace", skip(tcx))]
891pub(super) fn type_param_clauses<'tcx>(
892    tcx: TyCtxt<'tcx>,
893    (item_def_id, def_id, assoc_ident): (LocalDefId, LocalDefId, Ident),
894) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
895    match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
896        Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
897            return tcx.type_param_clauses((opaque_def_id.expect_local(), def_id, assoc_ident));
898        }
899        Some(ty::ImplTraitInTraitData::Impl { .. }) => {
900            unreachable!("should not be lowering bounds on RPITIT in impl")
901        }
902        None => {}
903    }
904
905    // In the HIR, bounds can derive from two places. Either
906    // written inline like `<T: Foo>` or in a where-clause like
907    // `where T: Foo`.
908
909    let param_id = tcx.local_def_id_to_hir_id(def_id);
910    let param_owner = tcx.hir_ty_param_owner(def_id);
911
912    // Don't look for bounds where the type parameter isn't in scope.
913    let parent = if item_def_id == param_owner {
914        // FIXME: Shouldn't this be unreachable?
915        None
916    } else {
917        tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
918    };
919
920    let result = if let Some(parent) = parent {
921        let icx = ItemCtxt::new(tcx, parent);
922        icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
923    } else {
924        ty::EarlyBinder::bind_iter(&[] as &[_])
925    };
926    let mut extend = None;
927
928    let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
929
930    let hir_node = tcx.hir_node(item_hir_id);
931    let Some(hir_generics) = hir_node.generics() else {
932        return result;
933    };
934
935    if let Node::Item(item) = hir_node
936        && let hir::ItemKind::Trait { .. } = item.kind
937        // Implied `Self: Trait` and supertrait bounds.
938        && param_id == item_hir_id
939    {
940        let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id());
941        extend = Some((identity_trait_ref.upcast(tcx), item.span));
942    }
943
944    let icx = ItemCtxt::new(tcx, item_def_id);
945    let extra_clauses = extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics(
946        hir_generics,
947        def_id,
948        PredicateFilter::SelfTraitThatDefines(assoc_ident),
949    ));
950
951    let bounds =
952        &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses));
953
954    // Double check that the bounds *only* contain `SelfTy: Trait` clauses.
955    let self_ty = match tcx.def_kind(def_id) {
956        DefKind::TyParam => Ty::new_param(
957            tcx,
958            tcx.generics_of(item_def_id)
959                .param_def_id_to_index(tcx, def_id.to_def_id())
960                .expect("expected generic param to be owned by item"),
961            tcx.item_name(def_id.to_def_id()),
962        ),
963        DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param,
964        _ => unreachable!(),
965    };
966    assert_only_contains_clauses_from(
967        PredicateFilter::SelfTraitThatDefines(assoc_ident),
968        bounds,
969        self_ty,
970    );
971
972    ty::EarlyBinder::bind_iter(bounds)
973}
974
975impl<'tcx> ItemCtxt<'tcx> {
976    /// Finds bounds from `hir::Generics`.
977    ///
978    /// This requires scanning through the HIR.
979    /// We do this to avoid having to lower *all* the bounds, which would create artificial cycles.
980    /// Instead, we can only lower the bounds for a type parameter `X` if `X::Foo` is used.
981    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("probe_ty_param_bounds_in_generics",
                                    "rustc_hir_analysis::collect::clauses_of",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
                                    ::tracing_core::__macro_support::Option::Some(981u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("param_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("param_def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("filter")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("filter");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&param_def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&filter)
                                                            as &dyn ::tracing::field::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: Vec<(ty::Clause<'tcx>, Span)> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let mut bounds = Vec::new();
            if let PredicateFilter::All = filter {
                for param in hir_generics.params {
                    match param.kind {
                        hir::GenericParamKind::Type { .. } => {
                            let param_ty = self.lowerer().lower_ty_param(param.hir_id);
                            self.lowerer().add_implicit_sizedness_bounds(&mut bounds,
                                param_ty, &[],
                                ImpliedBoundsContext::TyParam(param.def_id,
                                    hir_generics.predicates), param.span);
                            self.lowerer().add_default_traits(&mut bounds, param_ty,
                                &[],
                                ImpliedBoundsContext::TyParam(param.def_id,
                                    hir_generics.predicates), param.span);
                        }
                        hir::GenericParamKind::Lifetime { .. } |
                            hir::GenericParamKind::Const { .. } => {}
                    }
                }
            }
            for predicate in hir_generics.predicates {
                let hir_id = predicate.hir_id;
                let hir::WherePredicateKind::BoundPredicate(predicate) =
                    predicate.kind else { continue; };
                match filter {
                    _ if predicate.is_param_bound(param_def_id.to_def_id()) =>
                        {}
                    PredicateFilter::All => {}
                    PredicateFilter::SelfOnly |
                        PredicateFilter::SelfTraitThatDefines(_) |
                        PredicateFilter::SelfConstIfConst |
                        PredicateFilter::SelfAndAssociatedTypeBounds => continue,
                    PredicateFilter::ConstIfConst =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
                let bound_ty =
                    self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
                let bound_vars = self.tcx.late_bound_vars(hir_id);
                self.lowerer().lower_bounds(bound_ty, predicate.bounds,
                    &mut bounds, bound_vars, filter,
                    OverlappingAsssocItemConstraints::Allowed);
            }
            bounds
        }
    }
}#[instrument(level = "trace", skip(self, hir_generics))]
982    fn probe_ty_param_bounds_in_generics(
983        &self,
984        hir_generics: &'tcx hir::Generics<'tcx>,
985        param_def_id: LocalDefId,
986        filter: PredicateFilter,
987    ) -> Vec<(ty::Clause<'tcx>, Span)> {
988        let mut bounds = Vec::new();
989
990        if let PredicateFilter::All = filter {
991            for param in hir_generics.params {
992                match param.kind {
993                    hir::GenericParamKind::Type { .. } => {
994                        let param_ty = self.lowerer().lower_ty_param(param.hir_id);
995                        self.lowerer().add_implicit_sizedness_bounds(
996                            &mut bounds,
997                            param_ty,
998                            &[],
999                            ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
1000                            param.span,
1001                        );
1002                        self.lowerer().add_default_traits(
1003                            &mut bounds,
1004                            param_ty,
1005                            &[],
1006                            ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
1007                            param.span,
1008                        );
1009                    }
1010                    hir::GenericParamKind::Lifetime { .. }
1011                    | hir::GenericParamKind::Const { .. } => {}
1012                }
1013            }
1014        }
1015
1016        for predicate in hir_generics.predicates {
1017            let hir_id = predicate.hir_id;
1018            let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
1019                continue;
1020            };
1021
1022            match filter {
1023                _ if predicate.is_param_bound(param_def_id.to_def_id()) => {
1024                    // Ok
1025                }
1026                PredicateFilter::All => {
1027                    // Ok
1028                }
1029                PredicateFilter::SelfOnly
1030                | PredicateFilter::SelfTraitThatDefines(_)
1031                | PredicateFilter::SelfConstIfConst
1032                | PredicateFilter::SelfAndAssociatedTypeBounds => continue,
1033                PredicateFilter::ConstIfConst => unreachable!(),
1034            }
1035
1036            let bound_ty = self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
1037
1038            let bound_vars = self.tcx.late_bound_vars(hir_id);
1039            self.lowerer().lower_bounds(
1040                bound_ty,
1041                predicate.bounds,
1042                &mut bounds,
1043                bound_vars,
1044                filter,
1045                OverlappingAsssocItemConstraints::Allowed,
1046            );
1047        }
1048
1049        bounds
1050    }
1051}
1052
1053pub(super) fn const_conditions<'tcx>(
1054    tcx: TyCtxt<'tcx>,
1055    def_id: LocalDefId,
1056) -> ty::ConstConditions<'tcx> {
1057    if !tcx.is_conditionally_const(def_id) {
1058        bug_impl(None,
    format_args!("const_conditions invoked for item that is not conditionally const: {0:?}",
        def_id), Location::caller());bug!("const_conditions invoked for item that is not conditionally const: {def_id:?}");
1059    }
1060
1061    match tcx.opt_rpitit_info(def_id.to_def_id()) {
1062        // RPITITs inherit const conditions of their parent fn
1063        Some(
1064            ty::ImplTraitInTraitData::Impl { fn_def_id }
1065            | ty::ImplTraitInTraitData::Trait { fn_def_id, .. },
1066        ) => return tcx.const_conditions(fn_def_id),
1067        None => {}
1068    }
1069
1070    let (generics, trait_def_id_and_supertraits, has_parent) = match tcx.hir_node_by_def_id(def_id)
1071    {
1072        Node::Item(item) => match item.kind {
1073            hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
1074            hir::ItemKind::Fn { generics, .. } => (generics, None, false),
1075            hir::ItemKind::Trait { generics, bounds: supertraits, .. } => {
1076                (generics, Some((Some(item.owner_id.def_id), supertraits)), false)
1077            }
1078            hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
1079                (generics, Some((None, supertraits)), false)
1080            }
1081            _ => bug_impl(None,
    format_args!("const_conditions called on wrong item: {0:?}", def_id),
    Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1082        },
1083        // While associated types are not really const, we do allow them to have `[const]`
1084        // bounds and where clauses. `const_conditions` is responsible for gathering
1085        // these up so we can check them in `compare_type_clause_entailment`, and
1086        // in `HostEffect` goal computation.
1087        Node::TraitItem(item) => match item.kind {
1088            hir::TraitItemKind::Fn(_, _) | hir::TraitItemKind::Type(_, _) => {
1089                (item.generics, None, true)
1090            }
1091            _ => bug_impl(None,
    format_args!("const_conditions called on wrong item: {0:?}", def_id),
    Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1092        },
1093        Node::ImplItem(item) => match item.kind {
1094            hir::ImplItemKind::Fn(_, _) | hir::ImplItemKind::Type(_) => {
1095                (item.generics, None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1096            }
1097            _ => bug_impl(None,
    format_args!("const_conditions called on wrong item: {0:?}", def_id),
    Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1098        },
1099        Node::ForeignItem(item) => match item.kind {
1100            hir::ForeignItemKind::Fn(_, _, generics) => (generics, None, false),
1101            _ => bug_impl(None,
    format_args!("const_conditions called on wrong item: {0:?}", def_id),
    Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1102        },
1103        Node::OpaqueTy(opaque) => match opaque.origin {
1104            hir::OpaqueTyOrigin::FnReturn { parent, .. } => return tcx.const_conditions(parent),
1105            hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => {
1106                ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
1107            }
1108        },
1109        // N.B. Tuple ctors are unconditionally constant.
1110        Node::Ctor(hir::VariantData::Tuple { .. }) => return Default::default(),
1111        Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_), .. }) => {
1112            (hir::Generics::empty(), None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1113        }
1114        _ => bug_impl(None,
    format_args!("const_conditions called on wrong item: {0:?}", def_id),
    Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1115    };
1116
1117    let icx = ItemCtxt::new(tcx, def_id);
1118    let mut bounds = Vec::new();
1119
1120    for pred in generics.predicates {
1121        match pred.kind {
1122            hir::WherePredicateKind::BoundPredicate(bound_pred) => {
1123                let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
1124                let bound_vars = tcx.late_bound_vars(pred.hir_id);
1125                icx.lowerer().lower_bounds(
1126                    ty,
1127                    bound_pred.bounds.iter(),
1128                    &mut bounds,
1129                    bound_vars,
1130                    PredicateFilter::ConstIfConst,
1131                    OverlappingAsssocItemConstraints::Allowed,
1132                );
1133            }
1134            _ => {}
1135        }
1136    }
1137
1138    if let Some((def_id, supertraits)) = trait_def_id_and_supertraits {
1139        if let Some(def_id) = def_id {
1140            // We've checked above that the trait is conditionally const.
1141            bounds.push((
1142                ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1143                    .to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1144                DUMMY_SP,
1145            ));
1146        }
1147
1148        icx.lowerer().lower_bounds(
1149            tcx.types.self_param,
1150            supertraits,
1151            &mut bounds,
1152            ty::List::empty(),
1153            PredicateFilter::ConstIfConst,
1154            OverlappingAsssocItemConstraints::Allowed,
1155        );
1156    }
1157
1158    ty::ConstConditions {
1159        parent: has_parent.then(|| tcx.local_parent(def_id).to_def_id()),
1160        clauses: tcx.arena.alloc_from_iter(bounds.into_iter().map(|(clause, span)| {
1161            (
1162                clause.kind().map_bound(|clause| match clause {
1163                    ty::ClauseKind::HostEffect(ty::HostEffectClause {
1164                        trait_ref,
1165                        constness: ty::BoundConstness::Maybe,
1166                    }) => trait_ref,
1167                    _ => bug_impl(None, format_args!("converted {0:?}", clause), Location::caller())bug!("converted {clause:?}"),
1168                }),
1169                span,
1170            )
1171        })),
1172    }
1173}
1174
1175pub(super) fn explicit_implied_const_bounds<'tcx>(
1176    tcx: TyCtxt<'tcx>,
1177    def_id: LocalDefId,
1178) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
1179    if !tcx.is_conditionally_const(def_id) {
1180        bug_impl(None,
    format_args!("explicit_implied_const_bounds invoked for item that is not conditionally const: {0:?}",
        def_id), Location::caller());bug!(
1181            "explicit_implied_const_bounds invoked for item that is not conditionally const: {def_id:?}"
1182        );
1183    }
1184
1185    let bounds = match tcx.opt_rpitit_info(def_id.to_def_id()) {
1186        // RPITIT's bounds are the same as opaque type bounds, but with
1187        // a projection self type.
1188        Some(ty::ImplTraitInTraitData::Trait { .. }) => {
1189            explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1190        }
1191        Some(ty::ImplTraitInTraitData::Impl { .. }) => {
1192            bug_impl(Some(tcx.def_span(def_id)),
    format_args!("RPITIT in impl should not have item bounds"),
    Location::caller())span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
1193        }
1194        None => match tcx.hir_node_by_def_id(def_id) {
1195            Node::Item(hir::Item {
1196                kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..),
1197                ..
1198            }) => implied_clauses_with_filter(
1199                tcx,
1200                def_id.to_def_id(),
1201                PredicateFilter::SelfConstIfConst,
1202            ),
1203            Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
1204            | Node::OpaqueTy(_) => {
1205                explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1206            }
1207            _ => bug_impl(None,
    format_args!("explicit_implied_const_bounds called on wrong item: {0:?}",
        def_id), Location::caller())bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
1208        },
1209    };
1210
1211    bounds.map_bound(|bounds| {
1212        &*tcx.arena.alloc_from_iter(bounds.iter().copied().map(|(clause, span)| {
1213            (
1214                clause.kind().map_bound(|clause| match clause {
1215                    ty::ClauseKind::HostEffect(ty::HostEffectClause {
1216                        trait_ref,
1217                        constness: ty::BoundConstness::Maybe,
1218                    }) => trait_ref,
1219                    _ => bug_impl(None, format_args!("converted {0:?}", clause), Location::caller())bug!("converted {clause:?}"),
1220                }),
1221                span,
1222            )
1223        }))
1224    })
1225}