Skip to main content

rustc_ty_utils/
needs_drop.rs

1//! Check whether a type has (potentially) non-trivial drop glue.
2
3use rustc_attr_ir::find_attr;
4use rustc_data_structures::fx::FxHashSet;
5use rustc_hir::def_id::DefId;
6use rustc_middle::query::Providers;
7use rustc_middle::ty::util::{AlwaysRequiresDrop, needs_drop_components};
8use rustc_middle::ty::{self, EarlyBinder, GenericArgs, Ty, TyCtxt, Unnormalized};
9use rustc_span::bug;
10use rustc_structures::Limit;
11use tracing::{debug, instrument};
12
13use crate::diagnostics::NeedsDropOverflow;
14
15type NeedsDropResult<T> = Result<T, AlwaysRequiresDrop>;
16
17fn needs_drop_raw<'tcx>(
18    tcx: TyCtxt<'tcx>,
19    query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
20) -> bool {
21    // If we don't know a type doesn't need drop, for example if it's a type
22    // parameter without a `Copy` bound, then we conservatively return that it
23    // needs drop.
24    let adt_has_dtor =
25        |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
26    let res = drop_tys_helper(
27        tcx,
28        query.value,
29        query.typing_env,
30        adt_has_dtor,
31        DropTysOptions::default(),
32    )
33    .filter(filter_array_elements(tcx, query.typing_env))
34    .next()
35    .is_some();
36
37    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:37",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(37u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("needs_drop_raw({0:?}) = {1:?}",
                                                    query, res) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("needs_drop_raw({:?}) = {:?}", query, res);
38    res
39}
40
41fn needs_async_drop_raw<'tcx>(
42    tcx: TyCtxt<'tcx>,
43    query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
44) -> bool {
45    // If we don't know a type doesn't need async drop, for example if it's a
46    // type parameter without a `Copy` bound, then we conservatively return that
47    // it needs async drop.
48    let adt_has_async_dtor =
49        |adt_def: ty::AdtDef<'tcx>| adt_def.async_destructor(tcx).map(|_| DtorType::Significant);
50    let res = drop_tys_helper(
51        tcx,
52        query.value,
53        query.typing_env,
54        adt_has_async_dtor,
55        DropTysOptions::default().recurse_into_box_for_async_drop(),
56    )
57    .filter(filter_array_elements_async(tcx, query.typing_env))
58    .next()
59    .is_some();
60
61    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:61",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(61u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("needs_async_drop_raw({0:?}) = {1:?}",
                                                    query, res) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("needs_async_drop_raw({:?}) = {:?}", query, res);
62    res
63}
64
65/// HACK: in order to not mistakenly assume that `[PhantomData<T>; N]` requires drop glue
66/// we check the element type for drop glue. The correct fix would be looking at the
67/// entirety of the code around `needs_drop_components` and this file and come up with
68/// logic that is easier to follow while not repeating any checks that may thus diverge.
69fn filter_array_elements<'tcx>(
70    tcx: TyCtxt<'tcx>,
71    typing_env: ty::TypingEnv<'tcx>,
72) -> impl Fn(&Result<Ty<'tcx>, AlwaysRequiresDrop>) -> bool {
73    move |ty| match ty {
74        Ok(ty) => match *ty.kind() {
75            ty::Array(elem, _) => tcx.needs_drop_raw(typing_env.as_query_input(elem)),
76            _ => true,
77        },
78        Err(AlwaysRequiresDrop) => true,
79    }
80}
81fn filter_array_elements_async<'tcx>(
82    tcx: TyCtxt<'tcx>,
83    typing_env: ty::TypingEnv<'tcx>,
84) -> impl Fn(&Result<Ty<'tcx>, AlwaysRequiresDrop>) -> bool {
85    move |ty| match ty {
86        Ok(ty) => match *ty.kind() {
87            ty::Array(elem, _) => tcx.needs_async_drop_raw(typing_env.as_query_input(elem)),
88            _ => true,
89        },
90        Err(AlwaysRequiresDrop) => true,
91    }
92}
93
94fn has_significant_drop_raw<'tcx>(
95    tcx: TyCtxt<'tcx>,
96    query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
97) -> bool {
98    let res = drop_tys_helper(
99        tcx,
100        query.value,
101        query.typing_env,
102        adt_consider_insignificant_dtor(tcx),
103        DropTysOptions::default().only_significant(),
104    )
105    .filter(filter_array_elements(tcx, query.typing_env))
106    .next()
107    .is_some();
108    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:108",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(108u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("has_significant_drop_raw({0:?}) = {1:?}",
                                                    query, res) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("has_significant_drop_raw({:?}) = {:?}", query, res);
