1use std::{assert_matches, fmt};
2
3use rustc_data_structures::fx::FxHashMap;
4use rustc_errors::ErrorGuaranteed;
5use rustc_hir as hir;
6use rustc_hir::def::{CtorKind, DefKind, Namespace};
7use rustc_hir::def_id::{CrateNum, DefId};
8use rustc_hir::lang_items::LangItem;
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::error;
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#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for Instance<'tcx> { }Copy, #[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::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) {
match *self {
Instance { def: ref __binding_0, args: 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 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_hasher::StableHash for
Instance<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hasher::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hasher::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#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReifyReason { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ReifyReason {
#[inline]
fn clone(&self) -> ReifyReason { *self }
}Clone, #[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);
match *self {
ReifyReason::FnPtr => {}
ReifyReason::Vtable => {}
}
}
}
};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_hasher::StableHash for
ReifyReason {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hasher::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
ReifyReason::FnPtr => {}
ReifyReason::Vtable => {}
}
}
}
};StableHash)]
45pub enum ReifyReason {
46 FnPtr,
54 Vtable,
58}
59
60#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for InstanceKind<'tcx> { }Copy, #[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<Option<ReifyReason>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<usize>;
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>>;
*self
}
}Clone, #[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::VTableShim(__self_0),
InstanceKind::VTableShim(__arg1_0)) => __self_0 == __arg1_0,
(InstanceKind::ReifyShim(__self_0, __self_1),
InstanceKind::ReifyShim(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::FnPtrShim(__self_0, __self_1),
InstanceKind::FnPtrShim(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::Virtual(__self_0, __self_1),
InstanceKind::Virtual(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::ClosureOnceShim {
call_once: __self_0, track_caller: __self_1 },
InstanceKind::ClosureOnceShim {
call_once: __arg1_0, track_caller: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __self_0,
receiver_by_ref: __self_1 },
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __arg1_0,
receiver_by_ref: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(InstanceKind::ThreadLocalShim(__self_0),
InstanceKind::ThreadLocalShim(__arg1_0)) =>
__self_0 == __arg1_0,
(InstanceKind::FutureDropPollShim(__self_0, __self_1,
__self_2),
InstanceKind::FutureDropPollShim(__arg1_0, __arg1_1,
__arg1_2)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
(InstanceKind::DropGlue(__self_0, __self_1),
InstanceKind::DropGlue(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::CloneShim(__self_0, __self_1),
InstanceKind::CloneShim(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::FnPtrAddrShim(__self_0, __self_1),
InstanceKind::FnPtrAddrShim(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::AsyncDropGlueCtorShim(__self_0, __self_1),
InstanceKind::AsyncDropGlueCtorShim(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::AsyncDropGlue(__self_0, __self_1),
InstanceKind::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 InstanceKind<'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<usize>;
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>>;
}
}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::VTableShim(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InstanceKind::ReifyShim(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::FnPtrShim(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::Virtual(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::ClosureOnceShim {
call_once: __self_0, track_caller: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::ConstructCoroutineInClosureShim {
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)
}
InstanceKind::ThreadLocalShim(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InstanceKind::FutureDropPollShim(__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)
}
InstanceKind::DropGlue(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::CloneShim(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::FnPtrAddrShim(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::AsyncDropGlueCtorShim(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::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 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::VTableShim(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"VTableShim", &__self_0),
InstanceKind::ReifyShim(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ReifyShim", __self_0, &__self_1),
InstanceKind::FnPtrShim(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FnPtrShim", __self_0, &__self_1),
InstanceKind::Virtual(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"Virtual", __self_0, &__self_1),
InstanceKind::ClosureOnceShim {
call_once: __self_0, track_caller: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ClosureOnceShim", "call_once", __self_0, "track_caller",
&__self_1),
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __self_0, receiver_by_ref: __self_1
} =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ConstructCoroutineInClosureShim",
"coroutine_closure_def_id", __self_0, "receiver_by_ref",
&__self_1),
InstanceKind::ThreadLocalShim(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ThreadLocalShim", &__self_0),
InstanceKind::FutureDropPollShim(__self_0, __self_1, __self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"FutureDropPollShim", __self_0, __self_1, &__self_2),
InstanceKind::DropGlue(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DropGlue", __self_0, &__self_1),
InstanceKind::CloneShim(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"CloneShim", __self_0, &__self_1),
InstanceKind::FnPtrAddrShim(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FnPtrAddrShim", __self_0, &__self_1),
InstanceKind::AsyncDropGlueCtorShim(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AsyncDropGlueCtorShim", __self_0, &__self_1),
InstanceKind::AsyncDropGlue(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AsyncDropGlue", __self_0, &__self_1),
}
}
}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::VTableShim(ref __binding_0) => { 2usize }
InstanceKind::ReifyShim(ref __binding_0, ref __binding_1) =>
{
3usize
}
InstanceKind::FnPtrShim(ref __binding_0, ref __binding_1) =>
{
4usize
}
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
5usize
}
InstanceKind::ClosureOnceShim {
call_once: ref __binding_0, track_caller: ref __binding_1 }
=> {
6usize
}
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
7usize
}
InstanceKind::ThreadLocalShim(ref __binding_0) => { 8usize }
InstanceKind::FutureDropPollShim(ref __binding_0,
ref __binding_1, ref __binding_2) => {
9usize
}
InstanceKind::DropGlue(ref __binding_0, ref __binding_1) =>
{
10usize
}
InstanceKind::CloneShim(ref __binding_0, ref __binding_1) =>
{
11usize
}
InstanceKind::FnPtrAddrShim(ref __binding_0,
ref __binding_1) => {
12usize
}
InstanceKind::AsyncDropGlueCtorShim(ref __binding_0,
ref __binding_1) => {
13usize
}
InstanceKind::AsyncDropGlue(ref __binding_0,
ref __binding_1) => {
14usize
}
};
::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::VTableShim(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InstanceKind::ReifyShim(ref __binding_0, ref __binding_1) =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::FnPtrShim(ref __binding_0, ref __binding_1) =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__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::ClosureOnceShim {
call_once: ref __binding_0, track_caller: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::ConstructCoroutineInClosureShim {
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);
}
InstanceKind::ThreadLocalShim(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InstanceKind::FutureDropPollShim(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);
}
InstanceKind::DropGlue(ref __binding_0, ref __binding_1) =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::CloneShim(ref __binding_0, ref __binding_1) =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::FnPtrAddrShim(ref __binding_0,
ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::AsyncDropGlueCtorShim(ref __binding_0,
ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::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 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::VTableShim(::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
InstanceKind::ReifyShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
InstanceKind::FnPtrShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
5usize => {
InstanceKind::Virtual(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
InstanceKind::ClosureOnceShim {
call_once: ::rustc_serialize::Decodable::decode(__decoder),
track_caller: ::rustc_serialize::Decodable::decode(__decoder),
}
}
7usize => {
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: ::rustc_serialize::Decodable::decode(__decoder),
receiver_by_ref: ::rustc_serialize::Decodable::decode(__decoder),
}
}
8usize => {
InstanceKind::ThreadLocalShim(::rustc_serialize::Decodable::decode(__decoder))
}
9usize => {
InstanceKind::FutureDropPollShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
10usize => {
InstanceKind::DropGlue(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
11usize => {
InstanceKind::CloneShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
12usize => {
InstanceKind::FnPtrAddrShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
13usize => {
InstanceKind::AsyncDropGlueCtorShim(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
14usize => {
InstanceKind::AsyncDropGlue(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InstanceKind`, expected 0..15, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hasher::StableHash for
InstanceKind<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hasher::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hasher::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::VTableShim(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
InstanceKind::ReifyShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::FnPtrShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.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::ClosureOnceShim {
call_once: ref __binding_0, track_caller: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::ConstructCoroutineInClosureShim {
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); }
}
InstanceKind::ThreadLocalShim(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
InstanceKind::FutureDropPollShim(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); }
}
InstanceKind::DropGlue(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::CloneShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::FnPtrAddrShim(ref __binding_0,
ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::AsyncDropGlueCtorShim(ref __binding_0,
ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::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 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::VTableShim(__binding_0) => {
InstanceKind::VTableShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
InstanceKind::ReifyShim(__binding_0, __binding_1) => {
InstanceKind::ReifyShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::FnPtrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__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::ClosureOnceShim {
call_once: __binding_0, track_caller: __binding_1 } => {
InstanceKind::ClosureOnceShim {
call_once: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
track_caller: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
InstanceKind::ConstructCoroutineInClosureShim {
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)?,
}
}
InstanceKind::ThreadLocalShim(__binding_0) => {
InstanceKind::ThreadLocalShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
InstanceKind::FutureDropPollShim(__binding_0, __binding_1,
__binding_2) => {
InstanceKind::FutureDropPollShim(::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)?)
}
InstanceKind::DropGlue(__binding_0, __binding_1) => {
InstanceKind::DropGlue(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::CloneShim(__binding_0, __binding_1) => {
InstanceKind::CloneShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::FnPtrAddrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrAddrShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::AsyncDropGlueCtorShim(__binding_0,
__binding_1) => {
InstanceKind::AsyncDropGlueCtorShim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::AsyncDropGlue(__binding_0, __binding_1) => {
InstanceKind::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 {
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::VTableShim(__binding_0) => {
InstanceKind::VTableShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
InstanceKind::ReifyShim(__binding_0, __binding_1) => {
InstanceKind::ReifyShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::FnPtrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__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::ClosureOnceShim {
call_once: __binding_0, track_caller: __binding_1 } => {
InstanceKind::ClosureOnceShim {
call_once: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
track_caller: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
InstanceKind::ConstructCoroutineInClosureShim {
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),
}
}
InstanceKind::ThreadLocalShim(__binding_0) => {
InstanceKind::ThreadLocalShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
InstanceKind::FutureDropPollShim(__binding_0, __binding_1,
__binding_2) => {
InstanceKind::FutureDropPollShim(::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))
}
InstanceKind::DropGlue(__binding_0, __binding_1) => {
InstanceKind::DropGlue(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::CloneShim(__binding_0, __binding_1) => {
InstanceKind::CloneShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::FnPtrAddrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrAddrShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::AsyncDropGlueCtorShim(__binding_0,
__binding_1) => {
InstanceKind::AsyncDropGlueCtorShim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::AsyncDropGlue(__binding_0, __binding_1) => {
InstanceKind::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 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::VTableShim(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::ReifyShim(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::FnPtrShim(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::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::ClosureOnceShim {
call_once: ref __binding_0, track_caller: 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::ConstructCoroutineInClosureShim {
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);
}
}
}
}
InstanceKind::ThreadLocalShim(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::FutureDropPollShim(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);
}
}
}
}
InstanceKind::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);
}
}
}
}
InstanceKind::CloneShim(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::FnPtrAddrShim(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::AsyncDropGlueCtorShim(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::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 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::VTableShim(__binding_0) => {
InstanceKind::VTableShim(__tcx.lift(__binding_0))
}
InstanceKind::ReifyShim(__binding_0, __binding_1) => {
InstanceKind::ReifyShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::FnPtrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::Virtual(__binding_0, __binding_1) => {
InstanceKind::Virtual(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::ClosureOnceShim {
call_once: __binding_0, track_caller: __binding_1 } => {
InstanceKind::ClosureOnceShim {
call_once: __tcx.lift(__binding_0),
track_caller: __tcx.lift(__binding_1),
}
}
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: __tcx.lift(__binding_0),
receiver_by_ref: __tcx.lift(__binding_1),
}
}
InstanceKind::ThreadLocalShim(__binding_0) => {
InstanceKind::ThreadLocalShim(__tcx.lift(__binding_0))
}
InstanceKind::FutureDropPollShim(__binding_0, __binding_1,
__binding_2) => {
InstanceKind::FutureDropPollShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1), __tcx.lift(__binding_2))
}
InstanceKind::DropGlue(__binding_0, __binding_1) => {
InstanceKind::DropGlue(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::CloneShim(__binding_0, __binding_1) => {
InstanceKind::CloneShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::FnPtrAddrShim(__binding_0, __binding_1) => {
InstanceKind::FnPtrAddrShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::AsyncDropGlueCtorShim(__binding_0,
__binding_1) => {
InstanceKind::AsyncDropGlueCtorShim(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::AsyncDropGlue(__binding_0, __binding_1) => {
InstanceKind::AsyncDropGlue(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
}
}
}
};Lift)]
62pub enum InstanceKind<'tcx> {
63 Item(DefId),
70
71 Intrinsic(DefId),
77
78 VTableShim(DefId),
84
85 ReifyShim(DefId, Option<ReifyReason>),
103
104 FnPtrShim(DefId, Ty<'tcx>),
108
109 Virtual(DefId, usize),
118
119 ClosureOnceShim { call_once: DefId, track_caller: bool },
126
127 ConstructCoroutineInClosureShim {
133 coroutine_closure_def_id: DefId,
134 receiver_by_ref: bool,
140 },
141
142 ThreadLocalShim(DefId),
146
147 FutureDropPollShim(DefId, Ty<'tcx>, Ty<'tcx>),
149
150 DropGlue(DefId, Option<Ty<'tcx>>),
156
157 CloneShim(DefId, Ty<'tcx>),
164
165 FnPtrAddrShim(DefId, Ty<'tcx>),
171
172 AsyncDropGlueCtorShim(DefId, Ty<'tcx>),
177
178 AsyncDropGlue(DefId, Ty<'tcx>),
183}
184
185impl<'tcx> Instance<'tcx> {
186 pub fn ty(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Ty<'tcx> {
189 let ty = tcx.type_of(self.def.def_id());
190 tcx.instantiate_and_normalize_erasing_regions(self.args, typing_env, ty)
191 }
192
193 pub fn upstream_monomorphization(&self, tcx: TyCtxt<'tcx>) -> Option<CrateNum> {
200 if self.def_id().is_local() {
203 return None;
204 }
205
206 if !tcx.sess.opts.share_generics()
210 && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_hir::attrs::InlineAttr::Never
213 {
214 return None;
215 }
216
217 self.args.non_erasable_generics().next()?;
219
220 if tcx.is_compiler_builtins(LOCAL_CRATE) {
222 return None;
223 }
224
225 match self.def {
226 InstanceKind::Item(def) => tcx
227 .upstream_monomorphizations_for(def)
228 .and_then(|monos| monos.get(&self.args).cloned()),
229 InstanceKind::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
230 InstanceKind::AsyncDropGlue(_, _) => None,
231 InstanceKind::FutureDropPollShim(_, _, _) => None,
232 InstanceKind::AsyncDropGlueCtorShim(_, _) => {
233 tcx.upstream_async_drop_glue_for(self.args)
234 }
235 _ => None,
236 }
237 }
238}
239
240impl<'tcx> InstanceKind<'tcx> {
241 #[inline]
242 pub fn def_id(self) -> DefId {
243 match self {
244 InstanceKind::Item(def_id)
245 | InstanceKind::VTableShim(def_id)
246 | InstanceKind::ReifyShim(def_id, _)
247 | InstanceKind::FnPtrShim(def_id, _)
248 | InstanceKind::Virtual(def_id, _)
249 | InstanceKind::Intrinsic(def_id)
250 | InstanceKind::ThreadLocalShim(def_id)
251 | InstanceKind::ClosureOnceShim { call_once: def_id, track_caller: _ }
252 | ty::InstanceKind::ConstructCoroutineInClosureShim {
253 coroutine_closure_def_id: def_id,
254 receiver_by_ref: _,
255 }
256 | InstanceKind::DropGlue(def_id, _)
257 | InstanceKind::CloneShim(def_id, _)
258 | InstanceKind::FnPtrAddrShim(def_id, _)
259 | InstanceKind::FutureDropPollShim(def_id, _, _)
260 | InstanceKind::AsyncDropGlue(def_id, _)
261 | InstanceKind::AsyncDropGlueCtorShim(def_id, _) => def_id,
262 }
263 }
264
265 pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
267 match self {
268 ty::InstanceKind::Item(def) => Some(def),
269 ty::InstanceKind::DropGlue(def_id, Some(_))
270 | InstanceKind::AsyncDropGlueCtorShim(def_id, _)
271 | InstanceKind::AsyncDropGlue(def_id, _)
272 | InstanceKind::FutureDropPollShim(def_id, ..)
273 | InstanceKind::ThreadLocalShim(def_id) => Some(def_id),
274 InstanceKind::VTableShim(..)
275 | InstanceKind::ReifyShim(..)
276 | InstanceKind::FnPtrShim(..)
277 | InstanceKind::Virtual(..)
278 | InstanceKind::Intrinsic(..)
279 | InstanceKind::ClosureOnceShim { .. }
280 | ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
281 | InstanceKind::DropGlue(..)
282 | InstanceKind::CloneShim(..)
283 | InstanceKind::FnPtrAddrShim(..) => None,
284 }
285 }
286
287 pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool {
293 use rustc_hir::definitions::DefPathData;
294 let def_id = match *self {
295 ty::InstanceKind::Item(def) => def,
296 ty::InstanceKind::DropGlue(_, Some(_)) => return false,
297 ty::InstanceKind::AsyncDropGlueCtorShim(_, ty) => return ty.is_coroutine(),
298 ty::InstanceKind::FutureDropPollShim(_, _, _) => return false,
299 ty::InstanceKind::AsyncDropGlue(_, _) => return false,
300 ty::InstanceKind::ThreadLocalShim(_) => return false,
301 _ => return true,
302 };
303 #[allow(non_exhaustive_omitted_patterns)] match tcx.def_key(def_id).disambiguated_data.data
{
DefPathData::Ctor | DefPathData::Closure => true,
_ => false,
}matches!(
304 tcx.def_key(def_id).disambiguated_data.data,
305 DefPathData::Ctor | DefPathData::Closure
306 )
307 }
308
309 pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
310 match *self {
311 InstanceKind::Item(def_id) | InstanceKind::Virtual(def_id, _) => {
312 tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
313 }
314 InstanceKind::ClosureOnceShim { call_once: _, track_caller } => track_caller,
315 _ => false,
316 }
317 }
318
319 pub fn has_polymorphic_mir_body(&self) -> bool {
326 match *self {
327 InstanceKind::CloneShim(..)
328 | InstanceKind::ThreadLocalShim(..)
329 | InstanceKind::FnPtrAddrShim(..)
330 | InstanceKind::FnPtrShim(..)
331 | InstanceKind::DropGlue(_, Some(_))
332 | InstanceKind::FutureDropPollShim(..)
333 | InstanceKind::AsyncDropGlue(_, _) => false,
334 InstanceKind::AsyncDropGlueCtorShim(_, _) => false,
335 InstanceKind::ClosureOnceShim { .. }
336 | InstanceKind::ConstructCoroutineInClosureShim { .. }
337 | InstanceKind::DropGlue(..)
338 | InstanceKind::Item(_)
339 | InstanceKind::Intrinsic(..)
340 | InstanceKind::ReifyShim(..)
341 | InstanceKind::Virtual(..)
342 | InstanceKind::VTableShim(..) => true,
343 }
344 }
345}
346
347fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
348 struct Visitor<'tcx> {
349 type_length: usize,
350 cache: FxHashMap<Ty<'tcx>, usize>,
351 }
352 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Visitor<'tcx> {
353 fn visit_ty(&mut self, t: Ty<'tcx>) {
354 if let Some(&value) = self.cache.get(&t) {
355 self.type_length += value;
356 return;
357 }
358
359 let prev = self.type_length;
360 self.type_length += 1;
361 t.super_visit_with(self);
362
363 if self.type_length > 16 {
365 self.cache.insert(t, self.type_length - prev);
366 }
367 }
368
369 fn visit_const(&mut self, ct: ty::Const<'tcx>) {
370 self.type_length += 1;
371 ct.super_visit_with(self);
372 }
373 }
374 let mut visitor = Visitor { type_length: 0, cache: Default::default() };
375 item.visit_with(&mut visitor);
376
377 visitor.type_length
378}
379
380impl<'tcx> fmt::Display for Instance<'tcx> {
381 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
382 ty::tls::with(|tcx| {
383 let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
384 tcx.lift(*self).print(&mut p)?;
385 let s = p.into_buffer();
386 f.write_str(&s)
387 })
388 }
389}
390
391fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
399 let first_cor = cor_ty;
400 let ty::Coroutine(poll_def_id, proxy_args) = first_cor.kind() else {
401 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
402 };
403 let poll_def_id = *poll_def_id;
404 let mut child_ty = cor_ty;
405 loop {
406 if let ty::Coroutine(child_def, child_args) = child_ty.kind() {
407 cor_ty = child_ty;
408 if *child_def == poll_def_id {
409 child_ty = child_args.first().unwrap().expect_ty();
410 continue;
411 } else {
412 return Instance {
413 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
414 args: proxy_args,
415 };
416 }
417 } else {
418 let ty::Coroutine(_, child_args) = cor_ty.kind() else {
419 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
420 };
421 if first_cor != cor_ty {
422 return Instance {
423 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
424 args: proxy_args,
425 };
426 } else {
427 return Instance {
428 def: ty::InstanceKind::AsyncDropGlue(poll_def_id, cor_ty),
429 args: child_args,
430 };
431 }
432 }
433 }
434}
435
436impl<'tcx> Instance<'tcx> {
437 pub fn new_raw(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
446 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!(
447 !args.has_escaping_bound_vars(),
448 "args of instance {def_id:?} has escaping bound vars: {args:?}"
449 );
450 Instance { def: InstanceKind::Item(def_id), args }
451 }
452
453 pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
454 let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
455 ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
456 ty::GenericParamDefKind::Type { .. } => {
457 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has type parameters",
def_id))bug!("Instance::mono: {:?} has type parameters", def_id)
458 }
459 ty::GenericParamDefKind::Const { .. } => {
460 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has const parameters",
def_id))bug!("Instance::mono: {:?} has const parameters", def_id)
461 }
462 });
463
464 Instance::new_raw(def_id, args)
465 }
466
467 #[inline]
468 pub fn def_id(&self) -> DefId {
469 self.def.def_id()
470 }
471
472 x;#[instrument(level = "debug", skip(tcx), ret)]
498 pub fn try_resolve(
499 tcx: TyCtxt<'tcx>,
500 typing_env: ty::TypingEnv<'tcx>,
501 def_id: DefId,
502 args: GenericArgsRef<'tcx>,
503 ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
504 assert_matches!(
505 tcx.def_kind(def_id),
506 DefKind::Fn
507 | DefKind::AssocFn
508 | DefKind::Const { .. }
509 | DefKind::AssocConst { .. }
510 | DefKind::AnonConst
511 | DefKind::InlineConst
512 | DefKind::Static { .. }
513 | DefKind::Ctor(_, CtorKind::Fn)
514 | DefKind::Closure
515 | DefKind::SyntheticCoroutineBody,
516 "`Instance::try_resolve` should only be used to resolve instances of \
517 functions, statics, and consts; to resolve associated types, use \
518 `try_normalize_erasing_regions`."
519 );
520
521 if tcx.sess.opts.unstable_opts.enforce_type_length_limit
528 && !tcx.type_length_limit().value_within_limit(type_length(args))
529 {
530 return Ok(None);
531 }
532
533 tcx.resolve_instance_raw(
536 tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id, args))),
537 )
538 }
539
540 pub fn expect_resolve(
541 tcx: TyCtxt<'tcx>,
542 typing_env: ty::TypingEnv<'tcx>,
543 def_id: DefId,
544 args: GenericArgsRef<'tcx>,
545 span: Span,
546 ) -> Instance<'tcx> {
547 let span_or_local_def_span =
551 || if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
552
553 match ty::Instance::try_resolve(tcx, typing_env, def_id, args) {
554 Ok(Some(instance)) => instance,
555 Ok(None) => {
556 let type_length = type_length(args);
557 if !tcx.type_length_limit().value_within_limit(type_length) {
558 tcx.dcx().emit_fatal(error::TypeLengthLimit {
559 span: span_or_local_def_span(),
563 instance: Instance::new_raw(def_id, args),
564 type_length,
565 });
566 } else {
567 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!(
568 span_or_local_def_span(),
569 "failed to resolve instance for {}",
570 tcx.def_path_str_with_args(def_id, args)
571 )
572 }
573 }
574 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!(
575 span_or_local_def_span(),
576 "failed to resolve instance for {}: {instance:#?}",
577 tcx.def_path_str_with_args(def_id, args)
578 ),
579 }
580 }
581
582 pub fn resolve_for_fn_ptr(
583 tcx: TyCtxt<'tcx>,
584 typing_env: ty::TypingEnv<'tcx>,
585 def_id: DefId,
586 args: GenericArgsRef<'tcx>,
587 ) -> Option<Instance<'tcx>> {
588 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:588",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(588u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("resolve(def_id={0:?}, args={1:?})",
def_id, args) as &dyn Value))])
});
} else { ; }
};debug!("resolve(def_id={:?}, args={:?})", def_id, args);
589 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:?}");
591 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
592 Instance::try_resolve(tcx, typing_env, def_id, args).ok().flatten().map(|mut resolved| {
593 match resolved.def {
594 InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
595 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:595",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(595u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => fn pointer created for function with #[track_caller]")
as &dyn Value))])
});
} else { ; }
};debug!(" => fn pointer created for function with #[track_caller]");
596 resolved.def = InstanceKind::ReifyShim(def, reason);
597 }
598 InstanceKind::Virtual(def_id, _) => {
599 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:599",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(599u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => fn pointer created for virtual call")
as &dyn Value))])
});
} else { ; }
};debug!(" => fn pointer created for virtual call");
600 resolved.def = InstanceKind::ReifyShim(def_id, reason);
601 }
602 _ if tcx.sess.is_sanitizer_kcfi_enabled() => {
603 if tcx.is_closure_like(resolved.def_id()) {
605 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args }
609 } else if let Some(assoc) = tcx.opt_associated_item(def_id)
611 && let AssocContainer::Trait | AssocContainer::TraitImpl(Ok(_)) =
612 assoc.container
613 && tcx.is_dyn_compatible(assoc.container_id(tcx))
614 {
615 resolved.def = InstanceKind::ReifyShim(resolved.def_id(), reason)
618 }
619 }
620 _ => {}
621 }
622
623 resolved
624 })
625 }
626
627 pub fn expect_resolve_for_vtable(
628 tcx: TyCtxt<'tcx>,
629 typing_env: ty::TypingEnv<'tcx>,
630 def_id: DefId,
631 args: GenericArgsRef<'tcx>,
632 span: Span,
633 ) -> Instance<'tcx> {
634 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:634",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(634u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("resolve_for_vtable(def_id={0:?}, args={1:?})",
def_id, args) as &dyn Value))])
});
} else { ; }
};debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
635 let fn_sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
636 let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
637 && fn_sig.input(0).skip_binder().is_param(0)
638 && tcx.generics_of(def_id).has_self;
639
640 if is_vtable_shim {
641 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:641",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(641u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => associated item with unsizeable self: Self")
as &dyn Value))])
});
} else { ; }
};debug!(" => associated item with unsizeable self: Self");
642 return Instance { def: InstanceKind::VTableShim(def_id), args };
643 }
644
645 let mut resolved = Instance::expect_resolve(tcx, typing_env, def_id, args, span);
646
647 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
648 match resolved.def {
649 InstanceKind::Item(def) => {
650 let needs_track_caller_shim = resolved.def.requires_caller_location(tcx)
660 && !tcx.should_inherit_track_caller(def)
663 && !#[allow(non_exhaustive_omitted_patterns)] match tcx.opt_associated_item(def) {
Some(ty::AssocItem { container: ty::AssocContainer::Trait, .. }) => true,
_ => false,
}matches!(
669 tcx.opt_associated_item(def),
670 Some(ty::AssocItem {
671 container: ty::AssocContainer::Trait,
672 ..
673 })
674 );
675 if needs_track_caller_shim {
676 if tcx.is_closure_like(def) {
677 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:677",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(677u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for closure with #[track_caller]: {0:?} for method {1:?} {2:?}",
def, def_id, args) as &dyn Value))])
});
} else { ; }
};debug!(
678 " => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
679 def, def_id, args
680 );
681
682 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args };
686 } else {
687 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:687",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(687u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for function with #[track_caller]: {0:?}",
def) as &dyn Value))])
});
} else { ; }
};debug!(
688 " => vtable fn pointer created for function with #[track_caller]: {:?}",
689 def
690 );
691 resolved.def = InstanceKind::ReifyShim(def, reason);
692 }
693 }
694 }
695 InstanceKind::Virtual(def_id, _) => {
696 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/instance.rs:696",
"rustc_middle::ty::instance", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/instance.rs"),
::tracing_core::__macro_support::Option::Some(696u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for virtual call")
as &dyn Value))])
});
} else { ; }
};debug!(" => vtable fn pointer created for virtual call");
697 resolved.def = InstanceKind::ReifyShim(def_id, reason)
698 }
699 _ => {}
700 }
701
702 resolved
703 }
704
705 pub fn resolve_closure(
706 tcx: TyCtxt<'tcx>,
707 def_id: DefId,
708 args: ty::GenericArgsRef<'tcx>,
709 requested_kind: ty::ClosureKind,
710 ) -> Instance<'tcx> {
711 let actual_kind = args.as_closure().kind();
712
713 match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
714 Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
715 _ => Instance::new_raw(def_id, args),
716 }
717 }
718
719 pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
720 let def_id = tcx.require_lang_item(LangItem::DropInPlace, DUMMY_SP);
721 let args = tcx.mk_args(&[ty.into()]);
722 Instance::expect_resolve(
723 tcx,
724 ty::TypingEnv::fully_monomorphized(),
725 def_id,
726 args,
727 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
728 )
729 }
730
731 pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
732 let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP);
733 let args = tcx.mk_args(&[ty.into()]);
734 Instance::expect_resolve(
735 tcx,
736 ty::TypingEnv::fully_monomorphized(),
737 def_id,
738 args,
739 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
740 )
741 }
742
743 pub fn resolve_async_drop_in_place_poll(
744 tcx: TyCtxt<'tcx>,
745 def_id: DefId,
746 ty: Ty<'tcx>,
747 ) -> ty::Instance<'tcx> {
748 let args = tcx.mk_args(&[ty.into()]);
749 Instance::expect_resolve(tcx, ty::TypingEnv::fully_monomorphized(), def_id, args, DUMMY_SP)
750 }
751
752 x;#[instrument(level = "debug", skip(tcx), ret)]
753 pub fn fn_once_adapter_instance(
754 tcx: TyCtxt<'tcx>,
755 closure_did: DefId,
756 args: ty::GenericArgsRef<'tcx>,
757 ) -> Instance<'tcx> {
758 let fn_once = tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
759 let call_once = tcx
760 .associated_items(fn_once)
761 .in_definition_order()
762 .find(|it| it.is_fn())
763 .unwrap()
764 .def_id;
765 let track_caller =
766 tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
767 let def = ty::InstanceKind::ClosureOnceShim { call_once, track_caller };
768
769 let self_ty = Ty::new_closure(tcx, closure_did, args);
770
771 let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
772 let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
773 let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
774
775 debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
776 Instance { def, args }
777 }
778
779 pub fn try_resolve_item_for_coroutine(
780 tcx: TyCtxt<'tcx>,
781 trait_item_id: DefId,
782 trait_id: DefId,
783 rcvr_args: ty::GenericArgsRef<'tcx>,
784 ) -> Option<Instance<'tcx>> {
785 let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
786 return None;
787 };
788 let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap();
789
790 let coroutine_callable_item = if tcx.is_lang_item(trait_id, LangItem::Future) {
791 {
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!(
792 coroutine_kind,
793 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
794 );
795 hir::LangItem::FuturePoll
796 } else if tcx.is_lang_item(trait_id, LangItem::Iterator) {
797 {
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!(
798 coroutine_kind,
799 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
800 );
801 hir::LangItem::IteratorNext
802 } else if tcx.is_lang_item(trait_id, LangItem::AsyncIterator) {
803 {
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!(
804 coroutine_kind,
805 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
806 );
807 hir::LangItem::AsyncIteratorPollNext
808 } else if tcx.is_lang_item(trait_id, LangItem::Coroutine) {
809 {
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(_));
810 hir::LangItem::CoroutineResume
811 } else {
812 return None;
813 };
814
815 if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
816 if tcx.is_async_drop_in_place_coroutine(coroutine_def_id) {
817 return Some(resolve_async_drop_poll(rcvr_args.type_at(0)));
818 }
819 let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
820 else {
821 crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
822 };
823
824 if args.as_coroutine().kind_ty() == id_args.as_coroutine().kind_ty() {
827 Some(Instance { def: ty::InstanceKind::Item(coroutine_def_id), args })
828 } else {
829 Some(Instance {
830 def: ty::InstanceKind::Item(
831 tcx.coroutine_by_move_body_def_id(coroutine_def_id),
832 ),
833 args,
834 })
835 }
836 } else {
837 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());
841 Some(Instance::new_raw(trait_item_id, rcvr_args))
842 }
843 }
844
845 fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
856 self.def.has_polymorphic_mir_body().then_some(self.args)
857 }
858
859 pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, &T>) -> T
860 where
861 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
862 {
863 let v = v.map_bound(|v| *v);
864 if let Some(args) = self.args_for_mir_body() {
865 v.instantiate(tcx, args).skip_norm_wip()
866 } else {
867 v.instantiate_identity().skip_norm_wip()
868 }
869 }
870
871 #[inline(always)]
872 pub fn instantiate_mir_and_normalize_erasing_regions<T>(
874 &self,
875 tcx: TyCtxt<'tcx>,
876 typing_env: ty::TypingEnv<'tcx>,
877 v: EarlyBinder<'tcx, T>,
878 ) -> T
879 where
880 T: TypeFoldable<TyCtxt<'tcx>>,
881 {
882 if let Some(args) = self.args_for_mir_body() {
883 tcx.instantiate_and_normalize_erasing_regions(args, typing_env, v)
884 } else {
885 tcx.normalize_erasing_regions(typing_env, v.instantiate_identity())
886 }
887 }
888
889 #[inline(always)]
890 pub fn try_instantiate_mir_and_normalize_erasing_regions<T>(
892 &self,
893 tcx: TyCtxt<'tcx>,
894 typing_env: ty::TypingEnv<'tcx>,
895 v: EarlyBinder<'tcx, T>,
896 ) -> Result<T, NormalizationError<'tcx>>
897 where
898 T: TypeFoldable<TyCtxt<'tcx>>,
899 {
900 if let Some(args) = self.args_for_mir_body() {
901 tcx.try_instantiate_and_normalize_erasing_regions(args, typing_env, v)
902 } else {
903 tcx.try_normalize_erasing_regions(typing_env, v.instantiate_identity())
909 }
910 }
911}
912
913fn needs_fn_once_adapter_shim(
914 actual_closure_kind: ty::ClosureKind,
915 trait_closure_kind: ty::ClosureKind,
916) -> Result<bool, ()> {
917 match (actual_closure_kind, trait_closure_kind) {
918 (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
919 | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
920 | (ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
921 Ok(false)
923 }
924 (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
925 Ok(false)
928 }
929 (ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
930 Ok(true)
938 }
939 (ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
940 }
941}