1use std::fmt;
2
3use rustc_data_structures::assert_matches;
4use rustc_data_structures::fx::FxHashMap;
5use rustc_errors::ErrorGuaranteed;
6use rustc_hir as hir;
7use rustc_hir::def::{CtorKind, DefKind, Namespace};
8use rustc_hir::def_id::{CrateNum, DefId};
9use rustc_hir::lang_items::LangItem;
10use rustc_index::bit_set::FiniteBitSet;
11use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
12use rustc_span::def_id::LOCAL_CRATE;
13use rustc_span::{DUMMY_SP, Span, Symbol};
14use tracing::{debug, instrument};
15
16use crate::error;
17use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
18use crate::ty::normalize_erasing_regions::NormalizationError;
19use crate::ty::print::{FmtPrinter, Print};
20use crate::ty::{
21 self, AssocContainer, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable,
22 TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
23};
24
25#[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_receiver_is_total_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)]
34#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for Instance<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::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)]
35pub struct Instance<'tcx> {
36 pub def: InstanceKind<'tcx>,
37 pub args: GenericArgsRef<'tcx>,
38}
39
40#[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_receiver_is_total_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)]
46#[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_query_system::ich::StableHashingContext<'__ctx>>
for ReifyReason {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::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)]
47pub enum ReifyReason {
48 FnPtr,
56 Vtable,
60}
61
62#[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_receiver_is_total_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)]
63#[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_query_system::ich::StableHashingContext<'__ctx>>
for InstanceKind<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::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)]
64pub enum InstanceKind<'tcx> {
65 Item(DefId),
72
73 Intrinsic(DefId),
79
80 VTableShim(DefId),
86
87 ReifyShim(DefId, Option<ReifyReason>),
105
106 FnPtrShim(DefId, Ty<'tcx>),
110
111 Virtual(DefId, usize),
120
121 ClosureOnceShim { call_once: DefId, track_caller: bool },
128
129 ConstructCoroutineInClosureShim {
135 coroutine_closure_def_id: DefId,
136 receiver_by_ref: bool,
142 },
143
144 ThreadLocalShim(DefId),
148
149 FutureDropPollShim(DefId, Ty<'tcx>, Ty<'tcx>),
151
152 DropGlue(DefId, Option<Ty<'tcx>>),
158
159 CloneShim(DefId, Ty<'tcx>),
166
167 FnPtrAddrShim(DefId, Ty<'tcx>),
173
174 AsyncDropGlueCtorShim(DefId, Ty<'tcx>),
179
180 AsyncDropGlue(DefId, Ty<'tcx>),
185}
186
187impl<'tcx> Instance<'tcx> {
188 pub fn ty(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Ty<'tcx> {
191 let ty = tcx.type_of(self.def.def_id());
192 tcx.instantiate_and_normalize_erasing_regions(self.args, typing_env, ty)
193 }
194
195 pub fn upstream_monomorphization(&self, tcx: TyCtxt<'tcx>) -> Option<CrateNum> {
202 if self.def_id().is_local() {
205 return None;
206 }
207
208 if !tcx.sess.opts.share_generics()
212 && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_hir::attrs::InlineAttr::Never
215 {
216 return None;
217 }
218
219 self.args.non_erasable_generics().next()?;
221
222 if tcx.is_compiler_builtins(LOCAL_CRATE) {
224 return None;
225 }
226
227 match self.def {
228 InstanceKind::Item(def) => tcx
229 .upstream_monomorphizations_for(def)
230 .and_then(|monos| monos.get(&self.args).cloned()),
231 InstanceKind::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
232 InstanceKind::AsyncDropGlue(_, _) => None,
233 InstanceKind::FutureDropPollShim(_, _, _) => None,
234 InstanceKind::AsyncDropGlueCtorShim(_, _) => {
235 tcx.upstream_async_drop_glue_for(self.args)
236 }
237 _ => None,
238 }
239 }
240}
241
242impl<'tcx> InstanceKind<'tcx> {
243 #[inline]
244 pub fn def_id(self) -> DefId {
245 match self {
246 InstanceKind::Item(def_id)
247 | InstanceKind::VTableShim(def_id)
248 | InstanceKind::ReifyShim(def_id, _)
249 | InstanceKind::FnPtrShim(def_id, _)
250 | InstanceKind::Virtual(def_id, _)
251 | InstanceKind::Intrinsic(def_id)
252 | InstanceKind::ThreadLocalShim(def_id)
253 | InstanceKind::ClosureOnceShim { call_once: def_id, track_caller: _ }
254 | ty::InstanceKind::ConstructCoroutineInClosureShim {
255 coroutine_closure_def_id: def_id,
256 receiver_by_ref: _,
257 }
258 | InstanceKind::DropGlue(def_id, _)
259 | InstanceKind::CloneShim(def_id, _)
260 | InstanceKind::FnPtrAddrShim(def_id, _)
261 | InstanceKind::FutureDropPollShim(def_id, _, _)
262 | InstanceKind::AsyncDropGlue(def_id, _)
263 | InstanceKind::AsyncDropGlueCtorShim(def_id, _) => def_id,
264 }
265 }
266
267 pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
269 match self {
270 ty::InstanceKind::Item(def) => Some(def),
271 ty::InstanceKind::DropGlue(def_id, Some(_))
272 | InstanceKind::AsyncDropGlueCtorShim(def_id, _)
273 | InstanceKind::AsyncDropGlue(def_id, _)
274 | InstanceKind::FutureDropPollShim(def_id, ..)
275 | InstanceKind::ThreadLocalShim(def_id) => Some(def_id),
276 InstanceKind::VTableShim(..)
277 | InstanceKind::ReifyShim(..)
278 | InstanceKind::FnPtrShim(..)
279 | InstanceKind::Virtual(..)
280 | InstanceKind::Intrinsic(..)
281 | InstanceKind::ClosureOnceShim { .. }
282 | ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
283 | InstanceKind::DropGlue(..)
284 | InstanceKind::CloneShim(..)
285 | InstanceKind::FnPtrAddrShim(..) => None,
286 }
287 }
288
289 #[inline]
290 pub fn get_attrs(
291 &self,
292 tcx: TyCtxt<'tcx>,
293 attr: Symbol,
294 ) -> impl Iterator<Item = &'tcx hir::Attribute> {
295 tcx.get_attrs(self.def_id(), attr)
296 }
297
298 pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool {
304 use rustc_hir::definitions::DefPathData;
305 let def_id = match *self {
306 ty::InstanceKind::Item(def) => def,
307 ty::InstanceKind::DropGlue(_, Some(_)) => return false,
308 ty::InstanceKind::AsyncDropGlueCtorShim(_, ty) => return ty.is_coroutine(),
309 ty::InstanceKind::FutureDropPollShim(_, _, _) => return false,
310 ty::InstanceKind::AsyncDropGlue(_, _) => return false,
311 ty::InstanceKind::ThreadLocalShim(_) => return false,
312 _ => return true,
313 };
314 #[allow(non_exhaustive_omitted_patterns)] match tcx.def_key(def_id).disambiguated_data.data
{
DefPathData::Ctor | DefPathData::Closure => true,
_ => false,
}matches!(
315 tcx.def_key(def_id).disambiguated_data.data,
316 DefPathData::Ctor | DefPathData::Closure
317 )
318 }
319
320 pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
321 match *self {
322 InstanceKind::Item(def_id) | InstanceKind::Virtual(def_id, _) => {
323 tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
324 }
325 InstanceKind::ClosureOnceShim { call_once: _, track_caller } => track_caller,
326 _ => false,
327 }
328 }
329
330 pub fn has_polymorphic_mir_body(&self) -> bool {
337 match *self {
338 InstanceKind::CloneShim(..)
339 | InstanceKind::ThreadLocalShim(..)
340 | InstanceKind::FnPtrAddrShim(..)
341 | InstanceKind::FnPtrShim(..)
342 | InstanceKind::DropGlue(_, Some(_))
343 | InstanceKind::FutureDropPollShim(..)
344 | InstanceKind::AsyncDropGlue(_, _) => false,
345 InstanceKind::AsyncDropGlueCtorShim(_, _) => false,
346 InstanceKind::ClosureOnceShim { .. }
347 | InstanceKind::ConstructCoroutineInClosureShim { .. }
348 | InstanceKind::DropGlue(..)
349 | InstanceKind::Item(_)
350 | InstanceKind::Intrinsic(..)
351 | InstanceKind::ReifyShim(..)
352 | InstanceKind::Virtual(..)
353 | InstanceKind::VTableShim(..) => true,
354 }
355 }
356}
357
358fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
359 struct Visitor<'tcx> {
360 type_length: usize,
361 cache: FxHashMap<Ty<'tcx>, usize>,
362 }
363 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Visitor<'tcx> {
364 fn visit_ty(&mut self, t: Ty<'tcx>) {
365 if let Some(&value) = self.cache.get(&t) {
366 self.type_length += value;
367 return;
368 }
369
370 let prev = self.type_length;
371 self.type_length += 1;
372 t.super_visit_with(self);
373
374 if self.type_length > 16 {
376 self.cache.insert(t, self.type_length - prev);
377 }
378 }
379
380 fn visit_const(&mut self, ct: ty::Const<'tcx>) {
381 self.type_length += 1;
382 ct.super_visit_with(self);
383 }
384 }
385 let mut visitor = Visitor { type_length: 0, cache: Default::default() };
386 item.visit_with(&mut visitor);
387
388 visitor.type_length
389}
390
391impl<'tcx> fmt::Display for Instance<'tcx> {
392 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
393 ty::tls::with(|tcx| {
394 let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
395 let instance = tcx.lift(*self).expect("could not lift for printing");
396 instance.print(&mut p)?;
397 let s = p.into_buffer();
398 f.write_str(&s)
399 })
400 }
401}
402
403fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
411 let first_cor = cor_ty;
412 let ty::Coroutine(poll_def_id, proxy_args) = first_cor.kind() else {
413 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
414 };
415 let poll_def_id = *poll_def_id;
416 let mut child_ty = cor_ty;
417 loop {
418 if let ty::Coroutine(child_def, child_args) = child_ty.kind() {
419 cor_ty = child_ty;
420 if *child_def == poll_def_id {
421 child_ty = child_args.first().unwrap().expect_ty();
422 continue;
423 } else {
424 return Instance {
425 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
426 args: proxy_args,
427 };
428 }
429 } else {
430 let ty::Coroutine(_, child_args) = cor_ty.kind() else {
431 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
432 };
433 if first_cor != cor_ty {
434 return Instance {
435 def: ty::InstanceKind::FutureDropPollShim(poll_def_id, first_cor, cor_ty),
436 args: proxy_args,
437 };
438 } else {
439 return Instance {
440 def: ty::InstanceKind::AsyncDropGlue(poll_def_id, cor_ty),
441 args: child_args,
442 };
443 }
444 }
445 }
446}
447
448impl<'tcx> Instance<'tcx> {
449 pub fn new_raw(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
458 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!(
459 !args.has_escaping_bound_vars(),
460 "args of instance {def_id:?} has escaping bound vars: {args:?}"
461 );
462 Instance { def: InstanceKind::Item(def_id), args }
463 }
464
465 pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
466 let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
467 ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
468 ty::GenericParamDefKind::Type { .. } => {
469 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has type parameters",
def_id))bug!("Instance::mono: {:?} has type parameters", def_id)
470 }
471 ty::GenericParamDefKind::Const { .. } => {
472 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has const parameters",
def_id))bug!("Instance::mono: {:?} has const parameters", def_id)
473 }
474 });
475
476 Instance::new_raw(def_id, args)
477 }
478
479 #[inline]
480 pub fn def_id(&self) -> DefId {
481 self.def.def_id()
482 }
483
484 x;#[instrument(level = "debug", skip(tcx), ret)]
510 pub fn try_resolve(
511 tcx: TyCtxt<'tcx>,
512 typing_env: ty::TypingEnv<'tcx>,
513 def_id: DefId,
514 args: GenericArgsRef<'tcx>,
515 ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
516 assert_matches!(
517 tcx.def_kind(def_id),
518 DefKind::Fn
519 | DefKind::AssocFn
520 | DefKind::Const
521 | DefKind::AssocConst
522 | DefKind::AnonConst
523 | DefKind::InlineConst
524 | DefKind::Static { .. }
525 | DefKind::Ctor(_, CtorKind::Fn)
526 | DefKind::Closure
527 | DefKind::SyntheticCoroutineBody,
528 "`Instance::try_resolve` should only be used to resolve instances of \
529 functions, statics, and consts; to resolve associated types, use \
530 `try_normalize_erasing_regions`."
531 );
532
533 if tcx.sess.opts.unstable_opts.enforce_type_length_limit
540 && !tcx.type_length_limit().value_within_limit(type_length(args))
541 {
542 return Ok(None);
543 }
544
545 tcx.resolve_instance_raw(
548 tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id, args))),
549 )
550 }
551
552 pub fn expect_resolve(
553 tcx: TyCtxt<'tcx>,
554 typing_env: ty::TypingEnv<'tcx>,
555 def_id: DefId,
556 args: GenericArgsRef<'tcx>,
557 span: Span,
558 ) -> Instance<'tcx> {
559 let span_or_local_def_span =
563 || if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
564
565 match ty::Instance::try_resolve(tcx, typing_env, def_id, args) {
566 Ok(Some(instance)) => instance,
567 Ok(None) => {
568 let type_length = type_length(args);
569 if !tcx.type_length_limit().value_within_limit(type_length) {
570 tcx.dcx().emit_fatal(error::TypeLengthLimit {
571 span: span_or_local_def_span(),
575 instance: Instance::new_raw(def_id, args),
576 type_length,
577 });
578 } else {
579 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!(
580 span_or_local_def_span(),
581 "failed to resolve instance for {}",
582 tcx.def_path_str_with_args(def_id, args)
583 )
584 }
585 }
586 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!(
587 span_or_local_def_span(),
588 "failed to resolve instance for {}: {instance:#?}",
589 tcx.def_path_str_with_args(def_id, args)
590 ),
591 }
592 }
593
594 pub fn resolve_for_fn_ptr(
595 tcx: TyCtxt<'tcx>,
596 typing_env: ty::TypingEnv<'tcx>,
597 def_id: DefId,
598 args: GenericArgsRef<'tcx>,
599 ) -> Option<Instance<'tcx>> {
600 {
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:600",
"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(600u32),
::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);
601 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:?}");
603 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
604 Instance::try_resolve(tcx, typing_env, def_id, args).ok().flatten().map(|mut resolved| {
605 match resolved.def {
606 InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
607 {
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:607",
"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(607u32),
::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]");
608 resolved.def = InstanceKind::ReifyShim(def, reason);
609 }
610 InstanceKind::Virtual(def_id, _) => {
611 {
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:611",
"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(611u32),
::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");
612 resolved.def = InstanceKind::ReifyShim(def_id, reason);
613 }
614 _ if tcx.sess.is_sanitizer_kcfi_enabled() => {
615 if tcx.is_closure_like(resolved.def_id()) {
617 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args }
621 } else if let Some(assoc) = tcx.opt_associated_item(def_id)
623 && let AssocContainer::Trait | AssocContainer::TraitImpl(Ok(_)) =
624 assoc.container
625 && tcx.is_dyn_compatible(assoc.container_id(tcx))
626 {
627 resolved.def = InstanceKind::ReifyShim(resolved.def_id(), reason)
630 }
631 }
632 _ => {}
633 }
634
635 resolved
636 })
637 }
638
639 pub fn expect_resolve_for_vtable(
640 tcx: TyCtxt<'tcx>,
641 typing_env: ty::TypingEnv<'tcx>,
642 def_id: DefId,
643 args: GenericArgsRef<'tcx>,
644 span: Span,
645 ) -> Instance<'tcx> {
646 {
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:646",
"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(646u32),
::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);
647 let fn_sig = tcx.fn_sig(def_id).instantiate_identity();
648 let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
649 && fn_sig.input(0).skip_binder().is_param(0)
650 && tcx.generics_of(def_id).has_self;
651
652 if is_vtable_shim {
653 {
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:653",
"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(653u32),
::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");
654 return Instance { def: InstanceKind::VTableShim(def_id), args };
655 }
656
657 let mut resolved = Instance::expect_resolve(tcx, typing_env, def_id, args, span);
658
659 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
660 match resolved.def {
661 InstanceKind::Item(def) => {
662 let needs_track_caller_shim = resolved.def.requires_caller_location(tcx)
672 && !tcx.should_inherit_track_caller(def)
675 && !#[allow(non_exhaustive_omitted_patterns)] match tcx.opt_associated_item(def) {
Some(ty::AssocItem { container: ty::AssocContainer::Trait, .. }) => true,
_ => false,
}matches!(
681 tcx.opt_associated_item(def),
682 Some(ty::AssocItem {
683 container: ty::AssocContainer::Trait,
684 ..
685 })
686 );
687 if needs_track_caller_shim {
688 if tcx.is_closure_like(def) {
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 closure with #[track_caller]: {0:?} for method {1:?} {2:?}",
def, def_id, args) as &dyn Value))])
});
} else { ; }
};debug!(
690 " => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
691 def, def_id, args
692 );
693
694 resolved = Instance { def: InstanceKind::ReifyShim(def_id, reason), args };
698 } else {
699 {
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:699",
"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(699u32),
::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!(
700 " => vtable fn pointer created for function with #[track_caller]: {:?}",
701 def
702 );
703 resolved.def = InstanceKind::ReifyShim(def, reason);
704 }
705 }
706 }
707 InstanceKind::Virtual(def_id, _) => {
708 {
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:708",
"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(708u32),
::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");
709 resolved.def = InstanceKind::ReifyShim(def_id, reason)
710 }
711 _ => {}
712 }
713
714 resolved
715 }
716
717 pub fn resolve_closure(
718 tcx: TyCtxt<'tcx>,
719 def_id: DefId,
720 args: ty::GenericArgsRef<'tcx>,
721 requested_kind: ty::ClosureKind,
722 ) -> Instance<'tcx> {
723 let actual_kind = args.as_closure().kind();
724
725 match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
726 Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
727 _ => Instance::new_raw(def_id, args),
728 }
729 }
730
731 pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
732 let def_id = tcx.require_lang_item(LangItem::DropInPlace, 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(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
744 let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP);
745 let args = tcx.mk_args(&[ty.into()]);
746 Instance::expect_resolve(
747 tcx,
748 ty::TypingEnv::fully_monomorphized(),
749 def_id,
750 args,
751 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
752 )
753 }
754
755 pub fn resolve_async_drop_in_place_poll(
756 tcx: TyCtxt<'tcx>,
757 def_id: DefId,
758 ty: Ty<'tcx>,
759 ) -> ty::Instance<'tcx> {
760 let args = tcx.mk_args(&[ty.into()]);
761 Instance::expect_resolve(tcx, ty::TypingEnv::fully_monomorphized(), def_id, args, DUMMY_SP)
762 }
763
764 x;#[instrument(level = "debug", skip(tcx), ret)]
765 pub fn fn_once_adapter_instance(
766 tcx: TyCtxt<'tcx>,
767 closure_did: DefId,
768 args: ty::GenericArgsRef<'tcx>,
769 ) -> Instance<'tcx> {
770 let fn_once = tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
771 let call_once = tcx
772 .associated_items(fn_once)
773 .in_definition_order()
774 .find(|it| it.is_fn())
775 .unwrap()
776 .def_id;
777 let track_caller =
778 tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
779 let def = ty::InstanceKind::ClosureOnceShim { call_once, track_caller };
780
781 let self_ty = Ty::new_closure(tcx, closure_did, args);
782
783 let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
784 let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
785 let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
786
787 debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
788 Instance { def, args }
789 }
790
791 pub fn try_resolve_item_for_coroutine(
792 tcx: TyCtxt<'tcx>,
793 trait_item_id: DefId,
794 trait_id: DefId,
795 rcvr_args: ty::GenericArgsRef<'tcx>,
796 ) -> Option<Instance<'tcx>> {
797 let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
798 return None;
799 };
800 let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap();
801
802 let coroutine_callable_item = if tcx.is_lang_item(trait_id, LangItem::Future) {
803 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!(
804 coroutine_kind,
805 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
806 );
807 hir::LangItem::FuturePoll
808 } else if tcx.is_lang_item(trait_id, LangItem::Iterator) {
809 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!(
810 coroutine_kind,
811 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
812 );
813 hir::LangItem::IteratorNext
814 } else if tcx.is_lang_item(trait_id, LangItem::AsyncIterator) {
815 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!(
816 coroutine_kind,
817 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
818 );
819 hir::LangItem::AsyncIteratorPollNext
820 } else if tcx.is_lang_item(trait_id, LangItem::Coroutine) {
821 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(_));
822 hir::LangItem::CoroutineResume
823 } else {
824 return None;
825 };
826
827 if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
828 if tcx.is_async_drop_in_place_coroutine(coroutine_def_id) {
829 return Some(resolve_async_drop_poll(rcvr_args.type_at(0)));
830 }
831 let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
832 else {
833 crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
834 };
835
836 if args.as_coroutine().kind_ty() == id_args.as_coroutine().kind_ty() {
839 Some(Instance { def: ty::InstanceKind::Item(coroutine_def_id), args })
840 } else {
841 Some(Instance {
842 def: ty::InstanceKind::Item(
843 tcx.coroutine_by_move_body_def_id(coroutine_def_id),
844 ),
845 args,
846 })
847 }
848 } else {
849 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());
853 Some(Instance::new_raw(trait_item_id, rcvr_args))
854 }
855 }
856
857 fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
868 self.def.has_polymorphic_mir_body().then_some(self.args)
869 }
870
871 pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, &T>) -> T
872 where
873 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
874 {
875 let v = v.map_bound(|v| *v);
876 if let Some(args) = self.args_for_mir_body() {
877 v.instantiate(tcx, args)
878 } else {
879 v.instantiate_identity()
880 }
881 }
882
883 #[inline(always)]
884 pub fn instantiate_mir_and_normalize_erasing_regions<T>(
886 &self,
887 tcx: TyCtxt<'tcx>,
888 typing_env: ty::TypingEnv<'tcx>,
889 v: EarlyBinder<'tcx, T>,
890 ) -> T
891 where
892 T: TypeFoldable<TyCtxt<'tcx>>,
893 {
894 if let Some(args) = self.args_for_mir_body() {
895 tcx.instantiate_and_normalize_erasing_regions(args, typing_env, v)
896 } else {
897 tcx.normalize_erasing_regions(typing_env, v.instantiate_identity())
898 }
899 }
900
901 #[inline(always)]
902 pub fn try_instantiate_mir_and_normalize_erasing_regions<T>(
904 &self,
905 tcx: TyCtxt<'tcx>,
906 typing_env: ty::TypingEnv<'tcx>,
907 v: EarlyBinder<'tcx, T>,
908 ) -> Result<T, NormalizationError<'tcx>>
909 where
910 T: TypeFoldable<TyCtxt<'tcx>>,
911 {
912 if let Some(args) = self.args_for_mir_body() {
913 tcx.try_instantiate_and_normalize_erasing_regions(args, typing_env, v)
914 } else {
915 tcx.try_normalize_erasing_regions(typing_env, v.instantiate_identity())
921 }
922 }
923}
924
925fn needs_fn_once_adapter_shim(
926 actual_closure_kind: ty::ClosureKind,
927 trait_closure_kind: ty::ClosureKind,
928) -> Result<bool, ()> {
929 match (actual_closure_kind, trait_closure_kind) {
930 (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
931 | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
932 | (ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
933 Ok(false)
935 }
936 (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
937 Ok(false)
940 }
941 (ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
942 Ok(true)
950 }
951 (ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
952 }
953}
954
955#[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_receiver_is_total_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_query_system::ich::StableHashingContext<'__ctx>>
for UnusedGenericParams {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
UnusedGenericParams(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
958pub struct UnusedGenericParams(FiniteBitSet<u32>);
959
960impl Default for UnusedGenericParams {
961 fn default() -> Self {
962 UnusedGenericParams::new_all_used()
963 }
964}
965
966impl UnusedGenericParams {
967 pub fn new_all_unused(amount: u32) -> Self {
968 let mut bitset = FiniteBitSet::new_empty();
969 bitset.set_range(0..amount);
970 Self(bitset)
971 }
972
973 pub fn new_all_used() -> Self {
974 Self(FiniteBitSet::new_empty())
975 }
976
977 pub fn mark_used(&mut self, idx: u32) {
978 self.0.clear(idx);
979 }
980
981 pub fn is_unused(&self, idx: u32) -> bool {
982 self.0.contains(idx).unwrap_or(false)
983 }
984
985 pub fn is_used(&self, idx: u32) -> bool {
986 !self.is_unused(idx)
987 }
988
989 pub fn all_used(&self) -> bool {
990 self.0.is_empty()
991 }
992
993 pub fn bits(&self) -> u32 {
994 self.0.0
995 }
996
997 pub fn from_bits(bits: u32) -> UnusedGenericParams {
998 UnusedGenericParams(FiniteBitSet(bits))
999 }
1000}