109    res
110}
111
112struct NeedsDropTypes<'tcx, F> {
113    tcx: TyCtxt<'tcx>,
114    typing_env: ty::TypingEnv<'tcx>,
115    query_ty: Ty<'tcx>,
116    seen_tys: FxHashSet<Ty<'tcx>>,
117    /// A stack of types left to process, and the recursion depth when we
118    /// pushed that type. Each round, we pop something from the stack and check
119    /// if it needs drop. If the result depends on whether some other types
120    /// need drop we push them onto the stack.
121    unchecked_tys: Vec<(Ty<'tcx>, usize)>,
122    recursion_limit: Limit,
123    adt_components: F,
124    /// Set this to true if an exhaustive list of types involved in
125    /// drop obligation is requested.
126    // FIXME: Calling this bool `exhaustive` is confusing and possibly a footgun,
127    // since it does two things: It makes the iterator yield *all* of the types
128    // that need drop, and it also affects the computation of the drop components
129    // on `Coroutine`s. The latter is somewhat confusing, and probably should be
130    // a function of `typing_env`. See the HACK comment below for why this is
131    // necessary. If this isn't possible, then we probably should turn this into
132    // a `NeedsDropMode` so that we can have a variant like `CollectAllSignificantDrops`,
133    // which will more accurately indicate that we want *all* of the *significant*
134    // drops, which are the two important behavioral changes toggled by this bool.
135    exhaustive: bool,
136}
137
138impl<'tcx, F> NeedsDropTypes<'tcx, F> {
139    fn new(
140        tcx: TyCtxt<'tcx>,
141        typing_env: ty::TypingEnv<'tcx>,
142        ty: Ty<'tcx>,
143        exhaustive: bool,
144        adt_components: F,
145    ) -> Self {
146        let mut seen_tys = FxHashSet::default();
147        seen_tys.insert(ty);
148        Self {
149            tcx,
150            typing_env,
151            seen_tys,
152            query_ty: ty,
153            unchecked_tys: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [(ty, 0)]))vec![(ty, 0)],
154            recursion_limit: tcx.recursion_limit(),
155            adt_components,
156            exhaustive,
157        }
158    }
159
160    /// Called when `ty` is found to always require drop.
161    /// If the exhaustive flag is true, then `Ok(ty)` is returned like any other type.
162    /// Otherwise, `Err(AlwaysRequireDrop)` is returned, which will cause iteration to abort.
163    fn always_drop_component(&self, ty: Ty<'tcx>) -> NeedsDropResult<Ty<'tcx>> {
164        if self.exhaustive { Ok(ty) } else { Err(AlwaysRequiresDrop) }
165    }
166}
167
168impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F>
169where
170    F: Fn(ty::AdtDef<'tcx>, GenericArgs<'tcx>) -> NeedsDropResult<I>,
171    I: Iterator<Item = Ty<'tcx>>,
172{
173    type Item = NeedsDropResult<Ty<'tcx>>;
174
175    {}
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("next",
                                "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                ::tracing_core::__macro_support::Option::Some(175u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{ meta.fields().value_set_all(&[]) })
            } 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:
                                Option<NeedsDropResult<Ty<'tcx>>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx;
                        while let Some((ty, level)) = self.unchecked_tys.pop() {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:180",
                                                    "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(180u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                                    ::tracing_core::field::FieldSet::new(&["message",
                                                                    {
                                                                        const NAME:
                                                                            ::tracing::__macro_support::FieldName<{
                                                                                ::tracing::__macro_support::FieldName::len("ty")
                                                                            }> =
                                                                            ::tracing::__macro_support::FieldName::new("ty");
                                                                        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(&format_args!("needs_drop_components: inspect")
                                                                        as &dyn ::tracing::field::Value)),
                                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            if !self.recursion_limit.value_within_limit(level) {
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:184",
                                                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(184u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                                        ::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!("needs_drop_components: recursion limit exceeded")
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                tcx.dcx().emit_err(NeedsDropOverflow {
                                        query_ty: self.query_ty,
                                    });
                                return Some(self.always_drop_component(ty));
                            }
                            let components =
                                match needs_drop_components(tcx, ty) {
                                    Err(AlwaysRequiresDrop) =>
                                        return Some(self.always_drop_component(ty)),
                                    Ok(components) => components,
                                };
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:193",
                                                    "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(193u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                                    ::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!("needs_drop_components({0:?}) = {1:?}",
                                                                                ty, components) as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            let queue_type =
                                move |this: &mut Self, component: Ty<'tcx>|
                                    {
                                        if this.seen_tys.insert(component) {
                                            this.unchecked_tys.push((component, level + 1));
                                        }
                                    };
                            for component in components {
                                match *component.kind() {
                                    ty::Coroutine(def_id, args) => {
                                        if self.exhaustive {
                                            for upvar in args.as_coroutine().upvar_tys() {
                                                queue_type(self, upvar);
                                            }
                                            queue_type(self, args.as_coroutine().resume_ty());
                                            if let Some(witness) = tcx.mir_coroutine_witnesses(def_id) {
                                                for field_ty in &witness.field_tys {
                                                    queue_type(self,
                                                        EarlyBinder::bind(tcx,
                                                                    field_ty.ty).instantiate(tcx, args).skip_norm_wip());
                                                }
                                            }
                                        } else { return Some(self.always_drop_component(ty)); }
                                    }
                                    ty::CoroutineWitness(..) => {
                                        {
                                            ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                                    format_args!("witness should be handled in parent")));
                                        };
                                    }
                                    ty::UnsafeBinder(bound_ty) => {
                                        let ty =
                                            self.tcx.instantiate_bound_regions_with_erased(bound_ty.into());
                                        queue_type(self, ty);
                                    }
                                    _ if
                                        tcx.type_is_copy_modulo_regions(self.typing_env, component)
                                        => {}
                                    ty::Closure(_, args) => {
                                        for upvar in args.as_closure().upvar_tys() {
                                            queue_type(self, upvar);
                                        }
                                    }
                                    ty::CoroutineClosure(_, args) => {
                                        for upvar in args.as_coroutine_closure().upvar_tys() {
                                            queue_type(self, upvar);
                                        }
                                    }
                                    ty::Adt(adt_def, args) => {
                                        let tys =
                                            match (self.adt_components)(adt_def, args) {
                                                Err(AlwaysRequiresDrop) => {
                                                    return Some(self.always_drop_component(ty));
                                                }
                                                Ok(tys) => tys,
                                            };
                                        for required_ty in tys {
                                            let required =
                                                tcx.try_normalize_erasing_regions(self.typing_env,
                                                        Unnormalized::new_wip(required_ty)).unwrap_or(required_ty);
                                            queue_type(self, required);
                                        }
                                    }
                                    ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) |
                                        ty::Param(_) => {
                                        if ty == component {
                                            return Some(Ok(component));
                                        } else { queue_type(self, component); }
                                    }
                                    ty::Foreign(_) | ty::Dynamic(..) => {
                                        {
                                            use ::tracing::__macro_support::Callsite as _;
                                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                {
                                                    static META: ::tracing::Metadata<'static> =
                                                        {
                                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:293",
                                                                "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                                                ::tracing_core::__macro_support::Option::Some(293u32),
                                                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                                                ::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!("needs_drop_components: foreign or dynamic")
                                                                                    as &dyn ::tracing::field::Value))])
                                                    });
                                            } else { ; }
                                        };
                                        return Some(self.always_drop_component(ty));
                                    }
                                    ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) |
                                        ty::Float(_) | ty::Str | ty::Slice(_) | ty::Ref(..) |
                                        ty::RawPtr(..) | ty::FnDef(..) | ty::Pat(..) | ty::FnPtr(..)
                                        | ty::Tuple(_) | ty::Bound(..) | ty::Never | ty::Infer(_) |
                                        ty::Error(_) => {
                                        ::rustc_span::macros::bug_impl(None,
                                            format_args!("unexpected type returned by `needs_drop_components`: {0}",
                                                component), Location::caller())
                                    }
                                    ty::View(..) =>
                                        ::core::panicking::unimplemented_default_msg(),
                                }
                            }
                        }
                        None
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:175",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(175u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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(self), ret)]
176    fn next(&mut self) -> Option<NeedsDropResult<Ty<'tcx>>> {
177        let tcx = self.tcx;
178
179        while let Some((ty, level)) = self.unchecked_tys.pop() {
180            debug!(?ty, "needs_drop_components: inspect");
181            if !self.recursion_limit.value_within_limit(level) {
182                // Not having a `Span` isn't great. But there's hopefully some other
183                // recursion limit error as well.
184                debug!("needs_drop_components: recursion limit exceeded");
185                tcx.dcx().emit_err(NeedsDropOverflow { query_ty: self.query_ty });
186                return Some(self.always_drop_component(ty));
187            }
188
189            let components = match needs_drop_components(tcx, ty) {
190                Err(AlwaysRequiresDrop) => return Some(self.always_drop_component(ty)),
191                Ok(components) => components,
192            };
193            debug!("needs_drop_components({:?}) = {:?}", ty, components);
194
195            let queue_type = move |this: &mut Self, component: Ty<'tcx>| {
196                if this.seen_tys.insert(component) {
197                    this.unchecked_tys.push((component, level + 1));
198                }
199            };
200
201            for component in components {
202                match *component.kind() {
203                    // The information required to determine whether a coroutine has drop is
204                    // computed on MIR, while this very method is used to build MIR.
205                    // To avoid cycles, we consider that coroutines always require drop.
206                    //
207                    // HACK: Because we erase regions contained in the coroutine witness, we
208                    // have to conservatively assume that every region captured by the
209                    // coroutine has to be live when dropped. This results in a lot of
210                    // undesirable borrowck errors. During borrowck, we call `needs_drop`
211                    // for the coroutine witness and check whether any of the contained types
212                    // need to be dropped, and only require the captured types to be live
213                    // if they do.
214                    ty::Coroutine(def_id, args) => {
215                        // FIXME: See FIXME on `exhaustive` field above.
216                        if self.exhaustive {
217                            for upvar in args.as_coroutine().upvar_tys() {
218                                queue_type(self, upvar);
219                            }
220                            queue_type(self, args.as_coroutine().resume_ty());
221                            if let Some(witness) = tcx.mir_coroutine_witnesses(def_id) {
222                                for field_ty in &witness.field_tys {
223                                    queue_type(
224                                        self,
225                                        EarlyBinder::bind(tcx, field_ty.ty)
226                                            .instantiate(tcx, args)
227                                            .skip_norm_wip(),
228                                    );
229                                }
230                            }
231                        } else {
232                            return Some(self.always_drop_component(ty));
233                        }
234                    }
235                    ty::CoroutineWitness(..) => {
236                        unreachable!("witness should be handled in parent");
237                    }
238
239                    ty::UnsafeBinder(bound_ty) => {
240                        let ty = self.tcx.instantiate_bound_regions_with_erased(bound_ty.into());
241                        queue_type(self, ty);
242                    }
243
244                    _ if tcx.type_is_copy_modulo_regions(self.typing_env, component) => {}
245
246                    ty::Closure(_, args) => {
247                        for upvar in args.as_closure().upvar_tys() {
248                            queue_type(self, upvar);
249                        }
250                    }
251
252                    ty::CoroutineClosure(_, args) => {
253                        for upvar in args.as_coroutine_closure().upvar_tys() {
254                            queue_type(self, upvar);
255                        }
256                    }
257
258                    // Check for a `Drop` impl and whether this is a union or
259                    // `ManuallyDrop`. If it's a struct or enum without a `Drop`
260                    // impl then check whether the field types need `Drop`.
261                    ty::Adt(adt_def, args) => {
262                        let tys = match (self.adt_components)(adt_def, args) {
263                            Err(AlwaysRequiresDrop) => {
264                                return Some(self.always_drop_component(ty));
265                            }
266                            Ok(tys) => tys,
267                        };
268                        for required_ty in tys {
269                            let required = tcx
270                                .try_normalize_erasing_regions(
271                                    self.typing_env,
272                                    Unnormalized::new_wip(required_ty),
273                                )
274                                .unwrap_or(required_ty);
275
276                            queue_type(self, required);
277                        }
278                    }
279                    ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => {
280                        if ty == component {
281                            // Return the type to the caller: they may be able
282                            // to normalize further than we can.
283                            return Some(Ok(component));
284                        } else {
285                            // Store the type for later. We can't return here
286                            // because we would then lose any other components
287                            // of the type.
288                            queue_type(self, component);
289                        }
290                    }
291
292                    ty::Foreign(_) | ty::Dynamic(..) => {
293                        debug!("needs_drop_components: foreign or dynamic");
294                        return Some(self.always_drop_component(ty));
295                    }
296
297                    ty::Bool
298                    | ty::Char
299                    | ty::Int(_)
300                    | ty::Uint(_)
301                    | ty::Float(_)
302                    | ty::Str
303                    | ty::Slice(_)
304                    | ty::Ref(..)
305                    | ty::RawPtr(..)
306                    | ty::FnDef(..)
307                    | ty::Pat(..)
308                    | ty::FnPtr(..)
309                    | ty::Tuple(_)
310                    | ty::Bound(..)
311                    | ty::Never
312                    | ty::Infer(_)
313                    | ty::Error(_) => {
314                        bug!("unexpected type returned by `needs_drop_components`: {component}")
315                    }
316
317                    // FIXME(scrabsha)
318                    ty::View(..) => unimplemented!(),
319                }
320            }
321        }
322
323        None
324    }
325}
326
327enum DtorType {
328    /// Type has a `Drop` but it is considered insignificant.
329    /// Check the query `adt_significant_drop_tys` for understanding
330    /// "significant" / "insignificant".
331    Insignificant,
332
333    /// Type has a `Drop` implantation.
334    Significant,
335}
336
337#[derive(#[automatically_derived]impl ::core::marker::Copy for DropTysOptions { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for DropTysOptions {
}
#[automatically_derived]impl ::core::clone::Clone for DropTysOptions {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]impl ::core::default::Default for DropTysOptions {
    #[inline]
    fn default() -> Self {
        DropTysOptions {
            only_significant: ::core::default::Default::default(),
            exhaustive: ::core::default::Default::default(),
            async_drop_recurses_into_box: ::core::default::Default::default(),
        }
    }
}Default)]
338struct DropTysOptions {
339    only_significant: bool,
340    exhaustive: bool,
341    async_drop_recurses_into_box: bool,
342}
343
344impl DropTysOptions {
345    fn only_significant(mut self) -> Self {
346        self.only_significant = true;
347        self
348    }
349
350    fn exhaustive(mut self) -> Self {
351        self.exhaustive = true;
352        self
353    }
354
355    fn recurse_into_box_for_async_drop(mut self) -> Self {
356        self.async_drop_recurses_into_box = true;
357        self
358    }
359}
360
361// This is a helper function for `adt_drop_tys` and `adt_significant_drop_tys`.
362// Depending on the implantation of `adt_has_dtor`, it is used to check if the
363// ADT has a destructor or if the ADT only has a significant destructor. For
364// understanding significant destructor look at `adt_significant_drop_tys`.
365fn drop_tys_helper<'tcx>(
366    tcx: TyCtxt<'tcx>,
367    ty: Ty<'tcx>,
368    typing_env: ty::TypingEnv<'tcx>,
369    adt_has_dtor: impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType>,
370    options: DropTysOptions,
371) -> impl Iterator<Item = NeedsDropResult<Ty<'tcx>>> {
372    fn with_query_cache<'tcx>(
373        tcx: TyCtxt<'tcx>,
374        iter: impl IntoIterator<Item = Ty<'tcx>>,
375    ) -> NeedsDropResult<Vec<Ty<'tcx>>> {
376        iter.into_iter().try_fold(Vec::new(), |mut vec, subty| {
377            match subty.kind() {
378                ty::Adt(adt_id, args) => {
379                    for subty in tcx.adt_drop_tys(adt_id.did())? {
380                        vec.push(
381                            EarlyBinder::bind(tcx, subty).instantiate(tcx, args).skip_norm_wip(),
382                        );
383                    }
384                }
385                _ => vec.push(subty),
386            };
387            Ok(vec)
388        })
389    }
390
391    let adt_components = move |adt_def: ty::AdtDef<'tcx>, args: GenericArgs<'tcx>| {
392        if adt_def.is_manually_drop() {
393            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:393",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(393u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("drop_tys_helper: `{0:?}` is manually drop",
                                                    adt_def) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("drop_tys_helper: `{:?}` is manually drop", adt_def);
394            Ok(Vec::new())
395        } else if options.async_drop_recurses_into_box && adt_def.is_box() {
396            let box_components = match args.as_slice() {
397                [boxed_ty, allocator_ty] => {
398                    let boxed_ty = boxed_ty.expect_ty();
399                    let allocator_ty = allocator_ty.expect_ty();
400                    match boxed_ty.kind() {
401                        // FIXME(async_drop): boxed dyn pointees are deliberately skipped here
402                        // because async drop glue does not yet dispatch through dyn metadata.
403                        // Once that is supported, this should include the boxed pointee too.
404                        ty::Dynamic(..) | ty::Error(_) => ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [allocator_ty]))vec![allocator_ty],
405                        _ => ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [boxed_ty, allocator_ty]))vec![boxed_ty, allocator_ty],
406                    }
407                }
408                _ => {
409                    ::rustc_span::macros::bug_impl(None,
    format_args!("drop_tys_helper: `Box` has unexpected generic args: {0:?}",
        args), Location::caller());bug!("drop_tys_helper: `Box` has unexpected generic args: {args:?}");
410                }
411            };
412            Ok(box_components)
413        } else if let Some(dtor_info) = adt_has_dtor(adt_def) {
414            match dtor_info {
415                DtorType::Significant => {
416                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:416",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(416u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("drop_tys_helper: `{0:?}` implements `Drop`",
                                                    adt_def) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("drop_tys_helper: `{:?}` implements `Drop`", adt_def);
417                    Err(AlwaysRequiresDrop)
418                }
419                DtorType::Insignificant => {
420                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:420",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(420u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("drop_tys_helper: `{0:?}` drop is insignificant",
                                                    adt_def) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("drop_tys_helper: `{:?}` drop is insignificant", adt_def);
421
422                    // Since the destructor is insignificant, we just want to make sure all of
423                    // the passed in type parameters are also insignificant.
424                    // Eg: Vec<T> dtor is insignificant when T=i32 but significant when T=Mutex.
425                    Ok(args.types().collect())
426                }
427            }
428        } else if adt_def.is_union() {
429            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:429",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(429u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("drop_tys_helper: `{0:?}` is a union",
                                                    adt_def) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("drop_tys_helper: `{:?}` is a union", adt_def);
