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_index::bit_set::FiniteBitSet;
10use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
11use rustc_span::def_id::LOCAL_CRATE;
12use rustc_span::{DUMMY_SP, Span};
13use tracing::{debug, instrument};
14
15use crate::error;
16use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
17use crate::ty::normalize_erasing_regions::NormalizationError;
18use crate::ty::print::{FmtPrinter, Print};
19use crate::ty::{
20 self, AssocContainer, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable,
21 TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
22};
23
24#[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)]
33#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for Instance<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Instance { def: ref __binding_0, args: ref __binding_1 } =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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>)
-> Option<Instance<'__lifted>> {
Some(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)]
34pub struct Instance<'tcx> {
35 pub def: InstanceKind<'tcx>,
36 pub args: GenericArgsRef<'tcx>,
37}
38
39#[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)]
45#[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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ReifyReason {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
ReifyReason::FnPtr => {}
ReifyReason::Vtable => {}
}
}
}
};HashStable)]
46pub enum ReifyReason {
47 FnPtr,
55 Vtable,
59}
60
61#[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)]
62#[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for InstanceKind<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
InstanceKind::Item(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
InstanceKind::Intrinsic(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
InstanceKind::VTableShim(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
InstanceKind::ReifyShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::FnPtrShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::ClosureOnceShim {
call_once: ref __binding_0, track_caller: ref __binding_1 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::ConstructCoroutineInClosureShim {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::ThreadLocalShim(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
InstanceKind::FutureDropPollShim(ref __binding_0,
ref __binding_1, ref __binding_2) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
InstanceKind::DropGlue(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::CloneShim(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::FnPtrAddrShim(ref __binding_0,
ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::AsyncDropGlueCtorShim(ref __binding_0,
ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
InstanceKind::AsyncDropGlue(ref __binding_0,
ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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>)
-> Option<InstanceKind<'__lifted>> {
Some(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)]
63pub enum InstanceKind<'tcx> {
64 Item(DefId),
71
72 Intrinsic(DefId),
78
79 VTableShim(DefId),
85
86 ReifyShim(DefId, Option<ReifyReason>),
104
105 FnPtrShim(DefId, Ty<'tcx>),
109
110 Virtual(DefId, usize),
119
120 ClosureOnceShim { call_once: DefId, track_caller: bool },
127
128 ConstructCoroutineInClosureShim {
134 coroutine_closure_def_id: DefId,
135 receiver_by_ref: bool,
141 },
142
143 ThreadLocalShim(DefId),
147
148 FutureDropPollShim(DefId, Ty<'tcx>, Ty<'tcx>),
150
151 DropGlue(DefId, Option<Ty<'tcx>>),
157
158 CloneShim(DefId, Ty<'tcx>),
165
166 FnPtrAddrShim(DefId, Ty<'tcx>),
172
173 AsyncDropGlueCtorShim(DefId, Ty<'tcx>),
178
179 AsyncDropGlue(DefId, Ty<'tcx>),
184}
185
186impl<'tcx> Instance<'tcx> {
187 pub fn ty(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Ty<'tcx> {
190 let ty = tcx.type_of(self.def.def_id());
191 tcx.instantiate_and_normalize_erasing_regions(self.args, typing_env, ty)
192 }
193
194 pub fn upstream_monomorphization(&self, tcx: TyCtxt<'tcx>) -> Option<CrateNum> {
201 if self.def_id().is_local() {
204 return None;
205 }
206
207 if !tcx.sess.opts.share_generics()
211 && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_hir::attrs::InlineAttr::Never
214 {
215 return None;
216 }
217
218 self.args.non_erasable_generics().next()?;
220
221 if tcx.is_compiler_builtins(LOCAL_CRATE) {
223 return None;
224 }
225
226 match self.def {
227 InstanceKind::Item(def) => tcx
228 .upstream_monomorphizations_for(def)
229 .and_then(|monos| monos.get(&self.args).cloned()),
230 InstanceKind::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
231 InstanceKind::AsyncDropGlue(_, _) => None,
232 InstanceKind::FutureDropPollShim(_, _, _) => None,
233 InstanceKind::AsyncDropGlueCtorShim(_, _) => {
234 tcx.upstream_async_drop_glue_for(self.args)
235 }
236 _ => None,
237 }
238 }
239}
240
241impl<'tcx> InstanceKind<'tcx> {
242 #[inline]
243 pub fn def_id(self) -> DefId {
244 match self {
245 InstanceKind::Item(def_id)
246 | InstanceKind::VTableShim(def_id)
247 | InstanceKind::ReifyShim(def_id, _)
248 | InstanceKind::FnPtrShim(def_id, _)
249 | InstanceKind::Virtual(def_id, _)
250 | InstanceKind::Intrinsic(def_id)
251 | InstanceKind::ThreadLocalShim(def_id)
252 | InstanceKind::ClosureOnceShim { call_once: def_id, track_caller: _ }
253 | ty::InstanceKind::ConstructCoroutineInClosureShim {
254 coroutine_closure_def_id: def_id,
255 receiver_by_ref: _,
256 }
257 | InstanceKind::DropGlue(def_id, _)
258 | InstanceKind::CloneShim(def_id, _)
259 | InstanceKind::FnPtrAddrShim(def_id, _)
260 | InstanceKind::FutureDropPollShim(def_id, _, _)
261 | InstanceKind::AsyncDropGlue(def_id, _)
262 | InstanceKind::AsyncDropGlueCtorShim(def_id, _) => def_id,
263 }
264 }
265
266 pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
268 match self {
269 ty::InstanceKind::Item(def) => Some(def),
270 ty::InstanceKind::DropGlue(def_id, Some(_))
271 | InstanceKind::AsyncDropGlueCtorShim(def_id, _)
272 | InstanceKind::AsyncDropGlue(def_id, _)
273 | InstanceKind::FutureDropPollShim(def_id, ..)
274 | InstanceKind::ThreadLocalShim(def_id) => Some(def_id),
275 InstanceKind::VTableShim(..)
276 | InstanceKind::ReifyShim(..)
277 | InstanceKind::FnPtrShim(..)
278 | InstanceKind::Virtual(..)
279 | InstanceKind::Intrinsic(..)
280 | InstanceKind::ClosureOnceShim { .. }
281 | ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
282 | InstanceKind::DropGlue(..)
283 | InstanceKind::CloneShim(..)
284 | InstanceKind::FnPtrAddrShim(..) => None,
285 }
286 }
287
288 pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool {
294 use rustc_hir::definitions::DefPathData;
295 let def_id = match *self {
296 ty::InstanceKind::Item(def) => def,
297 ty::InstanceKind::DropGlue(_, Some(_)) => return false,
298 ty::InstanceKind::AsyncDropGlueCtorShim(_, ty) => return ty.is_coroutine(),
299 ty::InstanceKind::FutureDropPollShim(_, _, _) => return false,
300 ty::InstanceKind::AsyncDropGlue(_, _) => return false,
301 ty::InstanceKind::ThreadLocalShim(_) => return false,
302 _ => return true,
303 };
304 #[allow(non_exhaustive_omitted_patterns)] match tcx.def_key(def_id).disambiguated_data.data
{
DefPathData::Ctor | DefPathData::Closure => true,
_ => false,
}matches!(
305 tcx.def_key(def_id).disambiguated_data.data,
306 DefPathData::Ctor | DefPathData::Closure
307 )
308 }
309
310 pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
311 match *self {
312 InstanceKind::Item(def_id) | InstanceKind::Virtual(def_id, _) => {
313 tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
314 }
315 InstanceKind::ClosureOnceShim { call_once: _, track_caller } => track_caller,
316 _ => false,
317 }
318 }
319
320 pub fn has_polymorphic_mir_body(&self) -> bool {
327 match *self {
328 InstanceKind::CloneShim(..)
329 | InstanceKind::ThreadLocalShim(..)
330 | InstanceKind::FnPtrAddrShim(..)
331 | InstanceKind::FnPtrShim(..)
332 | InstanceKind::DropGlue(_, Some(_))
333 | InstanceKind::FutureDropPollShim(..)
334 | InstanceKind::AsyncDropGlue(_, _) => false,
335 InstanceKind::AsyncDropGlueCtorShim(_, _) => false,
336 InstanceKind::ClosureOnceShim { .. }
337 | InstanceKind::ConstructCoroutineInClosureShim { .. }
338 | InstanceKind::DropGlue(..)
339 | InstanceKind::Item(_)
340 | InstanceKind::Intrinsic(..)
341 | InstanceKind::ReifyShim(..)
342 | InstanceKind::Virtual(..)
343 | InstanceKind::VTableShim(..) => true,
344 }
345 }
346}
347
348fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
349 struct Visitor<'tcx> {
350 type_length: usize,
351 cache: FxHashMap<Ty<'tcx>, usize>,
352 }
353 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Visitor<'tcx> {
354 fn visit_ty(&mut self, t: Ty<'tcx>) {
355 if let Some(&value) = self.cache.get(&t) {
356 self.type_length += value;
357 return;
358 }
359
360 let prev = self.type_length;
361 self.type_length += 1;
362 t.super_visit_with(self);
363
364 if self.type_length > 16 {
366 self.cache.insert(t, self.type_length - prev);
367 }
368 }
369
370 fn visit_const(&mut self, ct: ty::Const<'tcx>) {
371 self.type_length += 1;
372 ct.super_visit_with(self);
373 }
374 }
375 let mut visitor = Visitor { type_length: 0, cache: Default::default() };
376 item.visit_with(&mut visitor);
377
378 visitor.type_length
379}
380
381impl<'tcx> fmt::Display for Instance<'tcx> {
382 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
383 ty::tls::with(|tcx| {
384 let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
385 let instance = tcx.lift(*self).expect("could not lift for printing");
386 instance.print(&mut p)?;
387 let s = p.into_buffer();
388 f.write_str(&s)
389 })
390 }
391}
392
393fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
401 let first_cor = cor_ty;
402 let ty::Coroutine(poll_def_id, proxy_args) = first_cor.kind() else {
403 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
404 };
405 let poll_def_id = *poll_def_id;
406 let mut child_ty = cor_ty;
407 loop {
408 if let ty::Coroutine(child_def, child_args) = child_ty.kind() {
409 cor_ty = child_ty;
410 if *child_def == poll_def_id {
411 child_ty = child_args.first().unwrap().expect_ty();
412 continue;
413 } else {
414 return Instance {
415 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
416 args: proxy_args,
417 };
418 }
419 } else {
420 let ty::Coroutine(_, child_args) = cor_ty.kind() else {
421 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
422 };
423 if first_cor != cor_ty {
424 return Instance {
425 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
426 args: proxy_args,
427 };
428 } else {
429 return Instance {
430 def: ty::InstanceKind::AsyncDropGlue(poll_def_id, cor_ty),
431 args: child_args,
432 };
433 }
434 }
435 }
436}
437
438impl<'tcx> Instance<'tcx> {
439 pub fn new_raw(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
448 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!(
449 !args.has_escaping_bound_vars(),
450 "args of instance {def_id:?} has escaping bound vars: {args:?}"
451 );
452 Instance { def: InstanceKind::Item(def_id), args }
453 }
454
455 pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
456 let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
457 ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
458 ty::GenericParamDefKind::Type { .. } => {
459 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has type parameters",
def_id))bug!("Instance::mono: {:?} has type parameters", def_id)
460 }
461 ty::GenericParamDefKind::Const { .. } => {
462 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has const parameters",
def_id))bug!("Instance::mono: {:?} has const parameters", def_id)
463 }
464 });
465
466 Instance::new_raw(def_id, args)
467 }
468
469 #[inline]
470 pub fn def_id(&self) -> DefId {
471 self.def.def_id()
472 }
473
474 x;#[instrument(level = "debug", skip(tcx), ret)]
500 pub fn try_resolve(
501 tcx: TyCtxt<'tcx>,
502 typing_env: ty::TypingEnv<'tcx>,
503 def_id: DefId,
504 args: GenericArgsRef<'tcx>,
505 ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
506 assert_matches!(
507 tcx.def_kind(def_id),
508 DefKind::Fn
509 | DefKind::AssocFn
510 | DefKind::Const { .. }
511 | DefKind::AssocConst { .. }
512 | DefKind::AnonConst
513 | DefKind::InlineConst
514 | DefKind::Static { .. }
515 | DefKind::Ctor(_, CtorKind::Fn)
516 | DefKind::Closure
517 | DefKind::SyntheticCoroutineBody,
518 "`Instance::try_resolve` should only be used to resolve instances of \
519 functions, statics, and consts; to resolve associated types, use \
520 `try_normalize_erasing_regions`."
521 );
522
523 if tcx.sess.opts.unstable_opts.enforce_type_length_limit
530 && !tcx.type_length_limit().value_within_limit(type_length(args))
531 {
532 return Ok(None);
533 }
534
535 tcx.resolve_instance_raw(
538 tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id, args))),
539 )
540 }
541
542 pub fn expect_resolve(
543 tcx: TyCtxt<'tcx>,
544 typing_env: ty::TypingEnv<'tcx>,
545 def_id: DefId,
546 args: GenericArgsRef<'tcx>,
547 span: Span,
548 ) -> Instance<'tcx> {
549 let span_or_local_def_span =
553 || if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
554
555 match ty::Instance::try_resolve(tcx, typing_env, def_id, args) {
556 Ok(Some(instance)) => instance,
557 Ok(None) => {
558 let type_length = type_length(args);
559 if !tcx.type_length_limit().value_within_limit(type_length) {
560 tcx.dcx().emit_fatal(error::TypeLengthLimit {
561 span: span_or_local_def_span(),
565 instance: Instance::new_raw(def_id, args),
566 type_length,
567 });
568 } else {
569 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!(
570 span_or_local_def_span(),
571 "failed to resolve instance for {}",
572 tcx.def_path_str_with_args(def_id, args)
573 )
574 }
575 }
576 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!(
577 span_or_local_def_span(),
578 "failed to resolve instance for {}: {instance:#?}",
579 tcx.def_path_str_with_args(def_id, args)
580 ),
581 }
582 }
583
584 pub fn resolve_for_fn_ptr(
585 tcx: TyCtxt<'tcx>,
586 typing_env: ty::TypingEnv<'tcx>,
587 def_id: DefId,
588 args: GenericArgsRef<'tcx>,
589 ) -> Option<Instance<'tcx>> {
590 {
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:590",
"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(590u32),
::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);
591 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:?}");
593 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
594 Instance::try_resolve(tcx, typing_env, def_id, args).ok().flatten().map(|mut resolved| {
595 match resolved.def {
596 InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
597 {
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:597",
"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(597u32),
::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]");
598 resolved.def = InstanceKind::ReifyShim(def, reason);
599 }
600 InstanceKind::Virtual(def_id, _) => {
601 {
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:601",
"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(601u32),
::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");
602 resolved.def = InstanceKind::ReifyShim(def_id, reason);
603 }
604 _ if tcx.sess.is_sanitizer_kcfi_enabled() => {
605 if tcx.is_closure_like(resolved.def_id()) {
607 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args }
611 } else if let Some(assoc) = tcx.opt_associated_item(def_id)
613 && let AssocContainer::Trait | AssocContainer::TraitImpl(Ok(_)) =
614 assoc.container
615 && tcx.is_dyn_compatible(assoc.container_id(tcx))
616 {
617 resolved.def = InstanceKind::ReifyShim(resolved.def_id(), reason)
620 }
621 }
622 _ => {}
623 }
624
625 resolved
626 })
627 }
628
629 pub fn expect_resolve_for_vtable(
630 tcx: TyCtxt<'tcx>,
631 typing_env: ty::TypingEnv<'tcx>,
632 def_id: DefId,
633 args: GenericArgsRef<'tcx>,
634 span: Span,
635 ) -> Instance<'tcx> {
636 {
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:636",
"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(636u32),
::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);
637 let fn_sig = tcx.fn_sig(def_id).instantiate_identity();
638 let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
639 && fn_sig.input(0).skip_binder().is_param(0)
640 && tcx.generics_of(def_id).has_self;
641
642 if is_vtable_shim {
643 {
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:643",
"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(643u32),
::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");
644 return Instance { def: InstanceKind::VTableShim(def_id), args };
645 }
646
647 let mut resolved = Instance::expect_resolve(tcx, typing_env, def_id, args, span);
648
649 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
650 match resolved.def {
651 InstanceKind::Item(def) => {
652 let needs_track_caller_shim = resolved.def.requires_caller_location(tcx)
662 && !tcx.should_inherit_track_caller(def)
665 && !#[allow(non_exhaustive_omitted_patterns)] match tcx.opt_associated_item(def) {
Some(ty::AssocItem { container: ty::AssocContainer::Trait, .. }) => true,
_ => false,
}matches!(
671 tcx.opt_associated_item(def),
672 Some(ty::AssocItem {
673 container: ty::AssocContainer::Trait,
674 ..
675 })
676 );
677 if needs_track_caller_shim {
678 if tcx.is_closure_like(def) {
679 {
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:679",
"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(679u32),
::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!(
680 " => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
681 def, def_id, args
682 );
683
684 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args };
688 } else {
689 {
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:689",
"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(689u32),
::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!(
690 " => vtable fn pointer created for function with #[track_caller]: {:?}",
691 def
692 );
693 resolved.def = InstanceKind::ReifyShim(def, reason);
694 }
695 }
696 }
697 InstanceKind::Virtual(def_id, _) => {
698 {
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:698",
"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(698u32),
::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");
699 resolved.def = InstanceKind::ReifyShim(def_id, reason)
700 }
701 _ => {}
702 }
703
704 resolved
705 }
706
707 pub fn resolve_closure(
708 tcx: TyCtxt<'tcx>,
709 def_id: DefId,
710 args: ty::GenericArgsRef<'tcx>,
711 requested_kind: ty::ClosureKind,
712 ) -> Instance<'tcx> {
713 let actual_kind = args.as_closure().kind();
714
715 match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
716 Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
717 _ => Instance::new_raw(def_id, args),
718 }
719 }
720
721 pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
722 let def_id = tcx.require_lang_item(LangItem::DropInPlace, DUMMY_SP);
723 let args = tcx.mk_args(&[ty.into()]);
724 Instance::expect_resolve(
725 tcx,
726 ty::TypingEnv::fully_monomorphized(),
727 def_id,
728 args,
729 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
730 )
731 }
732
733 pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
734 let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP);
735 let args = tcx.mk_args(&[ty.into()]);
736 Instance::expect_resolve(
737 tcx,
738 ty::TypingEnv::fully_monomorphized(),
739 def_id,
740 args,
741 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
742 )
743 }
744
745 pub fn resolve_async_drop_in_place_poll(
746 tcx: TyCtxt<'tcx>,
747 def_id: DefId,
748 ty: Ty<'tcx>,
749 ) -> ty::Instance<'tcx> {
750 let args = tcx.mk_args(&[ty.into()]);
751 Instance::expect_resolve(tcx, ty::TypingEnv::fully_monomorphized(), def_id, args, DUMMY_SP)
752 }
753
754 x;#[instrument(level = "debug", skip(tcx), ret)]
755 pub fn fn_once_adapter_instance(
756 tcx: TyCtxt<'tcx>,
757 closure_did: DefId,
758 args: ty::GenericArgsRef<'tcx>,
759 ) -> Instance<'tcx> {
760 let fn_once = tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
761 let call_once = tcx
762 .associated_items(fn_once)
763 .in_definition_order()
764 .find(|it| it.is_fn())
765 .unwrap()
766 .def_id;
767 let track_caller =
768 tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
769 let def = ty::InstanceKind::ClosureOnceShim { call_once, track_caller };
770
771 let self_ty = Ty::new_closure(tcx, closure_did, args);
772
773 let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
774 let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
775 let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
776
777 debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
778 Instance { def, args }
779 }
780
781 pub fn try_resolve_item_for_coroutine(
782 tcx: TyCtxt<'tcx>,
783 trait_item_id: DefId,
784 trait_id: DefId,
785 rcvr_args: ty::GenericArgsRef<'tcx>,
786 ) -> Option<Instance<'tcx>> {
787 let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
788 return None;
789 };
790 let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap();
791
792 let coroutine_callable_item = if tcx.is_lang_item(trait_id, LangItem::Future) {
793 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!(
794 coroutine_kind,
795 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
796 );
797 hir::LangItem::FuturePoll
798 } else if tcx.is_lang_item(trait_id, LangItem::Iterator) {
799 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!(
800 coroutine_kind,
801 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
802 );
803 hir::LangItem::IteratorNext
804 } else if tcx.is_lang_item(trait_id, LangItem::AsyncIterator) {
805 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!(
806 coroutine_kind,
807 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
808 );
809 hir::LangItem::AsyncIteratorPollNext
810 } else if tcx.is_lang_item(trait_id, LangItem::Coroutine) {
811 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(_));
812 hir::LangItem::CoroutineResume
813 } else {
814 return None;
815 };
816
817 if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
818 if tcx.is_async_drop_in_place_coroutine(coroutine_def_id) {
819 return Some(resolve_async_drop_poll(rcvr_args.type_at(0)));
820 }
821 let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
822 else {
823 crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
824 };
825
826 if args.as_coroutine().kind_ty() == id_args.as_coroutine().kind_ty() {
829 Some(Instance { def: ty::InstanceKind::Item(coroutine_def_id), args })
830 } else {
831 Some(Instance {
832 def: ty::InstanceKind::Item(
833 tcx.coroutine_by_move_body_def_id(coroutine_def_id),
834 ),
835 args,
836 })
837 }
838 } else {
839 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());
843 Some(Instance::new_raw(trait_item_id, rcvr_args))
844 }
845 }
846
847 fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
858 self.def.has_polymorphic_mir_body().then_some(self.args)
859 }
860
861 pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, &T>) -> T
862 where
863 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
864 {
865 let v = v.map_bound(|v| *v);
866 if let Some(args) = self.args_for_mir_body() {
867 v.instantiate(tcx, args)
868 } else {
869 v.instantiate_identity()
870 }
871 }
872
873 #[inline(always)]
874 pub fn instantiate_mir_and_normalize_erasing_regions<T>(
876 &self,
877 tcx: TyCtxt<'tcx>,
878 typing_env: ty::TypingEnv<'tcx>,
879 v: EarlyBinder<'tcx, T>,
880 ) -> T
881 where
882 T: TypeFoldable<TyCtxt<'tcx>>,
883 {
884 if let Some(args) = self.args_for_mir_body() {
885 tcx.instantiate_and_normalize_erasing_regions(args, typing_env, v)
886 } else {
887 tcx.normalize_erasing_regions(typing_env, v.instantiate_identity())
888 }
889 }
890
891 #[inline(always)]
892 pub fn try_instantiate_mir_and_normalize_erasing_regions<T>(
894 &self,
895 tcx: TyCtxt<'tcx>,
896 typing_env: ty::TypingEnv<'tcx>,
897 v: EarlyBinder<'tcx, T>,
898 ) -> Result<T, NormalizationError<'tcx>>
899 where
900 T: TypeFoldable<TyCtxt<'tcx>>,
901 {
902 if let Some(args) = self.args_for_mir_body() {
903 tcx.try_instantiate_and_normalize_erasing_regions(args, typing_env, v)
904 } else {
905 tcx.try_normalize_erasing_regions(typing_env, v.instantiate_identity())
911 }
912 }
913}
914
915fn needs_fn_once_adapter_shim(
916 actual_closure_kind: ty::ClosureKind,
917 trait_closure_kind: ty::ClosureKind,
918) -> Result<bool, ()> {
919 match (actual_closure_kind, trait_closure_kind) {
920 (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
921 | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
922 | (ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
923 Ok(false)
925 }
926 (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
927 Ok(false)
930 }
931 (ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
932 Ok(true)
940 }
941 (ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
942 }
943}
944
945#[derive(#[automatically_derived]
impl ::core::fmt::Debug for UnusedGenericParams {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UnusedGenericParams", &&self.0)
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for UnusedGenericParams { }Copy, #[automatically_derived]
impl ::core::clone::Clone for UnusedGenericParams {
#[inline]
fn clone(&self) -> UnusedGenericParams {
let _: ::core::clone::AssertParamIsClone<FiniteBitSet<u32>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for UnusedGenericParams {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<FiniteBitSet<u32>>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for UnusedGenericParams {
#[inline]
fn eq(&self, other: &UnusedGenericParams) -> bool { self.0 == other.0 }
}PartialEq, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for UnusedGenericParams {
fn decode(__decoder: &mut __D) -> Self {
UnusedGenericParams(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for UnusedGenericParams {
fn encode(&self, __encoder: &mut __E) {
match *self {
UnusedGenericParams(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for UnusedGenericParams {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
UnusedGenericParams(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
948pub struct UnusedGenericParams(FiniteBitSet<u32>);
949
950impl Default for UnusedGenericParams {
951 fn default() -> Self {
952 UnusedGenericParams::new_all_used()
953 }
954}
955
956impl UnusedGenericParams {
957 pub fn new_all_unused(amount: u32) -> Self {
958 let mut bitset = FiniteBitSet::new_empty();
959 bitset.set_range(0..amount);
960 Self(bitset)
961 }
962
963 pub fn new_all_used() -> Self {
964 Self(FiniteBitSet::new_empty())
965 }
966
967 pub fn mark_used(&mut self, idx: u32) {
968 self.0.clear(idx);
969 }
970
971 pub fn is_unused(&self, idx: u32) -> bool {
972 self.0.contains(idx).unwrap_or(false)
973 }
974
975 pub fn is_used(&self, idx: u32) -> bool {
976 !self.is_unused(idx)
977 }
978
979 pub fn all_used(&self) -> bool {
980 self.0.is_empty()
981 }
982
983 pub fn bits(&self) -> u32 {
984 self.0.0
985 }
986
987 pub fn from_bits(bits: u32) -> UnusedGenericParams {
988 UnusedGenericParams(FiniteBitSet(bits))
989 }
990}