Skip to main content

rustc_middle/ty/
instance.rs

1use std::{assert_matches, fmt};
2
3use rustc_data_structures::fx::FxHashMap;
4use rustc_errors::ErrorGuaranteed;
5use rustc_hir as hir;
6use rustc_hir::attrs::lang_items::LangItem;
7use rustc_hir::def::{CtorKind, DefKind, Namespace};
8use rustc_hir::def_id::{CrateNum, DefId};
9use rustc_macros::{Lift, StableHash, TyDecodable, TyEncodable};
10use rustc_span::def_id::LOCAL_CRATE;
11use rustc_span::{DUMMY_SP, Span};
12use tracing::{debug, instrument};
13
14use crate::diagnostics;
15use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
16use crate::ty::normalize_erasing_regions::NormalizationError;
17use crate::ty::print::{FmtPrinter, Print};
18use crate::ty::{
19    self, AssocContainer, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable,
20    TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
21};
22
23/// An `InstanceKind` along with the args that are needed to substitute the instance.
24///
25/// Monomorphization happens on-the-fly and no monomorphized MIR is ever created. Instead, this type
26/// simply couples a potentially generic `InstanceKind` with some args, and codegen and const eval
27/// will do all required instantiations as they run.
28///
29/// Note: the `Lift` impl is currently not used by rustc, but is used by
30/// rustc_codegen_cranelift when the `jit` feature is enabled.
31#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for Instance<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for Instance<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for Instance<'tcx> {
    #[inline]
    fn clone(&self) -> Instance<'tcx> {
        let _: ::core::clone::AssertParamIsClone<InstanceKind<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<GenericArgsRef<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for Instance<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for Instance<'tcx> {
    #[inline]
    fn eq(&self, other: &Instance<'tcx>) -> bool {
        self.def == other.def && self.args == other.args
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for Instance<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<InstanceKind<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<GenericArgsRef<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for Instance<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.def, state);
        ::core::hash::Hash::hash(&self.args, state)
    }
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Instance<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "Instance",
            "def", &self.def, "args", &&self.args)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for Instance<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let Instance { def: ref __binding_0, args: ref __binding_1 } =
                    *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for Instance<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                Instance {
                    def: ::rustc_serialize::Decodable::decode(__decoder),
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };TyDecodable)]
32#[derive(const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            Instance<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    Instance { def: ref __binding_0, args: ref __binding_1 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<'tcx, '__lifted>
            ::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
            for Instance<'tcx> {
            type Lifted = Instance<'__lifted>;
            fn lift_to_interner(self,
                __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
                -> Instance<'__lifted> {
                match self {
                    Instance { def: __binding_0, args: __binding_1 } => {
                        Instance {
                            def: __tcx.lift(__binding_0),
                            args: __tcx.lift(__binding_1),
                        }
                    }
                }
            }
        }
    };Lift, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for Instance<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        Instance { def: __binding_0, args: __binding_1 } => {
                            Instance {
                                def: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                args: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    Instance { def: __binding_0, args: __binding_1 } => {
                        Instance {
                            def: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            args: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for Instance<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    Instance { def: ref __binding_0, args: ref __binding_1 } =>
                        {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
33pub struct Instance<'tcx> {
34    pub def: InstanceKind<'tcx>,
35    pub args: GenericArgsRef<'tcx>,
36}
37
38/// Describes why a `ReifyShim` was created. This is needed to distinguish a ReifyShim created to
39/// adjust for things like `#[track_caller]` in a vtable from a `ReifyShim` created to produce a
40/// function pointer from a vtable entry.
41/// Currently, this is only used when KCFI is enabled, as only KCFI needs to treat those two
42/// `ReifyShim`s differently.
43#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReifyReason { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ReifyReason { }
#[automatically_derived]
impl ::core::clone::Clone for ReifyReason {
    #[inline]
    fn clone(&self) -> ReifyReason { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ReifyReason { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ReifyReason {
    #[inline]
    fn eq(&self, other: &ReifyReason) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ReifyReason {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for ReifyReason {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for ReifyReason {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ReifyReason::FnPtr => "FnPtr",
                ReifyReason::Vtable => "Vtable",
            })
    }
}Debug)]
44#[derive(const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for ReifyReason {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        ReifyReason::FnPtr => { 0usize }
                        ReifyReason::Vtable => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for ReifyReason {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { ReifyReason::FnPtr }
                    1usize => { ReifyReason::Vtable }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ReifyReason`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for ReifyReason
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    ReifyReason::FnPtr => {}
                    ReifyReason::Vtable => {}
                }
            }
        }
    };StableHash)]
45pub enum ReifyReason {
46    /// The `ReifyShim` was created to produce a function pointer. This happens when:
47    /// * A vtable entry is directly converted to a function call (e.g. creating a fn ptr from a
48    ///   method on a `dyn` object).
49    /// * A function with `#[track_caller]` is converted to a function pointer
50    /// * If KCFI is enabled, creating a function pointer from a method on a dyn-compatible trait.
51    /// This includes the case of converting `::call`-like methods on closure-likes to function
52    /// pointers.
53    FnPtr,
54    /// This `ReifyShim` was created to populate a vtable. Currently, this happens when a
55    /// `#[track_caller]` mismatch occurs between the implementation of a method and the method.
56    /// This includes the case of `::call`-like methods in closure-likes' vtables.
57    Vtable,
58}
59
60#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for InstanceKind<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for InstanceKind<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for InstanceKind<'tcx> {
    #[inline]
    fn clone(&self) -> InstanceKind<'tcx> {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<usize>;
        let _: ::core::clone::AssertParamIsClone<ShimKind<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for InstanceKind<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for InstanceKind<'tcx> {
    #[inline]
    fn eq(&self, other: &InstanceKind<'tcx>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (InstanceKind::Item(__self_0), InstanceKind::Item(__arg1_0))
                    => __self_0 == __arg1_0,
                (InstanceKind::Intrinsic(__self_0),
                    InstanceKind::Intrinsic(__arg1_0)) => __self_0 == __arg1_0,
                (InstanceKind::LlvmIntrinsic(__self_0),
                    InstanceKind::LlvmIntrinsic(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (InstanceKind::Virtual(__self_0, __self_1),
                    InstanceKind::Virtual(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InstanceKind::Shim(__self_0), InstanceKind::Shim(__arg1_0))
                    => __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for InstanceKind<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DefId>;
        let _: ::core::cmp::AssertParamIsEq<usize>;
        let _: ::core::cmp::AssertParamIsEq<ShimKind<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for InstanceKind<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            InstanceKind::Item(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InstanceKind::Intrinsic(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InstanceKind::LlvmIntrinsic(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InstanceKind::Virtual(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            InstanceKind::Shim(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
        }
    }
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for InstanceKind<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            InstanceKind::Item(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Item",
                    &__self_0),
            InstanceKind::Intrinsic(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Intrinsic", &__self_0),
            InstanceKind::LlvmIntrinsic(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "LlvmIntrinsic", &__self_0),
            InstanceKind::Virtual(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "Virtual", __self_0, &__self_1),
            InstanceKind::Shim(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Shim",
                    &__self_0),
        }
    }
}Debug)]
61#[derive(const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for InstanceKind<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        InstanceKind::Item(ref __binding_0) => { 0usize }
                        InstanceKind::Intrinsic(ref __binding_0) => { 1usize }
                        InstanceKind::LlvmIntrinsic(ref __binding_0) => { 2usize }
                        InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
                            3usize
                        }
                        InstanceKind::Shim(ref __binding_0) => { 4usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    InstanceKind::Item(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InstanceKind::Intrinsic(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InstanceKind::LlvmIntrinsic(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    InstanceKind::Shim(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for InstanceKind<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        InstanceKind::Item(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        InstanceKind::Intrinsic(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        InstanceKind::LlvmIntrinsic(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => {
                        InstanceKind::Virtual(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        InstanceKind::Shim(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InstanceKind`, expected 0..5, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            InstanceKind<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    InstanceKind::Item(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    InstanceKind::Intrinsic(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    InstanceKind::LlvmIntrinsic(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    InstanceKind::Shim(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for InstanceKind<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        InstanceKind::Item(__binding_0) => {
                            InstanceKind::Item(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        InstanceKind::Intrinsic(__binding_0) => {
                            InstanceKind::Intrinsic(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        InstanceKind::LlvmIntrinsic(__binding_0) => {
                            InstanceKind::LlvmIntrinsic(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        InstanceKind::Virtual(__binding_0, __binding_1) => {
                            InstanceKind::Virtual(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        InstanceKind::Shim(__binding_0) => {
                            InstanceKind::Shim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    InstanceKind::Item(__binding_0) => {
                        InstanceKind::Item(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    InstanceKind::Intrinsic(__binding_0) => {
                        InstanceKind::Intrinsic(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    InstanceKind::LlvmIntrinsic(__binding_0) => {
                        InstanceKind::LlvmIntrinsic(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    InstanceKind::Virtual(__binding_0, __binding_1) => {
                        InstanceKind::Virtual(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    InstanceKind::Shim(__binding_0) => {
                        InstanceKind::Shim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for InstanceKind<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    InstanceKind::Item(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    InstanceKind::Intrinsic(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    InstanceKind::LlvmIntrinsic(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    InstanceKind::Shim(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable, const _: () =
    {
        impl<'tcx, '__lifted>
            ::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
            for InstanceKind<'tcx> {
            type Lifted = InstanceKind<'__lifted>;
            fn lift_to_interner(self,
                __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
                -> InstanceKind<'__lifted> {
                match self {
                    InstanceKind::Item(__binding_0) => {
                        InstanceKind::Item(__tcx.lift(__binding_0))
                    }
                    InstanceKind::Intrinsic(__binding_0) => {
                        InstanceKind::Intrinsic(__tcx.lift(__binding_0))
                    }
                    InstanceKind::LlvmIntrinsic(__binding_0) => {
                        InstanceKind::LlvmIntrinsic(__tcx.lift(__binding_0))
                    }
                    InstanceKind::Virtual(__binding_0, __binding_1) => {
                        InstanceKind::Virtual(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    InstanceKind::Shim(__binding_0) => {
                        InstanceKind::Shim(__tcx.lift(__binding_0))
                    }
                }
            }
        }
    };Lift)]
62pub enum InstanceKind<'tcx> {
63    /// A user-defined callable item.
64    ///
65    /// This includes:
66    /// - `fn` items
67    /// - closures
68    /// - coroutines
69    Item(DefId),
70
71    /// An intrinsic `fn` item (with`#[rustc_intrinsic]`).
72    ///
73    /// Alongside `LlvmIntrinsic` and `Virtual`, this is the only `InstanceKind`
74    /// that does not have its own callable MIR. Instead, codegen and const eval
75    /// "magically" evaluate calls to intrinsics purely in the caller.
76    Intrinsic(DefId),
77
78    /// An LLVM intrinsic `fn` item (with `extern "llvm-intrinsic"`).
79    ///
80    /// Alongside `Intrinsic` and `Virtual`, this is the only `InstanceKind`
81    /// that does not have its own callable MIR. Instead, codegen and const eval
82    /// "magically" evaluate calls to LLVM intrinsics purely in the caller.
83    LlvmIntrinsic(DefId),
84
85    /// Dynamic dispatch to `<dyn Trait as Trait>::fn`.
86    ///
87    /// This `InstanceKind` may have a callable MIR as the default implementation.
88    /// Calls to `Virtual` instances must be codegen'd as virtual calls through the vtable.
89    /// *This means we might not know exactly what is being called.*
90    ///
91    /// If this is reified to a `fn` pointer, a `ReifyShim` is used (see `ReifyShim` above for more
92    /// details on that).
93    Virtual(DefId, usize),
94
95    Shim(ShimKind<'tcx>),
96}
97
98#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ShimKind<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ShimKind<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ShimKind<'tcx> {
    #[inline]
    fn clone(&self) -> ShimKind<'tcx> {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<Option<ReifyReason>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Option<Ty<'tcx>>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for ShimKind<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ShimKind<'tcx> {
    #[inline]
    fn eq(&self, other: &ShimKind<'tcx>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (ShimKind::VTable(__self_0), ShimKind::VTable(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (ShimKind::Reify(__self_0, __self_1),
                    ShimKind::Reify(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::FnPtr(__self_0, __self_1),
                    ShimKind::FnPtr(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::ClosureOnce {
                    call_once: __self_0,
                    closure: __self_1,
                    track_caller: __self_2 }, ShimKind::ClosureOnce {
                    call_once: __arg1_0,
                    closure: __arg1_1,
                    track_caller: __arg1_2 }) =>
                    __self_2 == __arg1_2 && __self_0 == __arg1_0 &&
                        __self_1 == __arg1_1,
                (ShimKind::ConstructCoroutineInClosure {
                    coroutine_closure_def_id: __self_0,
                    receiver_by_ref: __self_1 },
                    ShimKind::ConstructCoroutineInClosure {
                    coroutine_closure_def_id: __arg1_0,
                    receiver_by_ref: __arg1_1 }) =>
                    __self_1 == __arg1_1 && __self_0 == __arg1_0,
                (ShimKind::ThreadLocal(__self_0),
                    ShimKind::ThreadLocal(__arg1_0)) => __self_0 == __arg1_0,
                (ShimKind::FutureDropPoll(__self_0, __self_1, __self_2),
                    ShimKind::FutureDropPoll(__arg1_0, __arg1_1, __arg1_2)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                (ShimKind::DropGlue(__self_0, __self_1),
                    ShimKind::DropGlue(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::Clone(__self_0, __self_1),
                    ShimKind::Clone(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::FnPtrAsPtr(__self_0, __self_1),
                    ShimKind::FnPtrAsPtr(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::FnPtrFromPtr(__self_0, __self_1),
                    ShimKind::FnPtrFromPtr(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::AsyncDropGlueCtor(__self_0, __self_1),
                    ShimKind::AsyncDropGlueCtor(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ShimKind::AsyncDropGlue(__self_0, __self_1),
                    ShimKind::AsyncDropGlue(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ShimKind<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DefId>;
        let _: ::core::cmp::AssertParamIsEq<Option<ReifyReason>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for ShimKind<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            ShimKind::VTable(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            ShimKind::Reify(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::FnPtr(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::ClosureOnce {
                call_once: __self_0, closure: __self_1, track_caller: __self_2
                } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            ShimKind::ConstructCoroutineInClosure {
                coroutine_closure_def_id: __self_0, receiver_by_ref: __self_1
                } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::ThreadLocal(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            ShimKind::FutureDropPoll(__self_0, __self_1, __self_2) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            ShimKind::DropGlue(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::Clone(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::FnPtrAsPtr(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::FnPtrFromPtr(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::AsyncDropGlueCtor(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            ShimKind::AsyncDropGlue(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
        }
    }
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ShimKind<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            ShimKind::VTable(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "VTable",
                    &__self_0),
            ShimKind::Reify(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Reify",
                    __self_0, &__self_1),
            ShimKind::FnPtr(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "FnPtr",
                    __self_0, &__self_1),
            ShimKind::ClosureOnce {
                call_once: __self_0, closure: __self_1, track_caller: __self_2
                } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f,
                    "ClosureOnce", "call_once", __self_0, "closure", __self_1,
                    "track_caller", &__self_2),
            ShimKind::ConstructCoroutineInClosure {
                coroutine_closure_def_id: __self_0, receiver_by_ref: __self_1
                } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "ConstructCoroutineInClosure", "coroutine_closure_def_id",
                    __self_0, "receiver_by_ref", &__self_1),
            ShimKind::ThreadLocal(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ThreadLocal", &__self_0),
            ShimKind::FutureDropPoll(__self_0, __self_1, __self_2) =>
                ::core::fmt::Formatter::debug_tuple_field3_finish(f,
                    "FutureDropPoll", __self_0, __self_1, &__self_2),
            ShimKind::DropGlue(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "DropGlue", __self_0, &__self_1),
            ShimKind::Clone(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Clone",
                    __self_0, &__self_1),
            ShimKind::FnPtrAsPtr(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "FnPtrAsPtr", __self_0, &__self_1),
            ShimKind::FnPtrFromPtr(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "FnPtrFromPtr", __self_0, &__self_1),
            ShimKind::AsyncDropGlueCtor(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "AsyncDropGlueCtor", __self_0, &__self_1),
            ShimKind::AsyncDropGlue(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "AsyncDropGlue", __self_0, &__self_1),
        }
    }
}Debug)]
99#[derive(const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for ShimKind<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        ShimKind::VTable(ref __binding_0) => { 0usize }
                        ShimKind::Reify(ref __binding_0, ref __binding_1) => {
                            1usize
                        }
                        ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
                            2usize
                        }
                        ShimKind::ClosureOnce {
                            call_once: ref __binding_0,
                            closure: ref __binding_1,
                            track_caller: ref __binding_2 } => {
                            3usize
                        }
                        ShimKind::ConstructCoroutineInClosure {
                            coroutine_closure_def_id: ref __binding_0,
                            receiver_by_ref: ref __binding_1 } => {
                            4usize
                        }
                        ShimKind::ThreadLocal(ref __binding_0) => { 5usize }
                        ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
                            ref __binding_2) => {
                            6usize
                        }
                        ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
                            7usize
                        }
                        ShimKind::Clone(ref __binding_0, ref __binding_1) => {
                            8usize
                        }
                        ShimKind::FnPtrAsPtr(ref __binding_0, ref __binding_1) => {
                            9usize
                        }
                        ShimKind::FnPtrFromPtr(ref __binding_0, ref __binding_1) =>
                            {
                            10usize
                        }
                        ShimKind::AsyncDropGlueCtor(ref __binding_0,
                            ref __binding_1) => {
                            11usize
                        }
                        ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
                            {
                            12usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    ShimKind::VTable(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    ShimKind::Reify(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::ClosureOnce {
                        call_once: ref __binding_0,
                        closure: ref __binding_1,
                        track_caller: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    ShimKind::ConstructCoroutineInClosure {
                        coroutine_closure_def_id: ref __binding_0,
                        receiver_by_ref: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::ThreadLocal(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
                        ref __binding_2) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::Clone(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::FnPtrAsPtr(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::FnPtrFromPtr(ref __binding_0, ref __binding_1) =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::AsyncDropGlueCtor(ref __binding_0,
                        ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for ShimKind<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        ShimKind::VTable(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        ShimKind::Reify(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        ShimKind::FnPtr(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => {
                        ShimKind::ClosureOnce {
                            call_once: ::rustc_serialize::Decodable::decode(__decoder),
                            closure: ::rustc_serialize::Decodable::decode(__decoder),
                            track_caller: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    4usize => {
                        ShimKind::ConstructCoroutineInClosure {
                            coroutine_closure_def_id: ::rustc_serialize::Decodable::decode(__decoder),
                            receiver_by_ref: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    5usize => {
                        ShimKind::ThreadLocal(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    6usize => {
                        ShimKind::FutureDropPoll(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    7usize => {
                        ShimKind::DropGlue(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    8usize => {
                        ShimKind::Clone(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    9usize => {
                        ShimKind::FnPtrAsPtr(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    10usize => {
                        ShimKind::FnPtrFromPtr(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    11usize => {
                        ShimKind::AsyncDropGlueCtor(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    12usize => {
                        ShimKind::AsyncDropGlue(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ShimKind`, expected 0..13, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            ShimKind<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    ShimKind::VTable(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::Reify(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::ClosureOnce {
                        call_once: ref __binding_0,
                        closure: ref __binding_1,
                        track_caller: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::ConstructCoroutineInClosure {
                        coroutine_closure_def_id: ref __binding_0,
                        receiver_by_ref: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::ThreadLocal(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
                        ref __binding_2) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::Clone(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::FnPtrAsPtr(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::FnPtrFromPtr(ref __binding_0, ref __binding_1) =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::AsyncDropGlueCtor(ref __binding_0,
                        ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for ShimKind<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        ShimKind::VTable(__binding_0) => {
                            ShimKind::VTable(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        ShimKind::Reify(__binding_0, __binding_1) => {
                            ShimKind::Reify(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::FnPtr(__binding_0, __binding_1) => {
                            ShimKind::FnPtr(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::ClosureOnce {
                            call_once: __binding_0,
                            closure: __binding_1,
                            track_caller: __binding_2 } => {
                            ShimKind::ClosureOnce {
                                call_once: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                closure: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                track_caller: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                        ShimKind::ConstructCoroutineInClosure {
                            coroutine_closure_def_id: __binding_0,
                            receiver_by_ref: __binding_1 } => {
                            ShimKind::ConstructCoroutineInClosure {
                                coroutine_closure_def_id: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                receiver_by_ref: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                        ShimKind::ThreadLocal(__binding_0) => {
                            ShimKind::ThreadLocal(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        ShimKind::FutureDropPoll(__binding_0, __binding_1,
                            __binding_2) => {
                            ShimKind::FutureDropPoll(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?)
                        }
                        ShimKind::DropGlue(__binding_0, __binding_1) => {
                            ShimKind::DropGlue(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::Clone(__binding_0, __binding_1) => {
                            ShimKind::Clone(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::FnPtrAsPtr(__binding_0, __binding_1) => {
                            ShimKind::FnPtrAsPtr(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::FnPtrFromPtr(__binding_0, __binding_1) => {
                            ShimKind::FnPtrFromPtr(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
                            ShimKind::AsyncDropGlueCtor(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                        ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
                            ShimKind::AsyncDropGlue(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    ShimKind::VTable(__binding_0) => {
                        ShimKind::VTable(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    ShimKind::Reify(__binding_0, __binding_1) => {
                        ShimKind::Reify(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::FnPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtr(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::ClosureOnce {
                        call_once: __binding_0,
                        closure: __binding_1,
                        track_caller: __binding_2 } => {
                        ShimKind::ClosureOnce {
                            call_once: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            closure: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            track_caller: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                    ShimKind::ConstructCoroutineInClosure {
                        coroutine_closure_def_id: __binding_0,
                        receiver_by_ref: __binding_1 } => {
                        ShimKind::ConstructCoroutineInClosure {
                            coroutine_closure_def_id: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            receiver_by_ref: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                    ShimKind::ThreadLocal(__binding_0) => {
                        ShimKind::ThreadLocal(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    ShimKind::FutureDropPoll(__binding_0, __binding_1,
                        __binding_2) => {
                        ShimKind::FutureDropPoll(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
                                __folder))
                    }
                    ShimKind::DropGlue(__binding_0, __binding_1) => {
                        ShimKind::DropGlue(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::Clone(__binding_0, __binding_1) => {
                        ShimKind::Clone(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::FnPtrAsPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtrAsPtr(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::FnPtrFromPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtrFromPtr(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
                        ShimKind::AsyncDropGlueCtor(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                    ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
                        ShimKind::AsyncDropGlue(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for ShimKind<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ShimKind::VTable(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::Reify(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::ClosureOnce {
                        call_once: ref __binding_0,
                        closure: ref __binding_1,
                        track_caller: ref __binding_2 } => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::ConstructCoroutineInClosure {
                        coroutine_closure_def_id: ref __binding_0,
                        receiver_by_ref: ref __binding_1 } => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::ThreadLocal(ref __binding_0) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
                        ref __binding_2) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::Clone(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::FnPtrAsPtr(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::FnPtrFromPtr(ref __binding_0, ref __binding_1) =>
                        {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::AsyncDropGlueCtor(ref __binding_0,
                        ref __binding_1) => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                    ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
                        {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable, const _: () =
    {
        impl<'tcx, '__lifted>
            ::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
            for ShimKind<'tcx> {
            type Lifted = ShimKind<'__lifted>;
            fn lift_to_interner(self,
                __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
                -> ShimKind<'__lifted> {
                match self {
                    ShimKind::VTable(__binding_0) => {
                        ShimKind::VTable(__tcx.lift(__binding_0))
                    }
                    ShimKind::Reify(__binding_0, __binding_1) => {
                        ShimKind::Reify(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::FnPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtr(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::ClosureOnce {
                        call_once: __binding_0,
                        closure: __binding_1,
                        track_caller: __binding_2 } => {
                        ShimKind::ClosureOnce {
                            call_once: __tcx.lift(__binding_0),
                            closure: __tcx.lift(__binding_1),
                            track_caller: __tcx.lift(__binding_2),
                        }
                    }
                    ShimKind::ConstructCoroutineInClosure {
                        coroutine_closure_def_id: __binding_0,
                        receiver_by_ref: __binding_1 } => {
                        ShimKind::ConstructCoroutineInClosure {
                            coroutine_closure_def_id: __tcx.lift(__binding_0),
                            receiver_by_ref: __tcx.lift(__binding_1),
                        }
                    }
                    ShimKind::ThreadLocal(__binding_0) => {
                        ShimKind::ThreadLocal(__tcx.lift(__binding_0))
                    }
                    ShimKind::FutureDropPoll(__binding_0, __binding_1,
                        __binding_2) => {
                        ShimKind::FutureDropPoll(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1), __tcx.lift(__binding_2))
                    }
                    ShimKind::DropGlue(__binding_0, __binding_1) => {
                        ShimKind::DropGlue(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::Clone(__binding_0, __binding_1) => {
                        ShimKind::Clone(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::FnPtrAsPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtrAsPtr(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::FnPtrFromPtr(__binding_0, __binding_1) => {
                        ShimKind::FnPtrFromPtr(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
                        ShimKind::AsyncDropGlueCtor(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                    ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
                        ShimKind::AsyncDropGlue(__tcx.lift(__binding_0),
                            __tcx.lift(__binding_1))
                    }
                }
            }
        }
    };Lift)]
100pub enum ShimKind<'tcx> {
101    /// `<T as Trait>::method` where `method` receives unsizeable `self: Self` (part of the
102    /// `unsized_fn_params` feature).
103    ///
104    /// The generated shim will take `Self` via `*mut Self` - conceptually this is `&owned Self` -
105    /// and dereference the argument to call the original function.
106    VTable(DefId),
107
108    /// `fn()` pointer where the function itself cannot be turned into a pointer.
109    ///
110    /// One example is `<dyn Trait as Trait>::fn`, where the shim contains
111    /// a virtual call, which codegen supports only via a direct call to the
112    /// `<dyn Trait as Trait>::fn` instance (an `InstanceKind::Virtual`).
113    ///
114    /// Another example is functions annotated with `#[track_caller]`, which
115    /// must have their implicit caller location argument populated for a call.
116    /// Because this is a required part of the function's ABI but can't be tracked
117    /// as a property of the function pointer, we use a single "caller location"
118    /// (the definition of the function itself).
119    ///
120    /// The second field encodes *why* this shim was created. This allows distinguishing between
121    /// a `ReifyShim` that appears in a vtable vs one that appears as a function pointer.
122    ///
123    /// This field will only be populated if we are compiling in a mode that needs these shims
124    /// to be separable, currently only when KCFI is enabled.
125    Reify(DefId, Option<ReifyReason>),
126
127    /// `<fn() as FnTrait>::call_*` (generated `FnTrait` implementation for `fn()` pointers).
128    ///
129    /// `DefId` is `FnTrait::call_*`.
130    FnPtr(DefId, Ty<'tcx>),
131
132    /// `<[FnMut/Fn closure] as FnOnce>::call_once`.
133    ///
134    /// The `DefId` is the ID of the `call_once` method in `FnOnce`.
135    ///
136    /// This generates a body that will just borrow the (owned) self type,
137    /// and dispatch to the `FnMut::call_mut` instance for the closure.
138    ClosureOnce { call_once: DefId, closure: DefId, track_caller: bool },
139
140    /// `<[FnMut/Fn coroutine-closure] as FnOnce>::call_once`
141    ///
142    /// The body generated here differs significantly from the `ClosureOnceShim`,
143    /// since we need to generate a distinct coroutine type that will move the
144    /// closure's upvars *out* of the closure.
145    ConstructCoroutineInClosure {
146        coroutine_closure_def_id: DefId,
147        // Whether the generated MIR body takes the coroutine by-ref. This is
148        // because the signature of `<{async fn} as FnMut>::call_mut` is:
149        // `fn(&mut self, args: A) -> <Self as FnOnce>::Output`, that is to say
150        // that it returns the `FnOnce`-flavored coroutine but takes the closure
151        // by mut ref (and similarly for `Fn::call`).
152        receiver_by_ref: bool,
153    },
154
155    /// Compiler-generated accessor for thread locals which returns a reference to the thread local
156    /// the `DefId` defines. This is used to export thread locals from dylibs on platforms lacking
157    /// native support.
158    ThreadLocal(DefId),
159
160    /// Proxy shim for async drop of future (def_id, proxy_cor_ty, impl_cor_ty)
161    FutureDropPoll(DefId, Ty<'tcx>, Ty<'tcx>),
162
163    /// `core::ptr::drop_glue::<T>`.
164    ///
165    /// The `DefId` is for `core::ptr::drop_glue`.
166    /// The `Option<Ty<'tcx>>` is either `Some(T)`, or `None` for empty drop glue.
167    ///
168    /// The type must be monomorphic; for polymorphic drop glue use
169    /// `rustc_mir_transform::build_drop_shim`.
170    DropGlue(DefId, Option<Ty<'tcx>>),
171
172    /// Compiler-generated `<T as Clone>::clone` implementation.
173    ///
174    /// For all types that automatically implement `Copy`, a trivial `Clone` impl is provided too.
175    /// Additionally, arrays, tuples, and closures get a `Clone` shim even if they aren't `Copy`.
176    ///
177    /// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl.
178    Clone(DefId, Ty<'tcx>),
179
180    /// Compiler-generated `<T as FnPtr>::as_ptr` implementation.
181    ///
182    /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types.
183    ///
184    /// The `DefId` is for `FnPtr::as_ptr`, the `Ty` is the type `T`.
185    FnPtrAsPtr(DefId, Ty<'tcx>),
186
187    /// Compiler-generated `<T as FnPtr>::from_ptr` implementation.
188    ///
189    /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types.
190    ///
191    /// The `DefId` is for `FnPtr::from_ptr`, the `Ty` is the type `T`.
192    FnPtrFromPtr(DefId, Ty<'tcx>),
193
194    /// `core::future::async_drop::async_drop_in_place::<'_, T>`.
195    ///
196    /// The `DefId` is for `core::future::async_drop::async_drop_in_place`, the `Ty`
197    /// is the type `T`.
198    AsyncDropGlueCtor(DefId, Ty<'tcx>),
199
200    /// `core::future::async_drop::async_drop_in_place::<'_, T>::{closure}`.
201    ///
202    /// async_drop_in_place poll function implementation (for generated coroutine).
203    /// `Ty` here is `async_drop_in_place<T>::{closure}` coroutine type, not just `T`
204    AsyncDropGlue(DefId, Ty<'tcx>),
205}
206
207impl<'tcx> Instance<'tcx> {
208    /// Returns the `Ty` corresponding to this `Instance`, with generic instantiations applied and
209    /// lifetimes erased, allowing a `ParamEnv` to be specified for use during normalization.
210    pub fn ty(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Ty<'tcx> {
211        let ty = tcx.type_of(self.def.def_id());
212        tcx.instantiate_and_normalize_erasing_regions(self.args, typing_env, ty)
213    }
214
215    /// Finds a crate that contains a monomorphization of this instance that
216    /// can be linked to from the local crate. A return value of `None` means
217    /// no upstream crate provides such an exported monomorphization.
218    ///
219    /// This method already takes into account the global `-Zshare-generics`
220    /// setting, always returning `None` if `share-generics` is off.
221    pub fn upstream_monomorphization(&self, tcx: TyCtxt<'tcx>) -> Option<CrateNum> {
222        // If this is an item that is defined in the local crate, no upstream
223        // crate can know about it/provide a monomorphization.
224        if self.def_id().is_local() {
225            return None;
226        }
227
228        // If we are not in share generics mode, we don't link to upstream
229        // monomorphizations but always instantiate our own internal versions
230        // instead.
231        if !tcx.sess.opts.share_generics()
232            // However, if the def_id is marked inline(never), then it's fine to just reuse the
233            // upstream monomorphization.
234            && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_hir::attrs::InlineAttr::Never
235        {
236            return None;
237        }
238
239        // If this a non-generic instance, it cannot be a shared monomorphization.
240        self.args.non_erasable_generics().next()?;
241
242        // compiler_builtins cannot use upstream monomorphizations.
243        if tcx.is_compiler_builtins(LOCAL_CRATE) {
244            return None;
245        }
246
247        match self.def {
248            InstanceKind::Item(def) => tcx
249                .upstream_monomorphizations_for(def)
250                .and_then(|monos| monos.get(&self.args).cloned()),
251            InstanceKind::Shim(ShimKind::DropGlue(_, Some(_))) => {
252                tcx.upstream_drop_glue_for(self.args)
253            }
254            InstanceKind::Shim(ShimKind::AsyncDropGlue(_, _)) => None,
255            InstanceKind::Shim(ShimKind::FutureDropPoll(_, _, _)) => None,
256            InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(_, _)) => {
257                tcx.upstream_async_drop_glue_for(self.args)
258            }
259            _ => None,
260        }
261    }
262}
263
264impl<'tcx> InstanceKind<'tcx> {
265    #[inline]
266    pub fn def_id(self) -> DefId {
267        match self {
268            InstanceKind::Item(def_id)
269            | InstanceKind::Virtual(def_id, _)
270            | InstanceKind::Intrinsic(def_id)
271            | InstanceKind::LlvmIntrinsic(def_id) => def_id,
272            InstanceKind::Shim(shim) => shim.def_id(),
273        }
274    }
275
276    /// Returns the `DefId` of instances which might not require codegen locally.
277    pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
278        match self {
279            InstanceKind::Item(def) => Some(def),
280            InstanceKind::Virtual(..)
281            | InstanceKind::Intrinsic(..)
282            | InstanceKind::LlvmIntrinsic(..) => None,
283            InstanceKind::Shim(shim) => shim.def_id_if_not_guaranteed_local_codegen(),
284        }
285    }
286
287    /// Returns `true` if the LLVM version of this instance is unconditionally
288    /// marked with `inline`. This implies that a copy of this instance is
289    /// generated in every codegen unit.
290    /// Note that this is only a hint. See the documentation for
291    /// `generates_cgu_internal_copy` for more information.
292    pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool {
293        use rustc_hir::definitions::DefPathData;
294        match *self {
295            InstanceKind::Item(def_id) => #[allow(non_exhaustive_omitted_patterns)] match tcx.def_key(def_id).disambiguated_data.data
    {
    DefPathData::Ctor | DefPathData::Closure => true,
    _ => false,
}matches!(
296                tcx.def_key(def_id).disambiguated_data.data,
297                DefPathData::Ctor | DefPathData::Closure
298            ),
299            InstanceKind::Shim(shim) => shim.requires_inline(),
300            InstanceKind::Virtual(..)
301            | InstanceKind::Intrinsic(..)
302            | InstanceKind::LlvmIntrinsic(..) => true,
303        }
304    }
305
306    pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
307        match *self {
308            InstanceKind::Item(def_id)
309            | InstanceKind::Virtual(def_id, _)
310            | InstanceKind::Shim(ShimKind::VTable(def_id)) => {
311                tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
312            }
313            InstanceKind::Shim(ShimKind::ClosureOnce {
314                call_once: _,
315                closure: _,
316                track_caller,
317            }) => track_caller,
318            _ => false,
319        }
320    }
321
322    /// Returns `true` when the MIR body associated with this instance should be monomorphized
323    /// by its users (e.g. codegen or miri) by instantiating the `args` from `Instance` (see
324    /// `Instance::args_for_mir_body`).
325    ///
326    /// Otherwise, returns `false` only for some kinds of shims where the construction of the MIR
327    /// body should perform necessary instantiations.
328    pub fn has_polymorphic_mir_body(&self) -> bool {
329        match *self {
330            InstanceKind::Item(_)
331            | InstanceKind::Intrinsic(..)
332            | InstanceKind::LlvmIntrinsic(..)
333            | InstanceKind::Virtual(..) => true,
334            InstanceKind::Shim(shim) => shim.has_polymorphic_mir_body(),
335        }
336    }
337}
338
339impl<'tcx> ShimKind<'tcx> {
340    #[inline]
341    pub fn def_id(self) -> DefId {
342        match self {
343            ShimKind::VTable(def_id)
344            | ShimKind::Reify(def_id, _)
345            | ShimKind::FnPtr(def_id, _)
346            | ShimKind::ThreadLocal(def_id)
347            | ShimKind::ClosureOnce { call_once: def_id, closure: _, track_caller: _ }
348            | ShimKind::ConstructCoroutineInClosure {
349                coroutine_closure_def_id: def_id,
350                receiver_by_ref: _,
351            }
352            | ShimKind::DropGlue(def_id, _)
353            | ShimKind::Clone(def_id, _)
354            | ShimKind::FnPtrAsPtr(def_id, _)
355            | ShimKind::FnPtrFromPtr(def_id, _)
356            | ShimKind::FutureDropPoll(def_id, _, _)
357            | ShimKind::AsyncDropGlue(def_id, _)
358            | ShimKind::AsyncDropGlueCtor(def_id, _) => def_id,
359        }
360    }
361
362    /// Returns the `DefId` of instances which might not require codegen locally.
363    pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
364        match self {
365            ShimKind::DropGlue(def_id, Some(_))
366            | ShimKind::AsyncDropGlueCtor(def_id, _)
367            | ShimKind::AsyncDropGlue(def_id, _)
368            | ShimKind::FutureDropPoll(def_id, ..)
369            | ShimKind::ThreadLocal(def_id) => Some(def_id),
370            ShimKind::VTable(..)
371            | ShimKind::Reify(..)
372            | ShimKind::FnPtr(..)
373            | ShimKind::ClosureOnce { .. }
374            | ShimKind::ConstructCoroutineInClosure { .. }
375            | ShimKind::DropGlue(..)
376            | ShimKind::Clone(..)
377            | ShimKind::FnPtrAsPtr(..)
378            | ShimKind::FnPtrFromPtr(..) => None,
379        }
380    }
381
382    pub fn requires_inline(&self) -> bool {
383        match self {
384            ShimKind::DropGlue(_, Some(ty)) => ty.is_array(),
385            ShimKind::AsyncDropGlueCtor(_, ty) => ty.is_coroutine(),
386            ShimKind::FutureDropPoll(_, _, _) => false,
387            ShimKind::AsyncDropGlue(_, _) => false,
388            ShimKind::ThreadLocal(_) => false,
389            _ => true,
390        }
391    }
392
393    pub fn has_polymorphic_mir_body(&self) -> bool {
394        match *self {
395            ShimKind::Clone(..)
396            | ShimKind::ThreadLocal(..)
397            | ShimKind::FnPtr(..)
398            | ShimKind::FnPtrAsPtr(..)
399            | ShimKind::FnPtrFromPtr(..)
400            | ShimKind::DropGlue(_, Some(_))
401            | ShimKind::FutureDropPoll(..)
402            | ShimKind::AsyncDropGlue(_, _) => false,
403            ShimKind::AsyncDropGlueCtor(_, _) => false,
404            ShimKind::ClosureOnce { .. }
405            | ShimKind::ConstructCoroutineInClosure { .. }
406            | ShimKind::DropGlue(..)
407            | ShimKind::Reify(..)
408            | ShimKind::VTable(..) => true,
409        }
410    }
411}
412
413fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
414    struct Visitor<'tcx> {
415        type_length: usize,
416        cache: FxHashMap<Ty<'tcx>, usize>,
417    }
418    impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Visitor<'tcx> {
419        fn visit_ty(&mut self, t: Ty<'tcx>) {
420            if let Some(&value) = self.cache.get(&t) {
421                self.type_length += value;
422                return;
423            }
424
425            let prev = self.type_length;
426            self.type_length += 1;
427            t.super_visit_with(self);
428
429            // We don't try to use the cache if the type is fairly small.
430            if self.type_length > 16 {
431                self.cache.insert(t, self.type_length - prev);
432            }
433        }
434
435        fn visit_const(&mut self, ct: ty::Const<'tcx>) {
436            self.type_length += 1;
437            ct.super_visit_with(self);
438        }
439    }
440    let mut visitor = Visitor { type_length: 0, cache: Default::default() };
441    item.visit_with(&mut visitor);
442
443    visitor.type_length
444}
445
446impl<'tcx> fmt::Display for Instance<'tcx> {
447    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
448        ty::tls::with(|tcx| {
449            let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
450            tcx.lift(*self).print(&mut p)?;
451            let s = p.into_buffer();
452            f.write_str(&s)
453        })
454    }
455}
456
457// async_drop_in_place<T>::coroutine.poll, when T is a standard coroutine,
458// should be resolved to this coroutine's future_drop_poll (through FutureDropPollShim proxy).
459// async_drop_in_place<async_drop_in_place<T>::coroutine>::coroutine.poll,
460// when T is a standard coroutine, should be resolved to this coroutine's future_drop_poll.
461// async_drop_in_place<async_drop_in_place<T>::coroutine>::coroutine.poll,
462// when T is not a coroutine, should be resolved to the innermost
463// async_drop_in_place<T>::coroutine's poll function (through FutureDropPollShim proxy)
464fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
465    let first_cor = cor_ty;
466    let ty::Coroutine(poll_def_id, proxy_args) = first_cor.kind() else {
467        crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
468    };
469    let poll_def_id = *poll_def_id;
470    let mut child_ty = cor_ty;
471    loop {
472        if let ty::Coroutine(child_def, child_args) = child_ty.kind() {
473            cor_ty = child_ty;
474            if *child_def == poll_def_id {
475                child_ty = child_args.first().unwrap().expect_ty();
476                continue;
477            } else {
478                return Instance {
479                    def: ty::InstanceKind::Shim(ShimKind::FutureDropPoll(
480                        poll_def_id,
481                        first_cor,
482                        cor_ty,
483                    )),
484                    args: proxy_args,
485                };
486            }
487        } else {
488            let ty::Coroutine(_, child_args) = cor_ty.kind() else {
489                crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
490            };
491            if first_cor != cor_ty {
492                return Instance {
493                    def: ty::InstanceKind::Shim(ShimKind::FutureDropPoll(
494                        poll_def_id,
495                        first_cor,
496                        cor_ty,
497                    )),
498                    args: proxy_args,
499                };
500            } else {
501                return Instance {
502                    def: ty::InstanceKind::Shim(ShimKind::AsyncDropGlue(poll_def_id, cor_ty)),
503                    args: child_args,
504                };
505            }
506        }
507    }
508}
509
510impl<'tcx> Instance<'tcx> {
511    /// Creates a new [`InstanceKind::Item`] from the `def_id` and `args`.
512    ///
513    /// Note that this item corresponds to the body of `def_id` directly, which
514    /// likely does not make sense for trait items which need to be resolved to an
515    /// implementation, and which may not even have a body themselves. Usages of
516    /// this function should probably use [`Instance::expect_resolve`], or if run
517    /// in a polymorphic environment or within a lint (that may encounter ambiguity)
518    /// [`Instance::try_resolve`] instead.
519    pub fn new_raw(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
520        if !!args.has_escaping_bound_vars() {
    {
        ::core::panicking::panic_fmt(format_args!("args of instance {0:?} has escaping bound vars: {1:?}",
                def_id, args));
    }
};assert!(
521            !args.has_escaping_bound_vars(),
522            "args of instance {def_id:?} has escaping bound vars: {args:?}"
523        );
524        Instance { def: InstanceKind::Item(def_id), args }
525    }
526
527    pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
528        let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
529            ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
530            ty::GenericParamDefKind::Type { .. } => {
531                crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has type parameters",
        def_id))bug!("Instance::mono: {:?} has type parameters", def_id)
532            }
533            ty::GenericParamDefKind::Const { .. } => {
534                crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has const parameters",
        def_id))bug!("Instance::mono: {:?} has const parameters", def_id)
535            }
536        });
537
538        Instance::new_raw(def_id, args)
539    }
540
541    #[inline]
542    pub fn def_id(&self) -> DefId {
543        self.def.def_id()
544    }
545
546    /// Resolves a `(def_id, args)` pair to an (optional) instance -- most commonly,
547    /// this is used to find the precise code that will run for a trait method invocation,
548    /// if known. This should only be used for functions and consts. If you want to
549    /// resolve an associated type, use [`TyCtxt::try_normalize_erasing_regions`].
550    ///
551    /// Returns `Ok(None)` if we cannot resolve `Instance` to a specific instance.
552    /// For example, in a context like this,
553    ///
554    /// ```ignore (illustrative)
555    /// fn foo<T: Debug>(t: T) { ... }
556    /// ```
557    ///
558    /// trying to resolve `Debug::fmt` applied to `T` will yield `Ok(None)`, because we do not
559    /// know what code ought to run. This setting is also affected by the current `TypingMode`
560    /// of the environment.
561    ///
562    /// Presuming that coherence and type-check have succeeded, if this method is invoked
563    /// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
564    /// `Ok(Some(instance))`, **except** for when the instance's inputs hit the type size limit,
565    /// in which case it may bail out and return `Ok(None)`.
566    ///
567    /// Returns `Err(ErrorGuaranteed)` when the `Instance` resolution process
568    /// couldn't complete due to errors elsewhere - this is distinct
569    /// from `Ok(None)` to avoid misleading diagnostics when an error
570    /// has already been/will be emitted, for the original cause
571    {}
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("try_resolve",
                                "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                                ::tracing_core::__macro_support::Option::Some(571u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("typing_env")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("typing_env");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("args")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("args");
                                                    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(&typing_env)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                        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:
                                Result<Option<Instance<'tcx>>, ErrorGuaranteed> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        {
                            match tcx.def_kind(def_id) {
                                DefKind::Fn | DefKind::AssocFn | DefKind::Const { .. } |
                                    DefKind::AssocConst { .. } | DefKind::AnonConst |
                                    DefKind::Static { .. } | DefKind::Ctor(_, CtorKind::Fn) |
                                    DefKind::Closure | DefKind::SyntheticCoroutineBody => {}
                                ref left_val => {
                                    ::core::panicking::assert_matches_failed(left_val,
                                        "DefKind::Fn | DefKind::AssocFn | DefKind::Const { .. } |\nDefKind::AssocConst { .. } | DefKind::AnonConst | DefKind::Static { .. } |\nDefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure |\nDefKind::SyntheticCoroutineBody",
                                        ::core::option::Option::Some(format_args!("`Instance::try_resolve` should only be used to resolve instances of functions, statics, and consts; to resolve associated types, use `try_normalize_erasing_regions`.")));
                                }
                            }
                        };
                        if tcx.sess.opts.unstable_opts.enforce_type_length_limit &&
                                !tcx.type_length_limit().value_within_limit(type_length(args))
                            {
                            return Ok(None);
                        }
                        tcx.resolve_instance_raw(tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id,
                                        args))))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:571",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(571u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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)]
572    pub fn try_resolve(
573        tcx: TyCtxt<'tcx>,
574        typing_env: ty::TypingEnv<'tcx>,
575        def_id: DefId,
576        args: GenericArgsRef<'tcx>,
577    ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
578        assert_matches!(
579            tcx.def_kind(def_id),
580            DefKind::Fn
581                | DefKind::AssocFn
582                | DefKind::Const { .. }
583                | DefKind::AssocConst { .. }
584                | DefKind::AnonConst
585                | DefKind::Static { .. }
586                | DefKind::Ctor(_, CtorKind::Fn)
587                | DefKind::Closure
588                | DefKind::SyntheticCoroutineBody,
589            "`Instance::try_resolve` should only be used to resolve instances of \
590            functions, statics, and consts; to resolve associated types, use \
591            `try_normalize_erasing_regions`."
592        );
593
594        // Rust code can easily create exponentially-long types using only a
595        // polynomial recursion depth. Even with the default recursion
596        // depth, you can easily get cases that take >2^60 steps to run,
597        // which means that rustc basically hangs.
598        //
599        // Bail out in these cases to avoid that bad user experience.
600        if tcx.sess.opts.unstable_opts.enforce_type_length_limit
601            && !tcx.type_length_limit().value_within_limit(type_length(args))
602        {
603            return Ok(None);
604        }
605
606        // All regions in the result of this query are erased, so it's
607        // fine to erase all of the input regions.
608        tcx.resolve_instance_raw(
609            tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id, args))),
610        )
611    }
612
613    pub fn expect_resolve(
614        tcx: TyCtxt<'tcx>,
615        typing_env: ty::TypingEnv<'tcx>,
616        def_id: DefId,
617        args: GenericArgsRef<'tcx>,
618        span: Span,
619    ) -> Instance<'tcx> {
620        // We compute the span lazily, to avoid unnecessary query calls.
621        // If `span` is a DUMMY_SP, and the def id is local, then use the
622        // def span of the def id.
623        let span_or_local_def_span =
624            || if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
625
626        match ty::Instance::try_resolve(tcx, typing_env, def_id, args) {
627            Ok(Some(instance)) => instance,
628            Ok(None) => {
629                let type_length = type_length(args);
630                if !tcx.type_length_limit().value_within_limit(type_length) {
631                    tcx.dcx().emit_fatal(diagnostics::TypeLengthLimit {
632                        // We don't use `def_span(def_id)` so that diagnostics point
633                        // to the crate root during mono instead of to foreign items.
634                        // This is arguably better.
635                        span: span_or_local_def_span(),
636                        instance: Instance::new_raw(def_id, args),
637                        type_length,
638                    });
639                } else {
640                    crate::util::bug::span_bug_fmt(span_or_local_def_span(),
    format_args!("failed to resolve instance for {0}",
        tcx.def_path_str_with_args(def_id, args)))span_bug!(
641                        span_or_local_def_span(),
642                        "failed to resolve instance for {}",
643                        tcx.def_path_str_with_args(def_id, args)
644                    )
645                }
646            }
647            instance => crate::util::bug::span_bug_fmt(span_or_local_def_span(),
    format_args!("failed to resolve instance for {0}: {1:#?}",
        tcx.def_path_str_with_args(def_id, args), instance))span_bug!(
648                span_or_local_def_span(),
649                "failed to resolve instance for {}: {instance:#?}",
650                tcx.def_path_str_with_args(def_id, args)
651            ),
652        }
653    }
654
655    pub fn resolve_for_fn_ptr(
656        tcx: TyCtxt<'tcx>,
657        typing_env: ty::TypingEnv<'tcx>,
658        def_id: DefId,
659        args: GenericArgsRef<'tcx>,
660    ) -> Option<Instance<'tcx>> {
661        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:661",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(661u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!("resolve(def_id={0:?}, args={1:?})",
                                                    def_id, args) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("resolve(def_id={:?}, args={:?})", def_id, args);
662        // Use either `resolve_closure` or `resolve_for_vtable`
663        if !!tcx.is_closure_like(def_id) {
    {
        ::core::panicking::panic_fmt(format_args!("Called `resolve_for_fn_ptr` on closure: {0:?}",
                def_id));
    }
};assert!(!tcx.is_closure_like(def_id), "Called `resolve_for_fn_ptr` on closure: {def_id:?}");
664        let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
665        Instance::try_resolve(tcx, typing_env, def_id, args).ok().flatten().map(|mut resolved| {
666            match resolved.def {
667                InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
668                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:668",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(668u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => fn pointer created for function with #[track_caller]")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(" => fn pointer created for function with #[track_caller]");
669                    resolved.def = InstanceKind::Shim(ShimKind::Reify(def, reason));
670                }
671                InstanceKind::Virtual(def_id, _) => {
672                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:672",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(672u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => fn pointer created for virtual call")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(" => fn pointer created for virtual call");
673                    resolved.def = InstanceKind::Shim(ShimKind::Reify(def_id, reason));
674                }
675                _ if tcx.sess.is_sanitizer_kcfi_enabled() => {
676                    // Reify `::call`-like method implementations
677                    if tcx.is_closure_like(resolved.def_id()) {
678                        // Reroute through a reify via the *unresolved* instance. The resolved one can't
679                        // be directly reified because it's closure-like. The reify can handle the
680                        // unresolved instance.
681                        resolved = Instance {
682                            def: InstanceKind::Shim(ShimKind::Reify(def_id, reason)),
683                            args,
684                        }
685                    // Reify `Trait::method` implementations if the trait is dyn-compatible.
686                    } else if let Some(assoc) = tcx.opt_associated_item(def_id)
687                        && let AssocContainer::Trait | AssocContainer::TraitImpl(Ok(_)) =
688                            assoc.container
689                        && tcx.is_dyn_compatible(assoc.container_id(tcx))
690                    {
691                        // If this function could also go in a vtable, we need to `ReifyShim` it with
692                        // KCFI because it can only attach one type per function.
693                        resolved.def =
694                            InstanceKind::Shim(ShimKind::Reify(resolved.def_id(), reason))
695                    }
696                }
697                _ => {}
698            }
699
700            resolved
701        })
702    }
703
704    pub fn expect_resolve_for_vtable(
705        tcx: TyCtxt<'tcx>,
706        typing_env: ty::TypingEnv<'tcx>,
707        def_id: DefId,
708        args: GenericArgsRef<'tcx>,
709        span: Span,
710    ) -> Instance<'tcx> {
711        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:711",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(711u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!("resolve_for_vtable(def_id={0:?}, args={1:?})",
                                                    def_id, args) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
712        let fn_sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
713        let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
714            && fn_sig.input(0).skip_binder().is_param(0)
715            && tcx.generics_of(def_id).has_self;
716
717        if is_vtable_shim {
718            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:718",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(718u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => associated item with unsizeable self: Self")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(" => associated item with unsizeable self: Self");
719            return Instance { def: InstanceKind::Shim(ShimKind::VTable(def_id)), args };
720        }
721
722        let mut resolved = Instance::expect_resolve(tcx, typing_env, def_id, args, span);
723
724        let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
725        match resolved.def {
726            InstanceKind::Item(def) => {
727                // We need to generate a shim when we cannot guarantee that
728                // the caller of a trait object method will be aware of
729                // `#[track_caller]` - this ensures that the caller
730                // and callee ABI will always match.
731                //
732                // The shim is generated when all of these conditions are met:
733                //
734                // 1) The underlying method expects a caller location parameter
735                // in the ABI
736                let needs_track_caller_shim = resolved.def.requires_caller_location(tcx)
737                    // 2) The caller location parameter comes from having `#[track_caller]`
738                    // on the implementation, and *not* on the trait method.
739                    && !tcx.should_inherit_track_caller(def)
740                    // If the method implementation comes from the trait definition itself
741                    // (e.g. `trait Foo { #[track_caller] my_fn() { /* impl */ } }`),
742                    // then we don't need to generate a shim. This check is needed because
743                    // `should_inherit_track_caller` returns `false` if our method
744                    // implementation comes from the trait block, and not an impl block
745                    && !#[allow(non_exhaustive_omitted_patterns)] match tcx.opt_associated_item(def) {
    Some(ty::AssocItem { container: ty::AssocContainer::Trait, .. }) => true,
    _ => false,
}matches!(
746                        tcx.opt_associated_item(def),
747                        Some(ty::AssocItem {
748                            container: ty::AssocContainer::Trait,
749                            ..
750                        })
751                    );
752                if needs_track_caller_shim {
753                    if tcx.is_closure_like(def) {
754                        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:754",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(754u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => vtable fn pointer created for closure with #[track_caller]: {0:?} for method {1:?} {2:?}",
                                                    def, def_id, args) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
755                            " => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
756                            def, def_id, args
757                        );
758
759                        // Create a shim for the `FnOnce/FnMut/Fn` method we are calling
760                        // - unlike functions, invoking a closure always goes through a
761                        // trait.
762                        resolved = Instance {
763                            def: InstanceKind::Shim(ShimKind::Reify(def_id, reason)),
764                            args,
765                        };
766                    } else {
767                        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:767",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(767u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => vtable fn pointer created for function with #[track_caller]: {0:?}",
                                                    def) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
768                            " => vtable fn pointer created for function with #[track_caller]: {:?}",
769                            def
770                        );
771                        resolved.def = InstanceKind::Shim(ShimKind::Reify(def, reason));
772                    }
773                }
774            }
775            InstanceKind::Virtual(def_id, _) => {
776                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:776",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(776u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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!(" => vtable fn pointer created for virtual call")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(" => vtable fn pointer created for virtual call");
777                resolved.def = InstanceKind::Shim(ShimKind::Reify(def_id, reason))
778            }
779            _ => {}
780        }
781
782        resolved
783    }
784
785    pub fn resolve_closure(
786        tcx: TyCtxt<'tcx>,
787        def_id: DefId,
788        args: ty::GenericArgsRef<'tcx>,
789        requested_kind: ty::ClosureKind,
790    ) -> Instance<'tcx> {
791        let actual_kind = args.as_closure().kind();
792
793        match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
794            Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
795            _ => Instance::new_raw(def_id, args),
796        }
797    }
798
799    pub fn resolve_drop_glue(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
800        let def_id = tcx.require_lang_item(LangItem::DropGlue, DUMMY_SP);
801        let args = tcx.mk_args(&[ty.into()]);
802        Instance::expect_resolve(
803            tcx,
804            ty::TypingEnv::fully_monomorphized(),
805            def_id,
806            args,
807            ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
808        )
809    }
810
811    pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
812        let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP);
813        let args = tcx.mk_args(&[ty.into()]);
814        Instance::expect_resolve(
815            tcx,
816            ty::TypingEnv::fully_monomorphized(),
817            def_id,
818            args,
819            ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
820        )
821    }
822
823    pub fn resolve_async_drop_in_place_poll(
824        tcx: TyCtxt<'tcx>,
825        def_id: DefId,
826        ty: Ty<'tcx>,
827    ) -> ty::Instance<'tcx> {
828        let args = tcx.mk_args(&[ty.into()]);
829        Instance::expect_resolve(tcx, ty::TypingEnv::fully_monomorphized(), def_id, args, DUMMY_SP)
830    }
831
832    {}
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("fn_once_adapter_instance",
                                "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                                ::tracing_core::__macro_support::Option::Some(832u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("closure_did")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("closure_did");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("args")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("args");
                                                    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(&closure_did)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                        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: Instance<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let fn_once =
                            tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
                        let call_once =
                            tcx.associated_items(fn_once).in_definition_order().find(|it|
                                            it.is_fn()).unwrap().def_id;
                        let track_caller =
                            tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
                        let def =
                            ty::InstanceKind::Shim(ShimKind::ClosureOnce {
                                    call_once,
                                    closure: closure_did,
                                    track_caller,
                                });
                        let self_ty = Ty::new_closure(tcx, closure_did, args);
                        let tupled_inputs_ty =
                            args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
                        let tupled_inputs_ty =
                            tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
                        let args =
                            tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:859",
                                                "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                                                ::tracing_core::__macro_support::Option::Some(859u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("self_ty")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("self_ty");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("args")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("args");
                                                                    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(&self_ty)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tupled_inputs_ty.tuple_fields())
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        Instance { def, args }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs:832",
                        "rustc_middle::ty::instance", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/f248f4038796913873f11ca65b1b901e311c8dae/compiler/rustc_middle/src/ty/instance.rs"),
                        ::tracing_core::__macro_support::Option::Some(832u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
                        ::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)]
833    pub fn fn_once_adapter_instance(
834        tcx: TyCtxt<'tcx>,
835        closure_did: DefId,
836        args: ty::GenericArgsRef<'tcx>,
837    ) -> Instance<'tcx> {
838        let fn_once = tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
839        let call_once = tcx
840            .associated_items(fn_once)
841            .in_definition_order()
842            .find(|it| it.is_fn())
843            .unwrap()
844            .def_id;
845        let track_caller =
846            tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
847        let def = ty::InstanceKind::Shim(ShimKind::ClosureOnce {
848            call_once,
849            closure: closure_did,
850            track_caller,
851        });
852
853        let self_ty = Ty::new_closure(tcx, closure_did, args);
854
855        let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
856        let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
857        let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
858
859        debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
860        Instance { def, args }
861    }
862
863    pub fn try_resolve_item_for_coroutine(
864        tcx: TyCtxt<'tcx>,
865        trait_item_id: DefId,
866        trait_id: DefId,
867        rcvr_args: ty::GenericArgsRef<'tcx>,
868    ) -> Option<Instance<'tcx>> {
869        let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
870            return None;
871        };
872        let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap();
873
874        let coroutine_callable_item = if tcx.is_lang_item(trait_id, LangItem::Future) {
875            {
    match coroutine_kind {
        hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) =>
            {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(
876                coroutine_kind,
877                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
878            );
879            LangItem::FuturePoll
880        } else if tcx.is_lang_item(trait_id, LangItem::Iterator) {
881            {
    match coroutine_kind {
        hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(
882                coroutine_kind,
883                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
884            );
885            LangItem::IteratorNext
886        } else if tcx.is_lang_item(trait_id, LangItem::AsyncIterator) {
887            {
    match coroutine_kind {
        hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
            => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(
888                coroutine_kind,
889                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
890            );
891            LangItem::AsyncIteratorPollNext
892        } else if tcx.is_lang_item(trait_id, LangItem::Coroutine) {
893            {
    match coroutine_kind {
        hir::CoroutineKind::Coroutine(_) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "hir::CoroutineKind::Coroutine(_)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
894            LangItem::CoroutineResume
895        } else {
896            return None;
897        };
898
899        if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
900            if tcx.is_async_drop_in_place_coroutine(coroutine_def_id) {
901                return Some(resolve_async_drop_poll(rcvr_args.type_at(0)));
902            }
903            let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
904            else {
905                crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
906            };
907
908            // If the closure's kind ty disagrees with the identity closure's kind ty,
909            // then this must be a coroutine generated by one of the `ConstructCoroutineInClosureShim`s.
910            if args.as_coroutine().kind_ty() == id_args.as_coroutine().kind_ty() {
911                Some(Instance { def: ty::InstanceKind::Item(coroutine_def_id), args })
912            } else {
913                Some(Instance {
914                    def: ty::InstanceKind::Item(
915                        tcx.coroutine_by_move_body_def_id(coroutine_def_id),
916                    ),
917                    args,
918                })
919            }
920        } else {
921            // All other methods should be defaulted methods of the built-in trait.
922            // This is important for `Iterator`'s combinators, but also useful for
923            // adding future default methods to `Future`, for instance.
924            if true {
    if !tcx.defaultness(trait_item_id).has_value() {
        ::core::panicking::panic("assertion failed: tcx.defaultness(trait_item_id).has_value()")
    };
};debug_assert!(tcx.defaultness(trait_item_id).has_value());
925            Some(Instance::new_raw(trait_item_id, rcvr_args))
926        }
927    }
928
929    /// Depending on the kind of `InstanceKind`, the MIR body associated with an
930    /// instance is expressed in terms of the generic parameters of `self.def_id()`, and in other
931    /// cases the MIR body is expressed in terms of the types found in the generic parameter array.
932    /// In the former case, we want to instantiate those generic types and replace them with the
933    /// values from the args when monomorphizing the function body. But in the latter case, we
934    /// don't want to do that instantiation, since it has already been done effectively.
935    ///
936    /// This function returns `Some(args)` in the former case and `None` otherwise -- i.e., if
937    /// this function returns `None`, then the MIR body does not require instantiation during
938    /// codegen.
939    fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
940        self.def.has_polymorphic_mir_body().then_some(self.args)
941    }
942
943    pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, T>) -> T
944    where
945        T: TypeFoldable<TyCtxt<'tcx>> + Copy,
946    {
947        if let Some(args) = self.args_for_mir_body() {
948            v.instantiate(tcx, args).skip_norm_wip()
949        } else {
950            v.instantiate_identity().skip_norm_wip()
951        }
952    }
953
954    #[inline(always)]
955    // Keep me in sync with try_instantiate_mir_and_normalize_erasing_regions
956    pub fn instantiate_mir_and_normalize_erasing_regions<T>(
957        &self,
958        tcx: TyCtxt<'tcx>,
959        typing_env: ty::TypingEnv<'tcx>,
960        v: EarlyBinder<'tcx, T>,
961    ) -> T
962    where
963        T: TypeFoldable<TyCtxt<'tcx>>,
964    {
965        if let Some(args) = self.args_for_mir_body() {
966            tcx.instantiate_and_normalize_erasing_regions(args, typing_env, v)
967        } else {
968            tcx.normalize_erasing_regions(typing_env, v.instantiate_identity())
969        }
970    }
971
972    #[inline(always)]
973    // Keep me in sync with instantiate_mir_and_normalize_erasing_regions
974    pub fn try_instantiate_mir_and_normalize_erasing_regions<T>(
975        &self,
976        tcx: TyCtxt<'tcx>,
977        typing_env: ty::TypingEnv<'tcx>,
978        v: EarlyBinder<'tcx, T>,
979    ) -> Result<T, NormalizationError<'tcx>>
980    where
981        T: TypeFoldable<TyCtxt<'tcx>>,
982    {
983        if let Some(args) = self.args_for_mir_body() {
984            tcx.try_instantiate_and_normalize_erasing_regions(args, typing_env, v)
985        } else {
986            // We're using `instantiate_identity` as e.g.
987            // `FnPtrShim` is separately generated for every
988            // instantiation of the `FnDef`, so the MIR body
989            // is already instantiated. Any generic parameters it
990            // contains are generic parameters from the caller.
991            tcx.try_normalize_erasing_regions(typing_env, v.instantiate_identity())
992        }
993    }
994}
995
996fn needs_fn_once_adapter_shim(
997    actual_closure_kind: ty::ClosureKind,
998    trait_closure_kind: ty::ClosureKind,
999) -> Result<bool, ()> {
1000    match (actual_closure_kind, trait_closure_kind) {
1001        (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
1002        | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
1003        | (ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
1004            // No adapter needed.
1005            Ok(false)
1006        }
1007        (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
1008            // The closure fn is a `fn(&self, ...)`, but we want a `fn(&mut self, ...)`.
1009            // At codegen time, these are basically the same, so we can just return the closure.
1010            Ok(false)
1011        }
1012        (ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
1013            // The closure fn is a `fn(&self, ...)` or `fn(&mut self, ...)`, but
1014            // we want a `fn(self, ...)`. We can produce this by doing something like:
1015            //
1016            //     fn call_once(self, ...) { Fn::call(&self, ...) }
1017            //     fn call_once(mut self, ...) { FnMut::call_mut(&mut self, ...) }
1018            //
1019            // These are both the same at codegen time.
1020            Ok(true)
1021        }
1022        (ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
1023    }
1024}