Skip to main content

rustc_ty_utils/
opaque_types.rs

1use rustc_data_structures::fx::FxHashSet;
2use rustc_hir::def::DefKind;
3use rustc_hir::def_id::LocalDefId;
4use rustc_hir::intravisit;
5use rustc_hir::intravisit::Visitor;
6use rustc_middle::query::Providers;
7use rustc_middle::ty::util::{CheckRegions, NotUniqueParam};
8use rustc_middle::ty::{
9    self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Unnormalized,
10};
11use rustc_span::{Span, bug, span_bug};
12use tracing::{instrument, trace};
13
14use crate::diagnostics::{DuplicateArg, NotParam};
15
16struct OpaqueTypeCollector<'tcx> {
17    tcx: TyCtxt<'tcx>,
18    opaques: Vec<LocalDefId>,
19    /// The `DefId` of the item which we are collecting opaque types for.
20    item: LocalDefId,
21
22    /// Avoid infinite recursion due to recursive declarations.
23    seen: FxHashSet<LocalDefId>,
24
25    span: Option<Span>,
26
27    mode: CollectionMode,
28}
29
30enum CollectionMode {
31    /// For impl trait in assoc types we only permit collecting them from
32    /// associated types of the same impl block.
33    ImplTraitInAssocTypes,
34    /// When collecting for an explicit `#[define_opaque]` attribute, find all TAITs
35    Taits,
36    /// The default case, only collect RPITs and AsyncFn return types, as these are
37    /// always defined by the current item.
38    RpitAndAsyncFnOnly,
39}
40
41impl<'tcx> OpaqueTypeCollector<'tcx> {
42    fn new(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self {
43        let mode = match tcx.def_kind(item) {
44            DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => {
45                CollectionMode::ImplTraitInAssocTypes
46            }
47            DefKind::TyAlias => CollectionMode::Taits,
48            _ => CollectionMode::RpitAndAsyncFnOnly,
49        };
50        Self { tcx, opaques: Vec::new(), item, seen: Default::default(), span: None, mode }
51    }
52
53    fn span(&self) -> Span {
54        self.span.unwrap_or_else(|| {
55            self.tcx.def_ident_span(self.item).unwrap_or_else(|| self.tcx.def_span(self.item))
56        })
57    }
58
59    fn visit_spanned(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) {
60        let old = self.span;
61        self.span = Some(span);
62        value.visit_with(self);
63        self.span = old;
64    }
65
66    {}
#[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("collect_taits_declared_in_body",
                                    "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                    ::tracing_core::__macro_support::Option::Some(66u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::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,
                        &{ meta.fields().value_set_all(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let Some(body) =
                self.tcx.hir_maybe_body_owned_by(self.item) else { return; };
            let body = body.value;
            struct TaitInBodyFinder<'a, 'tcx> {
                collector: &'a mut OpaqueTypeCollector<'tcx>,
            }
            impl<'v> intravisit::Visitor<'v> for TaitInBodyFinder<'_, '_> {
                fn visit_nested_item(&mut self, id: rustc_hir::ItemId) {
                    {}

                    #[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("visit_nested_item",
                                                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(76u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                                        ::tracing_core::field::FieldSet::new(&[{
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("id")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("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(&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: () = loop {};
                                return __tracing_attr_fake_return;
                            }
                            {
                                let id = id.owner_id.def_id;
                                if let DefKind::TyAlias = self.collector.tcx.def_kind(id) {
                                    let items = self.collector.tcx.opaque_types_defined_by(id);
                                    self.collector.opaques.extend(items);
                                }
                            }
                        }
                    }
                }
                fn visit_nested_body(&mut self, id: rustc_hir::BodyId) {
                    {}

                    #[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("visit_nested_body",
                                                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(84u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                                        ::tracing_core::field::FieldSet::new(&[{
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("id")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("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(&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: () = loop {};
                                return __tracing_attr_fake_return;
                            }
                            {
                                let body = self.collector.tcx.hir_body(id);
                                self.visit_body(body);
                            }
                        }
                    }
                }
            }
            TaitInBodyFinder { collector: self }.visit_expr(body);
        }
    }
}#[instrument(level = "trace", skip(self))]
67    fn collect_taits_declared_in_body(&mut self) {
68        let Some(body) = self.tcx.hir_maybe_body_owned_by(self.item) else {
69            return;
70        };
71        let body = body.value;
72        struct TaitInBodyFinder<'a, 'tcx> {
73            collector: &'a mut OpaqueTypeCollector<'tcx>,
74        }
75        impl<'v> intravisit::Visitor<'v> for TaitInBodyFinder<'_, '_> {
76            #[instrument(level = "trace", skip(self))]
77            fn visit_nested_item(&mut self, id: rustc_hir::ItemId) {
78                let id = id.owner_id.def_id;
79                if let DefKind::TyAlias = self.collector.tcx.def_kind(id) {
80                    let items = self.collector.tcx.opaque_types_defined_by(id);
81                    self.collector.opaques.extend(items);
82                }
83            }
84            #[instrument(level = "trace", skip(self))]
85            // Recurse into these, as they are type checked with their parent
86            fn visit_nested_body(&mut self, id: rustc_hir::BodyId) {
87                let body = self.collector.tcx.hir_body(id);
88                self.visit_body(body);
89            }
90        }
91        TaitInBodyFinder { collector: self }.visit_expr(body);
92    }
93
94    {}
#[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("visit_opaque_ty",
                                    "rustc_ty_utils::opaque_types", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                    ::tracing_core::__macro_support::Option::Some(94u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("alias_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("alias_ty");
                                                        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(&alias_ty)
                                                            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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let ty::Opaque { def_id } =
                alias_ty.kind else {
                    bug_impl(None, format_args!("{0:?}", alias_ty),
                        Location::caller())
                };
            if !self.seen.insert(def_id.expect_local()) { return; }
            match self.tcx.local_opaque_ty_origin(def_id.expect_local()) {
                rustc_hir::OpaqueTyOrigin::FnReturn { .. } |
                    rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {}
                rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } =>
                    match self.mode {
                        CollectionMode::ImplTraitInAssocTypes => {
                            if !in_assoc_ty { return; }
                        }
                        CollectionMode::Taits => { if in_assoc_ty { return; } }
                        CollectionMode::RpitAndAsyncFnOnly => return,
                    },
            }
            {
                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_ty_utils/src/opaque_types.rs:127",
                                    "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                    ::tracing_core::__macro_support::Option::Some(127u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                    ::tracing_core::field::FieldSet::new(&["message",
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("alias_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("alias_ty");
                                                        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(&format_args!("adding")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&alias_ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            self.opaques.push(def_id.expect_local());
            let parent_count = self.tcx.generics_of(def_id).parent_count;
            match self.tcx.uses_unique_generic_params(&alias_ty.args[..parent_count],
                    CheckRegions::FromFunction) {
                Ok(()) => {
                    for (pred, span) in
                        self.tcx.explicit_item_bounds(def_id).iter_identity_copied().map(Unnormalized::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_ty_utils/src/opaque_types.rs:152",
                                                "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                                ::tracing_core::__macro_support::Option::Some(152u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("pred")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("pred");
                                                                    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(&pred)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        self.visit_spanned(span, pred);
                    }
                }
                Err(NotUniqueParam::NotParam(arg)) => {
                    self.tcx.dcx().emit_err(NotParam {
                            arg,
                            span: self.span(),
                            opaque_span: self.tcx.def_span(def_id),
                        });
                }
                Err(NotUniqueParam::DuplicateParam(arg)) => {
                    self.tcx.dcx().emit_err(DuplicateArg {
                            arg,
                            span: self.span(),
                            opaque_span: self.tcx.def_span(def_id),
                        });
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
95    fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) {
96        let ty::Opaque { def_id } = alias_ty.kind else { bug!("{alias_ty:?}") };
97
98        if !self.seen.insert(def_id.expect_local()) {
99            return;
100        }
101
102        // TAITs outside their defining scopes are ignored.
103        match self.tcx.local_opaque_ty_origin(def_id.expect_local()) {
104            rustc_hir::OpaqueTyOrigin::FnReturn { .. }
105            | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {}
106            rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => match self.mode {
107                // If we are collecting opaques in an assoc method, we are only looking at assoc types
108                // mentioned in the assoc method and only at opaques defined in there. We do not
109                // want to collect TAITs
110                CollectionMode::ImplTraitInAssocTypes => {
111                    if !in_assoc_ty {
112                        return;
113                    }
114                }
115                // If we are collecting opaques referenced from a `define_opaque` attribute, we
116                // do not want to look at opaques defined in associated types. Those can only be
117                // defined by methods on the same impl.
118                CollectionMode::Taits => {
119                    if in_assoc_ty {
120                        return;
121                    }
122                }
123                CollectionMode::RpitAndAsyncFnOnly => return,
124            },
125        }
126
127        trace!(?alias_ty, "adding");
128        self.opaques.push(def_id.expect_local());
129
130        let parent_count = self.tcx.generics_of(def_id).parent_count;
131        // Only check that the parent generics of the TAIT/RPIT are unique.
132        // the args owned by the opaque are going to always be duplicate
133        // lifetime params for RPITs, and empty for TAITs.
134        match self
135            .tcx
136            .uses_unique_generic_params(&alias_ty.args[..parent_count], CheckRegions::FromFunction)
137        {
138            Ok(()) => {
139                // FIXME: implement higher kinded lifetime bounds on nested opaque types. They are not
140                // supported at all, so this is sound to do, but once we want to support them, you'll
141                // start seeing the error below.
142
143                // Collect opaque types nested within the associated type bounds of this opaque type.
144                // We use identity args here, because we already know that the opaque type uses
145                // only generic parameters, and thus instantiating would not give us more information.
146                for (pred, span) in self
147                    .tcx
148                    .explicit_item_bounds(def_id)
149                    .iter_identity_copied()
150                    .map(Unnormalized::skip_norm_wip)
151                {
152                    trace!(?pred);
153                    self.visit_spanned(span, pred);
154                }
155            }
156            Err(NotUniqueParam::NotParam(arg)) => {
157                self.tcx.dcx().emit_err(NotParam {
158                    arg,
159                    span: self.span(),
160                    opaque_span: self.tcx.def_span(def_id),
161                });
162            }
163            Err(NotUniqueParam::DuplicateParam(arg)) => {
164                self.tcx.dcx().emit_err(DuplicateArg {
165                    arg,
166                    span: self.span(),
167                    opaque_span: self.tcx.def_span(def_id),
168                });
169            }
170        }
171    }
172
173    /// Checks the `#[define_opaque]` attributes on items and collects opaques to define
174    /// from the referenced types.
175    {}
#[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("collect_taits_from_defines_attr",
                                    "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                    ::tracing_core::__macro_support::Option::Some(175u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::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,
                        &{ meta.fields().value_set_all(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let hir_id = self.tcx.local_def_id_to_hir_id(self.item);
            if !hir_id.is_owner() { return; }
            let Some(defines) =
                self.tcx.hir_attr_map(hir_id.owner).define_opaque else {
                    return;
                };
            for &(span, define) in defines {
                {
                    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_ty_utils/src/opaque_types.rs:185",
                                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                        ::tracing_core::__macro_support::Option::Some(185u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                        ::tracing_core::field::FieldSet::new(&[{
                                                            const NAME:
                                                                ::tracing::__macro_support::FieldName<{
                                                                    ::tracing::__macro_support::FieldName::len("define")
                                                                }> =
                                                                ::tracing::__macro_support::FieldName::new("define");
                                                            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(&define)
                                                            as &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                let mode =
                    std::mem::replace(&mut self.mode, CollectionMode::Taits);
                let n = self.opaques.len();
                rustc_ty_walk::walk_types(self.tcx, define, self);
                if n == self.opaques.len() {
                    self.tcx.dcx().span_err(span,
                        "item does not contain any opaque types");
                }
                self.mode = mode;
            }
            self.mode = CollectionMode::RpitAndAsyncFnOnly;
        }
    }
}#[instrument(level = "trace", skip(self))]
176    fn collect_taits_from_defines_attr(&mut self) {
177        let hir_id = self.tcx.local_def_id_to_hir_id(self.item);
178        if !hir_id.is_owner() {
179            return;
180        }
181        let Some(defines) = self.tcx.hir_attr_map(hir_id.owner).define_opaque else {
182            return;
183        };
184        for &(span, define) in defines {
185            trace!(?define);
186            let mode = std::mem::replace(&mut self.mode, CollectionMode::Taits);
187            let n = self.opaques.len();
188            rustc_ty_walk::walk_types(self.tcx, define, self);
189            if n == self.opaques.len() {
190                self.tcx.dcx().span_err(span, "item does not contain any opaque types");
191            }
192            self.mode = mode;
193        }
194        // Allow using `#[define_opaque]` on assoc methods and type aliases to override the default collection mode in
195        // case it was capturing too much.
196        self.mode = CollectionMode::RpitAndAsyncFnOnly;
197    }
198}
199
200impl<'tcx> rustc_ty_walk::SpannedTypeVisitor<'tcx> for OpaqueTypeCollector<'tcx> {
201    {}
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("visit",
                                "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                ::tracing_core::__macro_support::Option::Some(201u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("span")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("span");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("value")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("value");
                                                    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(&span)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
                                                        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: () = loop {};
                        return __tracing_attr_fake_return;
                    }
                    { self.visit_spanned(span, value); }
                })();
{
    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_ty_utils/src/opaque_types.rs:201",
                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                        ::tracing_core::__macro_support::Option::Some(201u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                        ::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(skip(self), ret, level = "trace")]
202    fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) {
203        self.visit_spanned(span, value);
204    }
205}
206
207impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
208    {}
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("visit_ty",
                                "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                ::tracing_core::__macro_support::Option::Some(208u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("t")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("t");
                                                    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(&t)
                                                        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: () = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        t.super_visit_with(self);
                        match *t.kind() {
                            ty::Alias(_, alias_ty @ ty::AliasTy {
                                kind: ty::Opaque { def_id }, .. }) if def_id.is_local() => {
                                self.visit_opaque_ty(alias_ty);
                            }
                            ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args,
                                .. }) if let Some(def_id) = def_id.as_local() => {
                                if !self.seen.insert(def_id) { return; }
                                self.tcx.type_of(def_id).instantiate(self.tcx,
                                            args).skip_norm_wip().visit_with(self);
                            }
                            ty::Alias(_, alias_ty @ ty::AliasTy {
                                kind: ty::Projection { def_id: alias_def_id }, .. }) => {
                                if let Some(parent) =
                                        self.tcx.trait_impl_of_assoc(self.item.to_def_id()) {
                                    let impl_trait_ref =
                                        self.tcx.impl_trait_ref(parent).instantiate_identity().skip_norm_wip();
                                    if alias_ty.trait_ref(self.tcx) == impl_trait_ref {
                                        for &assoc in
                                            self.tcx.associated_items(parent).in_definition_order() {
                                            {
                                                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_ty_utils/src/opaque_types.rs:246",
                                                                    "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                                                    ::tracing_core::__macro_support::Option::Some(246u32),
                                                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                                                    ::tracing_core::field::FieldSet::new(&[{
                                                                                        const NAME:
                                                                                            ::tracing::__macro_support::FieldName<{
                                                                                                ::tracing::__macro_support::FieldName::len("assoc")
                                                                                            }> =
                                                                                            ::tracing::__macro_support::FieldName::new("assoc");
                                                                                        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(&assoc)
                                                                                        as &dyn ::tracing::field::Value))])
                                                        });
                                                } else { ; }
                                            };
                                            if assoc.expect_trait_impl() != Ok(alias_def_id) {
                                                continue;
                                            }
                                            if !assoc.defaultness(self.tcx).is_final() { continue; }
                                            if !self.seen.insert(assoc.def_id.expect_local()) {
                                                return;
                                            }
                                            let alias_args =
                                                alias_ty.args.rebase_onto(self.tcx, impl_trait_ref.def_id,
                                                    ty::GenericArgs::identity_for_item(self.tcx, parent));
                                            if self.tcx.check_args_compatible(assoc.def_id, alias_args)
                                                {
                                                self.tcx.type_of(assoc.def_id).instantiate(self.tcx,
                                                            alias_args).skip_norm_wip().visit_with(self);
                                                return;
                                            } else {
                                                self.tcx.dcx().span_delayed_bug(self.tcx.def_span(assoc.def_id),
                                                    "item had incorrect args");
                                            }
                                        }
                                    }
                                } else if let Some(ty::ImplTraitInTraitData::Trait {
                                            fn_def_id, .. }) = self.tcx.opt_rpitit_info(alias_def_id) &&
                                        fn_def_id == self.item.into() {
                                    let ty =
                                        self.tcx.type_of(alias_def_id).instantiate(self.tcx,
                                                alias_ty.args).skip_norm_wip();
                                    let ty::Alias(_, alias_ty @ ty::AliasTy {
                                            kind: ty::Opaque { .. }, .. }) =
                                        *ty.kind() else {
                                            bug_impl(None, format_args!("{0:?}", ty),
                                                Location::caller())
                                        };
                                    self.visit_opaque_ty(alias_ty);
                                }
                            }
                            _ => {
                                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_ty_utils/src/opaque_types.rs:310",
                                                    "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(310u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                                                    ::tracing_core::field::FieldSet::new(&[{
                                                                        const NAME:
                                                                            ::tracing::__macro_support::FieldName<{
                                                                                ::tracing::__macro_support::FieldName::len("kind")
                                                                            }> =
                                                                            ::tracing::__macro_support::FieldName::new("kind");
                                                                        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(&t.kind())
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            }
                        }
                    }
                })();
{
    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_ty_utils/src/opaque_types.rs:208",
                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                        ::tracing_core::__macro_support::Option::Some(208u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                        ::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(skip(self), ret, level = "trace")]
209    fn visit_ty(&mut self, t: Ty<'tcx>) {
210        t.super_visit_with(self);
211        match *t.kind() {
212            ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Opaque { def_id }, .. })
213                if def_id.is_local() =>
214            {
215                self.visit_opaque_ty(alias_ty);
216            }
217            // Skips type aliases, as they are meant to be transparent.
218            // FIXME(type_alias_impl_trait): can we require mentioning nested type aliases explicitly?
219            ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. })
220                if let Some(def_id) = def_id.as_local() =>
221            {
222                if !self.seen.insert(def_id) {
223                    return;
224                }
225                self.tcx
226                    .type_of(def_id)
227                    .instantiate(self.tcx, args)
228                    .skip_norm_wip()
229                    .visit_with(self);
230            }
231            ty::Alias(
232                _,
233                alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_def_id }, .. },
234            ) => {
235                // This avoids having to do normalization of `Self::AssocTy` by only
236                // supporting the case of a method defining opaque types from assoc types
237                // in the same impl block.
238                if let Some(parent) = self.tcx.trait_impl_of_assoc(self.item.to_def_id()) {
239                    let impl_trait_ref =
240                        self.tcx.impl_trait_ref(parent).instantiate_identity().skip_norm_wip();
241                    // If the trait ref of the associated item and the impl differs,
242                    // then we can't use the impl's identity args below, so
243                    // just skip.
244                    if alias_ty.trait_ref(self.tcx) == impl_trait_ref {
245                        for &assoc in self.tcx.associated_items(parent).in_definition_order() {
246                            trace!(?assoc);
247                            if assoc.expect_trait_impl() != Ok(alias_def_id) {
248                                continue;
249                            }
250
251                            // If the type is further specializable, then the type_of
252                            // is not actually correct below.
253                            if !assoc.defaultness(self.tcx).is_final() {
254                                continue;
255                            }
256
257                            if !self.seen.insert(assoc.def_id.expect_local()) {
258                                return;
259                            }
260
261                            let alias_args = alias_ty.args.rebase_onto(
262                                self.tcx,
263                                impl_trait_ref.def_id,
264                                ty::GenericArgs::identity_for_item(self.tcx, parent),
265                            );
266
267                            if self.tcx.check_args_compatible(assoc.def_id, alias_args) {
268                                self.tcx
269                                    .type_of(assoc.def_id)
270                                    .instantiate(self.tcx, alias_args)
271                                    .skip_norm_wip()
272                                    .visit_with(self);
273                                return;
274                            } else {
275                                self.tcx.dcx().span_delayed_bug(
276                                    self.tcx.def_span(assoc.def_id),
277                                    "item had incorrect args",
278                                );
279                            }
280                        }
281                    }
282                } else if let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
283                    self.tcx.opt_rpitit_info(alias_def_id)
284                    && fn_def_id == self.item.into()
285                {
286                    // RPITIT in trait definitions get desugared to an associated type. For
287                    // default methods we also create an opaque type this associated type
288                    // normalizes to. The associated type is only known to normalize to the
289                    // opaque if it is fully concrete. There could otherwise be an impl
290                    // overwriting the default method.
291                    //
292                    // However, we have to be able to normalize the associated type while inside
293                    // of the default method. This is normally handled by adding an unchecked
294                    // `Projection(<Self as Trait>::synthetic_assoc_ty, trait_def::opaque)`
295                    // assumption to the `param_env` of the default method. We also separately
296                    // rely on that assumption here.
297                    let ty = self
298                        .tcx
299                        .type_of(alias_def_id)
300                        .instantiate(self.tcx, alias_ty.args)
301                        .skip_norm_wip();
302                    let ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
303                        *ty.kind()
304                    else {
305                        bug!("{ty:?}")
306                    };
307                    self.visit_opaque_ty(alias_ty);
308                }
309            }
310            _ => trace!(kind=?t.kind()),
311        }
312    }
313}
314
315fn opaque_types_defined_by<'tcx>(
316    tcx: TyCtxt<'tcx>,
317    item: LocalDefId,
318) -> &'tcx ty::List<LocalDefId> {
319    // Closures and coroutines are type checked with their parent
320    // Note that we also support `SyntheticCoroutineBody` since we create
321    // a MIR body for the def kind, and some MIR passes (like promotion)
322    // may require doing analysis using its typing env.
323    if tcx.is_typeck_child(item.to_def_id()) {
324        return tcx.opaque_types_defined_by(tcx.local_parent(item));
325    }
326    let kind = tcx.def_kind(item);
327    {
    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_ty_utils/src/opaque_types.rs:327",
                        "rustc_ty_utils::opaque_types", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/opaque_types.rs"),
                        ::tracing_core::__macro_support::Option::Some(327u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::opaque_types"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("kind")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("kind");
                                            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(&kind)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!(?kind);
328    let mut collector = OpaqueTypeCollector::new(tcx, item);
329    collector.collect_taits_from_defines_attr();
330    rustc_ty_walk::walk_types(tcx, item, &mut collector);
331
332    match kind {
333        DefKind::AssocFn
334        | DefKind::Fn
335        | DefKind::Static { .. }
336        | DefKind::Const
337        | DefKind::AssocConst
338        | DefKind::AnonConst => {
339            // Non-type-system inline consts should be caught by `if tcx.is_typeck_child` above
340            if true {
    if !(kind != DefKind::AnonConst ||
                tcx.anon_const_kind(item) !=
                    ty::AnonConstKind::NonTypeSystemInline) {
        ::core::panicking::panic("assertion failed: kind != DefKind::AnonConst ||\n    tcx.anon_const_kind(item) != ty::AnonConstKind::NonTypeSystemInline")
    };
};debug_assert!(
341                kind != DefKind::AnonConst
342                    || tcx.anon_const_kind(item) != ty::AnonConstKind::NonTypeSystemInline
343            );
344
345            collector.collect_taits_declared_in_body();
346        }
347        DefKind::AssocTy | DefKind::TyAlias | DefKind::GlobalAsm => {}
348        DefKind::OpaqueTy
349        | DefKind::Mod
350        | DefKind::Struct
351        | DefKind::Union
352        | DefKind::Enum
353        | DefKind::Variant
354        | DefKind::Trait
355        | DefKind::ForeignTy
356        | DefKind::TraitAlias
357        | DefKind::Closure
358        | DefKind::SyntheticCoroutineBody
359        | DefKind::TyParam
360        | DefKind::ConstParam
361        | DefKind::Ctor(_, _)
362        | DefKind::Macro(_)
363        | DefKind::ExternCrate
364        | DefKind::Use
365        | DefKind::ForeignMod
366        | DefKind::Field
367        | DefKind::LifetimeParam
368        | DefKind::Impl { .. }
369        | DefKind::TestBinderConstraints => {
370            bug_impl(Some(tcx.def_span(item)),
    format_args!("`opaque_types_defined_by` not defined for {0} `{1:?}`",
        kind.descr(item.to_def_id()), item), Location::caller());span_bug!(
371                tcx.def_span(item),
372                "`opaque_types_defined_by` not defined for {} `{item:?}`",
373                kind.descr(item.to_def_id())
374            );
375        }
376    }
377    tcx.mk_local_def_ids(&collector.opaques)
378}
379
380pub(super) fn provide(providers: &mut Providers) {
381    *providers = Providers { opaque_types_defined_by, ..*providers };
382}