1use std::{assert_matches, fmt};
2
3use rustc_data_structures::fx::FxHashMap;
4use rustc_errors::ErrorGuaranteed;
5use rustc_hir as hir;
6use rustc_hir::def::{CtorKind, DefKind, Namespace};
7use rustc_hir::def_id::{CrateNum, DefId};
8use rustc_hir::lang_items::LangItem;
9use rustc_macros::{Lift, StableHash, TyDecodable, TyEncodable};
10use rustc_span::def_id::LOCAL_CRATE;
11use rustc_span::{DUMMY_SP, Span};
12use tracing::{debug, instrument};
13
14use crate::error;
15use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
16use crate::ty::normalize_erasing_regions::NormalizationError;
17use crate::ty::print::{FmtPrinter, Print};
18use crate::ty::{
19 self, AssocContainer, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable,
20 TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
21};
22
23#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for Instance<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Instance<'tcx> {
#[inline]
fn clone(&self) -> Instance<'tcx> {
let _: ::core::clone::AssertParamIsClone<InstanceKind<'tcx>>;
let _: ::core::clone::AssertParamIsClone<GenericArgsRef<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for Instance<'tcx> {
#[inline]
fn eq(&self, other: &Instance<'tcx>) -> bool {
self.def == other.def && self.args == other.args
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for Instance<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<InstanceKind<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<GenericArgsRef<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for Instance<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.def, state);
::core::hash::Hash::hash(&self.args, state)
}
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Instance<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Instance",
"def", &self.def, "args", &&self.args)
}
}Debug, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for Instance<'tcx> {
fn encode(&self, __encoder: &mut __E) {
match *self {
Instance { def: ref __binding_0, args: ref __binding_1 } =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for Instance<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
Instance {
def: ::rustc_serialize::Decodable::decode(__decoder),
args: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
32#[derive(const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
Instance<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Instance { def: ref __binding_0, args: ref __binding_1 } =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, '__lifted>
::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
for Instance<'tcx> {
type Lifted = Instance<'__lifted>;
fn lift_to_interner(self,
__tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
-> Instance<'__lifted> {
match self {
Instance { def: __binding_0, args: __binding_1 } => {
Instance {
def: __tcx.lift(__binding_0),
args: __tcx.lift(__binding_1),
}
}
}
}
}
};Lift, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for Instance<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
Instance { def: __binding_0, args: __binding_1 } => {
Instance {
def: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
args: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
Instance { def: __binding_0, args: __binding_1 } => {
Instance {
def: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
args: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for Instance<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
Instance { def: ref __binding_0, args: ref __binding_1 } =>
{
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
33pub struct Instance<'tcx> {
34 pub def: InstanceKind<'tcx>,
35 pub args: GenericArgsRef<'tcx>,
36}
37
38#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReifyReason { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ReifyReason {
#[inline]
fn clone(&self) -> ReifyReason { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ReifyReason {
#[inline]
fn eq(&self, other: &ReifyReason) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ReifyReason {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for ReifyReason {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for ReifyReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ReifyReason::FnPtr => "FnPtr",
ReifyReason::Vtable => "Vtable",
})
}
}Debug)]
44#[derive(const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ReifyReason {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ReifyReason::FnPtr => { 0usize }
ReifyReason::Vtable => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ReifyReason::FnPtr => {}
ReifyReason::Vtable => {}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ReifyReason {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { ReifyReason::FnPtr }
1usize => { ReifyReason::Vtable }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ReifyReason`, expected 0..2, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ReifyReason
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
ReifyReason::FnPtr => {}
ReifyReason::Vtable => {}
}
}
}
};StableHash)]
45pub enum ReifyReason {
46 FnPtr,
54 Vtable,
58}
59
60#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for InstanceKind<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for InstanceKind<'tcx> {
#[inline]
fn clone(&self) -> InstanceKind<'tcx> {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<ShimKind<'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::LlvmIntrinsic(__self_0),
InstanceKind::LlvmIntrinsic(__arg1_0)) =>
__self_0 == __arg1_0,
(InstanceKind::Virtual(__self_0, __self_1),
InstanceKind::Virtual(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(InstanceKind::Shim(__self_0), InstanceKind::Shim(__arg1_0))
=> __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for InstanceKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<ShimKind<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for InstanceKind<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
InstanceKind::Item(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InstanceKind::Intrinsic(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InstanceKind::LlvmIntrinsic(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InstanceKind::Virtual(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
InstanceKind::Shim(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for InstanceKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
InstanceKind::Item(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Item",
&__self_0),
InstanceKind::Intrinsic(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Intrinsic", &__self_0),
InstanceKind::LlvmIntrinsic(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"LlvmIntrinsic", &__self_0),
InstanceKind::Virtual(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"Virtual", __self_0, &__self_1),
InstanceKind::Shim(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Shim",
&__self_0),
}
}
}Debug)]
61#[derive(const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for InstanceKind<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
InstanceKind::Item(ref __binding_0) => { 0usize }
InstanceKind::Intrinsic(ref __binding_0) => { 1usize }
InstanceKind::LlvmIntrinsic(ref __binding_0) => { 2usize }
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
3usize
}
InstanceKind::Shim(ref __binding_0) => { 4usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
InstanceKind::Item(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InstanceKind::Intrinsic(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InstanceKind::LlvmIntrinsic(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
InstanceKind::Shim(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for InstanceKind<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
InstanceKind::Item(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
InstanceKind::Intrinsic(::rustc_serialize::Decodable::decode(__decoder))
}
2usize => {
InstanceKind::LlvmIntrinsic(::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
InstanceKind::Virtual(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
InstanceKind::Shim(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InstanceKind`, expected 0..5, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
InstanceKind<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
InstanceKind::Item(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
InstanceKind::Intrinsic(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
InstanceKind::LlvmIntrinsic(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
InstanceKind::Shim(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for InstanceKind<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
InstanceKind::Item(__binding_0) => {
InstanceKind::Item(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
InstanceKind::Intrinsic(__binding_0) => {
InstanceKind::Intrinsic(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
InstanceKind::LlvmIntrinsic(__binding_0) => {
InstanceKind::LlvmIntrinsic(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
InstanceKind::Virtual(__binding_0, __binding_1) => {
InstanceKind::Virtual(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
InstanceKind::Shim(__binding_0) => {
InstanceKind::Shim(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
InstanceKind::Item(__binding_0) => {
InstanceKind::Item(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
InstanceKind::Intrinsic(__binding_0) => {
InstanceKind::Intrinsic(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
InstanceKind::LlvmIntrinsic(__binding_0) => {
InstanceKind::LlvmIntrinsic(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
InstanceKind::Virtual(__binding_0, __binding_1) => {
InstanceKind::Virtual(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
InstanceKind::Shim(__binding_0) => {
InstanceKind::Shim(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for InstanceKind<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
InstanceKind::Item(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
InstanceKind::Intrinsic(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
InstanceKind::LlvmIntrinsic(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
InstanceKind::Virtual(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
InstanceKind::Shim(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable, const _: () =
{
impl<'tcx, '__lifted>
::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
for InstanceKind<'tcx> {
type Lifted = InstanceKind<'__lifted>;
fn lift_to_interner(self,
__tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
-> InstanceKind<'__lifted> {
match self {
InstanceKind::Item(__binding_0) => {
InstanceKind::Item(__tcx.lift(__binding_0))
}
InstanceKind::Intrinsic(__binding_0) => {
InstanceKind::Intrinsic(__tcx.lift(__binding_0))
}
InstanceKind::LlvmIntrinsic(__binding_0) => {
InstanceKind::LlvmIntrinsic(__tcx.lift(__binding_0))
}
InstanceKind::Virtual(__binding_0, __binding_1) => {
InstanceKind::Virtual(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
InstanceKind::Shim(__binding_0) => {
InstanceKind::Shim(__tcx.lift(__binding_0))
}
}
}
}
};Lift)]
62pub enum InstanceKind<'tcx> {
63 Item(DefId),
70
71 Intrinsic(DefId),
77
78 LlvmIntrinsic(DefId),
84
85 Virtual(DefId, usize),
94
95 Shim(ShimKind<'tcx>),
96}
97
98#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ShimKind<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ShimKind<'tcx> {
#[inline]
fn clone(&self) -> ShimKind<'tcx> {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<Option<ReifyReason>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Option<Ty<'tcx>>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ShimKind<'tcx> {
#[inline]
fn eq(&self, other: &ShimKind<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ShimKind::VTable(__self_0), ShimKind::VTable(__arg1_0)) =>
__self_0 == __arg1_0,
(ShimKind::Reify(__self_0, __self_1),
ShimKind::Reify(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::FnPtr(__self_0, __self_1),
ShimKind::FnPtr(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::ClosureOnce {
call_once: __self_0,
closure: __self_1,
track_caller: __self_2 }, ShimKind::ClosureOnce {
call_once: __arg1_0,
closure: __arg1_1,
track_caller: __arg1_2 }) =>
__self_2 == __arg1_2 && __self_0 == __arg1_0 &&
__self_1 == __arg1_1,
(ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __self_0,
receiver_by_ref: __self_1 },
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __arg1_0,
receiver_by_ref: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(ShimKind::ThreadLocal(__self_0),
ShimKind::ThreadLocal(__arg1_0)) => __self_0 == __arg1_0,
(ShimKind::FutureDropPoll(__self_0, __self_1, __self_2),
ShimKind::FutureDropPoll(__arg1_0, __arg1_1, __arg1_2)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
(ShimKind::DropGlue(__self_0, __self_1),
ShimKind::DropGlue(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::Clone(__self_0, __self_1),
ShimKind::Clone(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::FnPtrAddr(__self_0, __self_1),
ShimKind::FnPtrAddr(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::AsyncDropGlueCtor(__self_0, __self_1),
ShimKind::AsyncDropGlueCtor(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ShimKind::AsyncDropGlue(__self_0, __self_1),
ShimKind::AsyncDropGlue(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ShimKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<Option<ReifyReason>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for ShimKind<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
ShimKind::VTable(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
ShimKind::Reify(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::FnPtr(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::ClosureOnce {
call_once: __self_0, closure: __self_1, track_caller: __self_2
} => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __self_0, receiver_by_ref: __self_1
} => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::ThreadLocal(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
ShimKind::FutureDropPoll(__self_0, __self_1, __self_2) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
ShimKind::DropGlue(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::Clone(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::FnPtrAddr(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::AsyncDropGlueCtor(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ShimKind::AsyncDropGlue(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
}
}
}Hash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ShimKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ShimKind::VTable(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "VTable",
&__self_0),
ShimKind::Reify(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Reify",
__self_0, &__self_1),
ShimKind::FnPtr(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "FnPtr",
__self_0, &__self_1),
ShimKind::ClosureOnce {
call_once: __self_0, closure: __self_1, track_caller: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"ClosureOnce", "call_once", __self_0, "closure", __self_1,
"track_caller", &__self_2),
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __self_0, receiver_by_ref: __self_1
} =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ConstructCoroutineInClosure", "coroutine_closure_def_id",
__self_0, "receiver_by_ref", &__self_1),
ShimKind::ThreadLocal(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ThreadLocal", &__self_0),
ShimKind::FutureDropPoll(__self_0, __self_1, __self_2) =>
::core::fmt::Formatter::debug_tuple_field3_finish(f,
"FutureDropPoll", __self_0, __self_1, &__self_2),
ShimKind::DropGlue(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DropGlue", __self_0, &__self_1),
ShimKind::Clone(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Clone",
__self_0, &__self_1),
ShimKind::FnPtrAddr(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FnPtrAddr", __self_0, &__self_1),
ShimKind::AsyncDropGlueCtor(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AsyncDropGlueCtor", __self_0, &__self_1),
ShimKind::AsyncDropGlue(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AsyncDropGlue", __self_0, &__self_1),
}
}
}Debug)]
99#[derive(const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ShimKind<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ShimKind::VTable(ref __binding_0) => { 0usize }
ShimKind::Reify(ref __binding_0, ref __binding_1) => {
1usize
}
ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
2usize
}
ShimKind::ClosureOnce {
call_once: ref __binding_0,
closure: ref __binding_1,
track_caller: ref __binding_2 } => {
3usize
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
4usize
}
ShimKind::ThreadLocal(ref __binding_0) => { 5usize }
ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
ref __binding_2) => {
6usize
}
ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
7usize
}
ShimKind::Clone(ref __binding_0, ref __binding_1) => {
8usize
}
ShimKind::FnPtrAddr(ref __binding_0, ref __binding_1) => {
9usize
}
ShimKind::AsyncDropGlueCtor(ref __binding_0,
ref __binding_1) => {
10usize
}
ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
{
11usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ShimKind::VTable(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ShimKind::Reify(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::ClosureOnce {
call_once: ref __binding_0,
closure: ref __binding_1,
track_caller: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::ThreadLocal(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
ref __binding_2) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::Clone(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::FnPtrAddr(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::AsyncDropGlueCtor(ref __binding_0,
ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ShimKind<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ShimKind::VTable(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
ShimKind::Reify(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
2usize => {
ShimKind::FnPtr(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
ShimKind::ClosureOnce {
call_once: ::rustc_serialize::Decodable::decode(__decoder),
closure: ::rustc_serialize::Decodable::decode(__decoder),
track_caller: ::rustc_serialize::Decodable::decode(__decoder),
}
}
4usize => {
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ::rustc_serialize::Decodable::decode(__decoder),
receiver_by_ref: ::rustc_serialize::Decodable::decode(__decoder),
}
}
5usize => {
ShimKind::ThreadLocal(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
ShimKind::FutureDropPoll(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
7usize => {
ShimKind::DropGlue(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
8usize => {
ShimKind::Clone(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
9usize => {
ShimKind::FnPtrAddr(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
10usize => {
ShimKind::AsyncDropGlueCtor(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
11usize => {
ShimKind::AsyncDropGlue(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ShimKind`, expected 0..12, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ShimKind<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
ShimKind::VTable(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ShimKind::Reify(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::ClosureOnce {
call_once: ref __binding_0,
closure: ref __binding_1,
track_caller: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::ThreadLocal(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
ref __binding_2) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::Clone(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::FnPtrAddr(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::AsyncDropGlueCtor(ref __binding_0,
ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for ShimKind<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
ShimKind::VTable(__binding_0) => {
ShimKind::VTable(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
ShimKind::Reify(__binding_0, __binding_1) => {
ShimKind::Reify(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::FnPtr(__binding_0, __binding_1) => {
ShimKind::FnPtr(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::ClosureOnce {
call_once: __binding_0,
closure: __binding_1,
track_caller: __binding_2 } => {
ShimKind::ClosureOnce {
call_once: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
closure: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
track_caller: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
__folder)?,
}
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
receiver_by_ref: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
ShimKind::ThreadLocal(__binding_0) => {
ShimKind::ThreadLocal(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
ShimKind::FutureDropPoll(__binding_0, __binding_1,
__binding_2) => {
ShimKind::FutureDropPoll(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
__folder)?)
}
ShimKind::DropGlue(__binding_0, __binding_1) => {
ShimKind::DropGlue(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::Clone(__binding_0, __binding_1) => {
ShimKind::Clone(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::FnPtrAddr(__binding_0, __binding_1) => {
ShimKind::FnPtrAddr(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlueCtor(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlue(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
ShimKind::VTable(__binding_0) => {
ShimKind::VTable(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
ShimKind::Reify(__binding_0, __binding_1) => {
ShimKind::Reify(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::FnPtr(__binding_0, __binding_1) => {
ShimKind::FnPtr(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::ClosureOnce {
call_once: __binding_0,
closure: __binding_1,
track_caller: __binding_2 } => {
ShimKind::ClosureOnce {
call_once: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
closure: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
track_caller: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
__folder),
}
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
receiver_by_ref: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
ShimKind::ThreadLocal(__binding_0) => {
ShimKind::ThreadLocal(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
ShimKind::FutureDropPoll(__binding_0, __binding_1,
__binding_2) => {
ShimKind::FutureDropPoll(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
__folder))
}
ShimKind::DropGlue(__binding_0, __binding_1) => {
ShimKind::DropGlue(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::Clone(__binding_0, __binding_1) => {
ShimKind::Clone(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::FnPtrAddr(__binding_0, __binding_1) => {
ShimKind::FnPtrAddr(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlueCtor(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlue(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for ShimKind<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ShimKind::VTable(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::Reify(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::FnPtr(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::ClosureOnce {
call_once: ref __binding_0,
closure: ref __binding_1,
track_caller: ref __binding_2 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: ref __binding_0,
receiver_by_ref: ref __binding_1 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::ThreadLocal(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::FutureDropPoll(ref __binding_0, ref __binding_1,
ref __binding_2) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::DropGlue(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::Clone(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::FnPtrAddr(ref __binding_0, ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::AsyncDropGlueCtor(ref __binding_0,
ref __binding_1) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
ShimKind::AsyncDropGlue(ref __binding_0, ref __binding_1) =>
{
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable, const _: () =
{
impl<'tcx, '__lifted>
::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>
for ShimKind<'tcx> {
type Lifted = ShimKind<'__lifted>;
fn lift_to_interner(self,
__tcx: ::rustc_middle::ty::TyCtxt<'__lifted>)
-> ShimKind<'__lifted> {
match self {
ShimKind::VTable(__binding_0) => {
ShimKind::VTable(__tcx.lift(__binding_0))
}
ShimKind::Reify(__binding_0, __binding_1) => {
ShimKind::Reify(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::FnPtr(__binding_0, __binding_1) => {
ShimKind::FnPtr(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::ClosureOnce {
call_once: __binding_0,
closure: __binding_1,
track_caller: __binding_2 } => {
ShimKind::ClosureOnce {
call_once: __tcx.lift(__binding_0),
closure: __tcx.lift(__binding_1),
track_caller: __tcx.lift(__binding_2),
}
}
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __binding_0,
receiver_by_ref: __binding_1 } => {
ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: __tcx.lift(__binding_0),
receiver_by_ref: __tcx.lift(__binding_1),
}
}
ShimKind::ThreadLocal(__binding_0) => {
ShimKind::ThreadLocal(__tcx.lift(__binding_0))
}
ShimKind::FutureDropPoll(__binding_0, __binding_1,
__binding_2) => {
ShimKind::FutureDropPoll(__tcx.lift(__binding_0),
__tcx.lift(__binding_1), __tcx.lift(__binding_2))
}
ShimKind::DropGlue(__binding_0, __binding_1) => {
ShimKind::DropGlue(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::Clone(__binding_0, __binding_1) => {
ShimKind::Clone(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::FnPtrAddr(__binding_0, __binding_1) => {
ShimKind::FnPtrAddr(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::AsyncDropGlueCtor(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlueCtor(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
ShimKind::AsyncDropGlue(__binding_0, __binding_1) => {
ShimKind::AsyncDropGlue(__tcx.lift(__binding_0),
__tcx.lift(__binding_1))
}
}
}
}
};Lift)]
100pub enum ShimKind<'tcx> {
101 VTable(DefId),
107
108 Reify(DefId, Option<ReifyReason>),
126
127 FnPtr(DefId, Ty<'tcx>),
131
132 ClosureOnce { call_once: DefId, closure: DefId, track_caller: bool },
139
140 ConstructCoroutineInClosure {
146 coroutine_closure_def_id: DefId,
147 receiver_by_ref: bool,
153 },
154
155 ThreadLocal(DefId),
159
160 FutureDropPoll(DefId, Ty<'tcx>, Ty<'tcx>),
162
163 DropGlue(DefId, Option<Ty<'tcx>>),
171
172 Clone(DefId, Ty<'tcx>),
179
180 FnPtrAddr(DefId, Ty<'tcx>),
186
187 AsyncDropGlueCtor(DefId, Ty<'tcx>),
192
193 AsyncDropGlue(DefId, Ty<'tcx>),
198}
199
200impl<'tcx> Instance<'tcx> {
201 pub fn ty(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Ty<'tcx> {
204 let ty = tcx.type_of(self.def.def_id());
205 tcx.instantiate_and_normalize_erasing_regions(self.args, typing_env, ty)
206 }
207
208 pub fn upstream_monomorphization(&self, tcx: TyCtxt<'tcx>) -> Option<CrateNum> {
215 if self.def_id().is_local() {
218 return None;
219 }
220
221 if !tcx.sess.opts.share_generics()
225 && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_hir::attrs::InlineAttr::Never
228 {
229 return None;
230 }
231
232 self.args.non_erasable_generics().next()?;
234
235 if tcx.is_compiler_builtins(LOCAL_CRATE) {
237 return None;
238 }
239
240 match self.def {
241 InstanceKind::Item(def) => tcx
242 .upstream_monomorphizations_for(def)
243 .and_then(|monos| monos.get(&self.args).cloned()),
244 InstanceKind::Shim(ShimKind::DropGlue(_, Some(_))) => {
245 tcx.upstream_drop_glue_for(self.args)
246 }
247 InstanceKind::Shim(ShimKind::AsyncDropGlue(_, _)) => None,
248 InstanceKind::Shim(ShimKind::FutureDropPoll(_, _, _)) => None,
249 InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(_, _)) => {
250 tcx.upstream_async_drop_glue_for(self.args)
251 }
252 _ => None,
253 }
254 }
255}
256
257impl<'tcx> InstanceKind<'tcx> {
258 #[inline]
259 pub fn def_id(self) -> DefId {
260 match self {
261 InstanceKind::Item(def_id)
262 | InstanceKind::Virtual(def_id, _)
263 | InstanceKind::Intrinsic(def_id)
264 | InstanceKind::LlvmIntrinsic(def_id) => def_id,
265 InstanceKind::Shim(shim) => shim.def_id(),
266 }
267 }
268
269 pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
271 match self {
272 InstanceKind::Item(def) => Some(def),
273 InstanceKind::Virtual(..)
274 | InstanceKind::Intrinsic(..)
275 | InstanceKind::LlvmIntrinsic(..) => None,
276 InstanceKind::Shim(shim) => shim.def_id_if_not_guaranteed_local_codegen(),
277 }
278 }
279
280 pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool {
286 use rustc_hir::definitions::DefPathData;
287 match *self {
288 InstanceKind::Item(def_id) => #[allow(non_exhaustive_omitted_patterns)] match tcx.def_key(def_id).disambiguated_data.data
{
DefPathData::Ctor | DefPathData::Closure => true,
_ => false,
}matches!(
289 tcx.def_key(def_id).disambiguated_data.data,
290 DefPathData::Ctor | DefPathData::Closure
291 ),
292 InstanceKind::Shim(shim) => shim.requires_inline(),
293 InstanceKind::Virtual(..)
294 | InstanceKind::Intrinsic(..)
295 | InstanceKind::LlvmIntrinsic(..) => true,
296 }
297 }
298
299 pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
300 match *self {
301 InstanceKind::Item(def_id)
302 | InstanceKind::Virtual(def_id, _)
303 | InstanceKind::Shim(ShimKind::VTable(def_id)) => {
304 tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
305 }
306 InstanceKind::Shim(ShimKind::ClosureOnce {
307 call_once: _,
308 closure: _,
309 track_caller,
310 }) => track_caller,
311 _ => false,
312 }
313 }
314
315 pub fn has_polymorphic_mir_body(&self) -> bool {
322 match *self {
323 InstanceKind::Item(_)
324 | InstanceKind::Intrinsic(..)
325 | InstanceKind::LlvmIntrinsic(..)
326 | InstanceKind::Virtual(..) => true,
327 InstanceKind::Shim(shim) => shim.has_polymorphic_mir_body(),
328 }
329 }
330}
331
332impl<'tcx> ShimKind<'tcx> {
333 #[inline]
334 pub fn def_id(self) -> DefId {
335 match self {
336 ShimKind::VTable(def_id)
337 | ShimKind::Reify(def_id, _)
338 | ShimKind::FnPtr(def_id, _)
339 | ShimKind::ThreadLocal(def_id)
340 | ShimKind::ClosureOnce { call_once: def_id, closure: _, track_caller: _ }
341 | ShimKind::ConstructCoroutineInClosure {
342 coroutine_closure_def_id: def_id,
343 receiver_by_ref: _,
344 }
345 | ShimKind::DropGlue(def_id, _)
346 | ShimKind::Clone(def_id, _)
347 | ShimKind::FnPtrAddr(def_id, _)
348 | ShimKind::FutureDropPoll(def_id, _, _)
349 | ShimKind::AsyncDropGlue(def_id, _)
350 | ShimKind::AsyncDropGlueCtor(def_id, _) => def_id,
351 }
352 }
353
354 pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
356 match self {
357 ShimKind::DropGlue(def_id, Some(_))
358 | ShimKind::AsyncDropGlueCtor(def_id, _)
359 | ShimKind::AsyncDropGlue(def_id, _)
360 | ShimKind::FutureDropPoll(def_id, ..)
361 | ShimKind::ThreadLocal(def_id) => Some(def_id),
362 ShimKind::VTable(..)
363 | ShimKind::Reify(..)
364 | ShimKind::FnPtr(..)
365 | ShimKind::ClosureOnce { .. }
366 | ShimKind::ConstructCoroutineInClosure { .. }
367 | ShimKind::DropGlue(..)
368 | ShimKind::Clone(..)
369 | ShimKind::FnPtrAddr(..) => None,
370 }
371 }
372
373 pub fn requires_inline(&self) -> bool {
374 match self {
375 ShimKind::DropGlue(_, Some(ty)) => ty.is_array(),
376 ShimKind::AsyncDropGlueCtor(_, ty) => ty.is_coroutine(),
377 ShimKind::FutureDropPoll(_, _, _) => false,
378 ShimKind::AsyncDropGlue(_, _) => false,
379 ShimKind::ThreadLocal(_) => false,
380 _ => true,
381 }
382 }
383
384 pub fn has_polymorphic_mir_body(&self) -> bool {
385 match *self {
386 ShimKind::Clone(..)
387 | ShimKind::ThreadLocal(..)
388 | ShimKind::FnPtrAddr(..)
389 | ShimKind::FnPtr(..)
390 | ShimKind::DropGlue(_, Some(_))
391 | ShimKind::FutureDropPoll(..)
392 | ShimKind::AsyncDropGlue(_, _) => false,
393 ShimKind::AsyncDropGlueCtor(_, _) => false,
394 ShimKind::ClosureOnce { .. }
395 | ShimKind::ConstructCoroutineInClosure { .. }
396 | ShimKind::DropGlue(..)
397 | ShimKind::Reify(..)
398 | ShimKind::VTable(..) => true,
399 }
400 }
401}
402
403fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
404 struct Visitor<'tcx> {
405 type_length: usize,
406 cache: FxHashMap<Ty<'tcx>, usize>,
407 }
408 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Visitor<'tcx> {
409 fn visit_ty(&mut self, t: Ty<'tcx>) {
410 if let Some(&value) = self.cache.get(&t) {
411 self.type_length += value;
412 return;
413 }
414
415 let prev = self.type_length;
416 self.type_length += 1;
417 t.super_visit_with(self);
418
419 if self.type_length > 16 {
421 self.cache.insert(t, self.type_length - prev);
422 }
423 }
424
425 fn visit_const(&mut self, ct: ty::Const<'tcx>) {
426 self.type_length += 1;
427 ct.super_visit_with(self);
428 }
429 }
430 let mut visitor = Visitor { type_length: 0, cache: Default::default() };
431 item.visit_with(&mut visitor);
432
433 visitor.type_length
434}
435
436impl<'tcx> fmt::Display for Instance<'tcx> {
437 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
438 ty::tls::with(|tcx| {
439 let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
440 tcx.lift(*self).print(&mut p)?;
441 let s = p.into_buffer();
442 f.write_str(&s)
443 })
444 }
445}
446
447fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
455 let first_cor = cor_ty;
456 let ty::Coroutine(poll_def_id, proxy_args) = first_cor.kind() else {
457 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
458 };
459 let poll_def_id = *poll_def_id;
460 let mut child_ty = cor_ty;
461 loop {
462 if let ty::Coroutine(child_def, child_args) = child_ty.kind() {
463 cor_ty = child_ty;
464 if *child_def == poll_def_id {
465 child_ty = child_args.first().unwrap().expect_ty();
466 continue;
467 } else {
468 return Instance {
469 def: ty::InstanceKind::Shim(ShimKind::FutureDropPoll(
470 poll_def_id,
471 first_cor,
472 cor_ty,
473 )),
474 args: proxy_args,
475 };
476 }
477 } else {
478 let ty::Coroutine(_, child_args) = cor_ty.kind() else {
479 crate::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
480 };
481 if first_cor != cor_ty {
482 return Instance {
483 def: ty::InstanceKind::Shim(ShimKind::FutureDropPoll(
484 poll_def_id,
485 first_cor,
486 cor_ty,
487 )),
488 args: proxy_args,
489 };
490 } else {
491 return Instance {
492 def: ty::InstanceKind::Shim(ShimKind::AsyncDropGlue(poll_def_id, cor_ty)),
493 args: child_args,
494 };
495 }
496 }
497 }
498}
499
500impl<'tcx> Instance<'tcx> {
501 pub fn new_raw(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
510 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!(
511 !args.has_escaping_bound_vars(),
512 "args of instance {def_id:?} has escaping bound vars: {args:?}"
513 );
514 Instance { def: InstanceKind::Item(def_id), args }
515 }
516
517 pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
518 let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
519 ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
520 ty::GenericParamDefKind::Type { .. } => {
521 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has type parameters",
def_id))bug!("Instance::mono: {:?} has type parameters", def_id)
522 }
523 ty::GenericParamDefKind::Const { .. } => {
524 crate::util::bug::bug_fmt(format_args!("Instance::mono: {0:?} has const parameters",
def_id))bug!("Instance::mono: {:?} has const parameters", def_id)
525 }
526 });
527
528 Instance::new_raw(def_id, args)
529 }
530
531 #[inline]
532 pub fn def_id(&self) -> DefId {
533 self.def.def_id()
534 }
535
536 x;#[instrument(level = "debug", skip(tcx), ret)]
562 pub fn try_resolve(
563 tcx: TyCtxt<'tcx>,
564 typing_env: ty::TypingEnv<'tcx>,
565 def_id: DefId,
566 args: GenericArgsRef<'tcx>,
567 ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
568 assert_matches!(
569 tcx.def_kind(def_id),
570 DefKind::Fn
571 | DefKind::AssocFn
572 | DefKind::Const { .. }
573 | DefKind::AssocConst { .. }
574 | DefKind::AnonConst
575 | DefKind::Static { .. }
576 | DefKind::Ctor(_, CtorKind::Fn)
577 | DefKind::Closure
578 | DefKind::SyntheticCoroutineBody,
579 "`Instance::try_resolve` should only be used to resolve instances of \
580 functions, statics, and consts; to resolve associated types, use \
581 `try_normalize_erasing_regions`."
582 );
583
584 if tcx.sess.opts.unstable_opts.enforce_type_length_limit
591 && !tcx.type_length_limit().value_within_limit(type_length(args))
592 {
593 return Ok(None);
594 }
595
596 tcx.resolve_instance_raw(
599 tcx.erase_and_anonymize_regions(typing_env.as_query_input((def_id, args))),
600 )
601 }
602
603 pub fn expect_resolve(
604 tcx: TyCtxt<'tcx>,
605 typing_env: ty::TypingEnv<'tcx>,
606 def_id: DefId,
607 args: GenericArgsRef<'tcx>,
608 span: Span,
609 ) -> Instance<'tcx> {
610 let span_or_local_def_span =
614 || if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
615
616 match ty::Instance::try_resolve(tcx, typing_env, def_id, args) {
617 Ok(Some(instance)) => instance,
618 Ok(None) => {
619 let type_length = type_length(args);
620 if !tcx.type_length_limit().value_within_limit(type_length) {
621 tcx.dcx().emit_fatal(error::TypeLengthLimit {
622 span: span_or_local_def_span(),
626 instance: Instance::new_raw(def_id, args),
627 type_length,
628 });
629 } else {
630 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!(
631 span_or_local_def_span(),
632 "failed to resolve instance for {}",
633 tcx.def_path_str_with_args(def_id, args)
634 )
635 }
636 }
637 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!(
638 span_or_local_def_span(),
639 "failed to resolve instance for {}: {instance:#?}",
640 tcx.def_path_str_with_args(def_id, args)
641 ),
642 }
643 }
644
645 pub fn resolve_for_fn_ptr(
646 tcx: TyCtxt<'tcx>,
647 typing_env: ty::TypingEnv<'tcx>,
648 def_id: DefId,
649 args: GenericArgsRef<'tcx>,
650 ) -> Option<Instance<'tcx>> {
651 {
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:651",
"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(651u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve(def_id={0:?}, args={1:?})",
def_id, args) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve(def_id={:?}, args={:?})", def_id, args);
652 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:?}");
654 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
655 Instance::try_resolve(tcx, typing_env, def_id, args).ok().flatten().map(|mut resolved| {
656 match resolved.def {
657 InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
658 {
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:658",
"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(658u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => fn pointer created for function with #[track_caller]")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(" => fn pointer created for function with #[track_caller]");
659 resolved.def = InstanceKind::Shim(ShimKind::Reify(def, reason));
660 }
661 InstanceKind::Virtual(def_id, _) => {
662 {
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:662",
"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(662u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => fn pointer created for virtual call")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(" => fn pointer created for virtual call");
663 resolved.def = InstanceKind::Shim(ShimKind::Reify(def_id, reason));
664 }
665 _ if tcx.sess.is_sanitizer_kcfi_enabled() => {
666 if tcx.is_closure_like(resolved.def_id()) {
668 resolved = Instance {
672 def: InstanceKind::Shim(ShimKind::Reify(def_id, reason)),
673 args,
674 }
675 } else if let Some(assoc) = tcx.opt_associated_item(def_id)
677 && let AssocContainer::Trait | AssocContainer::TraitImpl(Ok(_)) =
678 assoc.container
679 && tcx.is_dyn_compatible(assoc.container_id(tcx))
680 {
681 resolved.def =
684 InstanceKind::Shim(ShimKind::Reify(resolved.def_id(), reason))
685 }
686 }
687 _ => {}
688 }
689
690 resolved
691 })
692 }
693
694 pub fn expect_resolve_for_vtable(
695 tcx: TyCtxt<'tcx>,
696 typing_env: ty::TypingEnv<'tcx>,
697 def_id: DefId,
698 args: GenericArgsRef<'tcx>,
699 span: Span,
700 ) -> Instance<'tcx> {
701 {
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:701",
"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(701u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("resolve_for_vtable(def_id={0:?}, args={1:?})",
def_id, args) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
702 let fn_sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
703 let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
704 && fn_sig.input(0).skip_binder().is_param(0)
705 && tcx.generics_of(def_id).has_self;
706
707 if is_vtable_shim {
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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => associated item with unsizeable self: Self")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(" => associated item with unsizeable self: Self");
709 return Instance { def: InstanceKind::Shim(ShimKind::VTable(def_id)), args };
710 }
711
712 let mut resolved = Instance::expect_resolve(tcx, typing_env, def_id, args, span);
713
714 let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
715 match resolved.def {
716 InstanceKind::Item(def) => {
717 let needs_track_caller_shim = resolved.def.requires_caller_location(tcx)
727 && !tcx.should_inherit_track_caller(def)
730 && !#[allow(non_exhaustive_omitted_patterns)] match tcx.opt_associated_item(def) {
Some(ty::AssocItem { container: ty::AssocContainer::Trait, .. }) => true,
_ => false,
}matches!(
736 tcx.opt_associated_item(def),
737 Some(ty::AssocItem {
738 container: ty::AssocContainer::Trait,
739 ..
740 })
741 );
742 if needs_track_caller_shim {
743 if tcx.is_closure_like(def) {
744 {
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:744",
"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(744u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for closure with #[track_caller]: {0:?} for method {1:?} {2:?}",
def, def_id, args) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
745 " => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
746 def, def_id, args
747 );
748
749 resolved = Instance {
753 def: InstanceKind::Shim(ShimKind::Reify(def_id, reason)),
754 args,
755 };
756 } else {
757 {
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:757",
"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(757u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for function with #[track_caller]: {0:?}",
def) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
758 " => vtable fn pointer created for function with #[track_caller]: {:?}",
759 def
760 );
761 resolved.def = InstanceKind::Shim(ShimKind::Reify(def, reason));
762 }
763 }
764 }
765 InstanceKind::Virtual(def_id, _) => {
766 {
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:766",
"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(766u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::instance"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" => vtable fn pointer created for virtual call")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(" => vtable fn pointer created for virtual call");
767 resolved.def = InstanceKind::Shim(ShimKind::Reify(def_id, reason))
768 }
769 _ => {}
770 }
771
772 resolved
773 }
774
775 pub fn resolve_closure(
776 tcx: TyCtxt<'tcx>,
777 def_id: DefId,
778 args: ty::GenericArgsRef<'tcx>,
779 requested_kind: ty::ClosureKind,
780 ) -> Instance<'tcx> {
781 let actual_kind = args.as_closure().kind();
782
783 match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
784 Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
785 _ => Instance::new_raw(def_id, args),
786 }
787 }
788
789 pub fn resolve_drop_glue(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
790 let def_id = tcx.require_lang_item(LangItem::DropGlue, DUMMY_SP);
791 let args = tcx.mk_args(&[ty.into()]);
792 Instance::expect_resolve(
793 tcx,
794 ty::TypingEnv::fully_monomorphized(),
795 def_id,
796 args,
797 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
798 )
799 }
800
801 pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
802 let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP);
803 let args = tcx.mk_args(&[ty.into()]);
804 Instance::expect_resolve(
805 tcx,
806 ty::TypingEnv::fully_monomorphized(),
807 def_id,
808 args,
809 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
810 )
811 }
812
813 pub fn resolve_async_drop_in_place_poll(
814 tcx: TyCtxt<'tcx>,
815 def_id: DefId,
816 ty: Ty<'tcx>,
817 ) -> ty::Instance<'tcx> {
818 let args = tcx.mk_args(&[ty.into()]);
819 Instance::expect_resolve(tcx, ty::TypingEnv::fully_monomorphized(), def_id, args, DUMMY_SP)
820 }
821
822 x;#[instrument(level = "debug", skip(tcx), ret)]
823 pub fn fn_once_adapter_instance(
824 tcx: TyCtxt<'tcx>,
825 closure_did: DefId,
826 args: ty::GenericArgsRef<'tcx>,
827 ) -> Instance<'tcx> {
828 let fn_once = tcx.require_lang_item(LangItem::FnOnce, DUMMY_SP);
829 let call_once = tcx
830 .associated_items(fn_once)
831 .in_definition_order()
832 .find(|it| it.is_fn())
833 .unwrap()
834 .def_id;
835 let track_caller =
836 tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
837 let def = ty::InstanceKind::Shim(ShimKind::ClosureOnce {
838 call_once,
839 closure: closure_did,
840 track_caller,
841 });
842
843 let self_ty = Ty::new_closure(tcx, closure_did, args);
844
845 let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
846 let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
847 let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
848
849 debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
850 Instance { def, args }
851 }
852
853 pub fn try_resolve_item_for_coroutine(
854 tcx: TyCtxt<'tcx>,
855 trait_item_id: DefId,
856 trait_id: DefId,
857 rcvr_args: ty::GenericArgsRef<'tcx>,
858 ) -> Option<Instance<'tcx>> {
859 let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
860 return None;
861 };
862 let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap();
863
864 let coroutine_callable_item = if tcx.is_lang_item(trait_id, LangItem::Future) {
865 {
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!(
866 coroutine_kind,
867 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
868 );
869 hir::LangItem::FuturePoll
870 } else if tcx.is_lang_item(trait_id, LangItem::Iterator) {
871 {
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!(
872 coroutine_kind,
873 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
874 );
875 hir::LangItem::IteratorNext
876 } else if tcx.is_lang_item(trait_id, LangItem::AsyncIterator) {
877 {
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!(
878 coroutine_kind,
879 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
880 );
881 hir::LangItem::AsyncIteratorPollNext
882 } else if tcx.is_lang_item(trait_id, LangItem::Coroutine) {
883 {
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(_));
884 hir::LangItem::CoroutineResume
885 } else {
886 return None;
887 };
888
889 if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
890 if tcx.is_async_drop_in_place_coroutine(coroutine_def_id) {
891 return Some(resolve_async_drop_poll(rcvr_args.type_at(0)));
892 }
893 let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
894 else {
895 crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
896 };
897
898 if args.as_coroutine().kind_ty() == id_args.as_coroutine().kind_ty() {
901 Some(Instance { def: ty::InstanceKind::Item(coroutine_def_id), args })
902 } else {
903 Some(Instance {
904 def: ty::InstanceKind::Item(
905 tcx.coroutine_by_move_body_def_id(coroutine_def_id),
906 ),
907 args,
908 })
909 }
910 } else {
911 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());
915 Some(Instance::new_raw(trait_item_id, rcvr_args))
916 }
917 }
918
919 fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
930 self.def.has_polymorphic_mir_body().then_some(self.args)
931 }
932
933 pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, T>) -> T
934 where
935 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
936 {
937 if let Some(args) = self.args_for_mir_body() {
938 v.instantiate(tcx, args).skip_norm_wip()
939 } else {
940 v.instantiate_identity().skip_norm_wip()
941 }
942 }
943
944 #[inline(always)]
945 pub fn instantiate_mir_and_normalize_erasing_regions<T>(
947 &self,
948 tcx: TyCtxt<'tcx>,
949 typing_env: ty::TypingEnv<'tcx>,
950 v: EarlyBinder<'tcx, T>,
951 ) -> T
952 where
953 T: TypeFoldable<TyCtxt<'tcx>>,
954 {
955 if let Some(args) = self.args_for_mir_body() {
956 tcx.instantiate_and_normalize_erasing_regions(args, typing_env, v)
957 } else {
958 tcx.normalize_erasing_regions(typing_env, v.instantiate_identity())
959 }
960 }
961
962 #[inline(always)]
963 pub fn try_instantiate_mir_and_normalize_erasing_regions<T>(
965 &self,
966 tcx: TyCtxt<'tcx>,
967 typing_env: ty::TypingEnv<'tcx>,
968 v: EarlyBinder<'tcx, T>,
969 ) -> Result<T, NormalizationError<'tcx>>
970 where
971 T: TypeFoldable<TyCtxt<'tcx>>,
972 {
973 if let Some(args) = self.args_for_mir_body() {
974 tcx.try_instantiate_and_normalize_erasing_regions(args, typing_env, v)
975 } else {
976 tcx.try_normalize_erasing_regions(typing_env, v.instantiate_identity())
982 }
983 }
984}
985
986fn needs_fn_once_adapter_shim(
987 actual_closure_kind: ty::ClosureKind,
988 trait_closure_kind: ty::ClosureKind,
989) -> Result<bool, ()> {
990 match (actual_closure_kind, trait_closure_kind) {
991 (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
992 | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
993 | (ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
994 Ok(false)
996 }
997 (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
998 Ok(false)
1001 }
1002 (ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
1003 Ok(true)
1011 }
1012 (ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
1013 }
1014}