430            Ok(Vec::new())
431        } else {
432            let field_tys = adt_def.all_fields().map(|field| {
433                let r = tcx.type_of(field.did).instantiate(tcx, args).skip_norm_wip();
434                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:434",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(434u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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!("drop_tys_helper: Instantiate into {0:?} with {1:?} getting {2:?}",
                                                    field, args, r) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
435                    "drop_tys_helper: Instantiate into {:?} with {:?} getting {:?}",
436                    field, args, r
437                );
438                r
439            });
440            if options.only_significant {
441                // We can't recurse through the query system here because we might induce a cycle
442                Ok(field_tys.collect())
443            } else {
444                // We can use the query system if we consider all drops significant. In that case,
445                // ADTs are `needs_drop` exactly if they `impl Drop` or if any of their "transitive"
446                // fields do. There can be no cycles here, because ADTs cannot contain themselves as
447                // fields.
448                with_query_cache(tcx, field_tys)
449            }
450        }
451        .map(|v| v.into_iter())
452    };
453
454    NeedsDropTypes::new(tcx, typing_env, ty, options.exhaustive, adt_components)
455}
456
457fn adt_consider_insignificant_dtor<'tcx>(
458    tcx: TyCtxt<'tcx>,
459) -> impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType> {
460    move |adt_def: ty::AdtDef<'tcx>| {
461        if {
        {
            'done:
                {
                for i in
                    ::rustc_attr_ir::HasAttrs::get_attrs(adt_def.did(), &tcx) {
                    #[allow(unused_imports)]
                    use ::rustc_attr_ir::AttributeKind::*;
                    let i: &::rustc_attr_ir::Attribute = i;
                    match i {
                        ::rustc_attr_ir::Attribute::Parsed(RustcInsignificantDtor)
                            => {
                            break 'done Some(());
                        }
                        ::rustc_attr_ir::Attribute::Tool { .. } |
                            ::rustc_attr_ir::Attribute::DeriveHelper(..) =>
                            {}
                            #[deny(unreachable_patterns)]
                            _ => {}
                    }
                }
                None
            }
        }
    }.is_some()find_attr!(tcx, adt_def.did(), RustcInsignificantDtor) {
462            // In some cases like `std::collections::HashMap` where the struct is a wrapper around
463            // a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies
464            // outside stdlib, we might choose to still annotate the wrapper (std HashMap) with
465            // `rustc_insignificant_dtor`, even if the type itself doesn't have a `Drop` impl.
466            Some(DtorType::Insignificant)
467        } else if adt_def.destructor(tcx).is_some() {
468            // There is a Drop impl and the type isn't marked insignificant, therefore Drop must be
469            // significant.
470            Some(DtorType::Significant)
471        } else {
472            // No destructor found nor the type is annotated with `rustc_insignificant_dtor`, we
473            // treat this as the simple case of Drop impl for type.
474            None
475        }
476    }
477}
478
479fn adt_drop_tys<'tcx>(
480    tcx: TyCtxt<'tcx>,
481    def_id: DefId,
482) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
483    // This is for the "adt_drop_tys" query, that considers all `Drop` impls, therefore all dtors are
484    // significant.
485    let adt_has_dtor =
486        |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
487    // `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_args)`
488    drop_tys_helper(
489        tcx,
490        tcx.type_of(def_id).instantiate_identity().skip_norm_wip(),
491        ty::TypingEnv::non_body_analysis(tcx, def_id),
492        adt_has_dtor,
493        DropTysOptions::default(),
494    )
495    .collect::<Result<Vec<_>, _>>()
496    .map(|components| tcx.mk_type_list(&components))
497}
498
499fn adt_async_drop_tys<'tcx>(
500    tcx: TyCtxt<'tcx>,
501    def_id: DefId,
502) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
503    // This is for the "adt_async_drop_tys" query, that considers all `AsyncDrop` impls.
504    let adt_has_dtor =
505        |adt_def: ty::AdtDef<'tcx>| adt_def.async_destructor(tcx).map(|_| DtorType::Significant);
506    // `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_args)`
507    drop_tys_helper(
508        tcx,
509        tcx.type_of(def_id).instantiate_identity().skip_norm_wip(),
510        ty::TypingEnv::non_body_analysis(tcx, def_id),
511        adt_has_dtor,
512        DropTysOptions::default().recurse_into_box_for_async_drop(),
513    )
514    .collect::<Result<Vec<_>, _>>()
515    .map(|components| tcx.mk_type_list(&components))
516}
517
518// If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed
519// a `tcx.make_ty(def, identity_args)` and as such it is legal to instantiate the generic parameters
520// of the ADT into the outputted `ty`s.
521fn adt_significant_drop_tys(
522    tcx: TyCtxt<'_>,
523    def_id: DefId,
524) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
525    drop_tys_helper(
526        tcx,
527        tcx.type_of(def_id).instantiate_identity().skip_norm_wip(), // identical to `tcx.make_adt(def, identity_args)`
528        ty::TypingEnv::non_body_analysis(tcx, def_id),
529        adt_consider_insignificant_dtor(tcx),
530        DropTysOptions::default().only_significant(),
531    )
532    .collect::<Result<Vec<_>, _>>()
533    .map(|components| tcx.mk_type_list(&components))
534}
535
536{}
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("list_significant_drop_tys",
                                "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                                ::tracing_core::__macro_support::Option::Some(536u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("key")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("key");
                                                    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(&key)
                                                        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: &'tcx ty::List<Ty<'tcx>> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        tcx.mk_type_list(&drop_tys_helper(tcx, key.value,
                                            key.typing_env, adt_consider_insignificant_dtor(tcx),
                                            DropTysOptions::default().only_significant().exhaustive()).filter_map(|res|
                                            res.ok()).collect::<Vec<_>>())
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs:536",
                        "rustc_ty_utils::needs_drop", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/137d1d49458b73b7b85d2c1599d8730886d65e47/compiler/rustc_ty_utils/src/needs_drop.rs"),
                        ::tracing_core::__macro_support::Option::Some(536u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ty_utils::needs_drop"),
                        ::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), ret)]
537fn list_significant_drop_tys<'tcx>(
538    tcx: TyCtxt<'tcx>,
539    key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
540) -> &'tcx ty::List<Ty<'tcx>> {
541    tcx.mk_type_list(
542        &drop_tys_helper(
543            tcx,
544            key.value,
545            key.typing_env,
546            adt_consider_insignificant_dtor(tcx),
547            DropTysOptions::default().only_significant().exhaustive(),
548        )
549        .filter_map(|res| res.ok())
550        .collect::<Vec<_>>(),
551    )
552}
553
554pub(crate) fn provide(providers: &mut Providers) {
555    *providers = Providers {
556        needs_drop_raw,
557        needs_async_drop_raw,
558        has_significant_drop_raw,
559        adt_drop_tys,
560        adt_async_drop_tys,
561        adt_significant_drop_tys,
562        list_significant_drop_tys,
563        ..*providers
564    };
565}