Skip to main content

rustc_type_ir/
ty_kind.rs

1use std::fmt;
2use std::ops::Deref;
3
4use derive_where::derive_where;
5use rustc_abi::ExternAbi;
6use rustc_ast_ir::Mutability;
7#[cfg(feature = "nightly")]
8use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
9#[cfg(feature = "nightly")]
10use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
11use rustc_type_ir::data_structures::{NoError, UnifyKey, UnifyValue};
12use rustc_type_ir_macros::{
13    GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
14};
15
16use self::TyKind::*;
17pub use self::closure::*;
18use crate::inherent::*;
19#[cfg(feature = "nightly")]
20use crate::visit::TypeVisitable;
21use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy};
22
23mod closure;
24
25#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for AliasTyKind<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            AliasTyKind::Projection { def_id: ref __field_def_id } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "Projection");
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
            AliasTyKind::Inherent { def_id: ref __field_def_id } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "Inherent");
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
            AliasTyKind::Opaque { def_id: ref __field_def_id } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "Opaque");
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
            AliasTyKind::Free { def_id: ref __field_def_id } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "Free");
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
26#[derive(GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for AliasTyKind<I>
            where I: Interner, J: Interner,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId>,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId>,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId>,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId> {
            type Lifted = AliasTyKind<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        AliasTyKind::Projection { def_id: __binding_0 } => {
                            AliasTyKind::Projection {
                                def_id: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                        AliasTyKind::Inherent { def_id: __binding_0 } => {
                            AliasTyKind::Inherent {
                                def_id: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                        AliasTyKind::Opaque { def_id: __binding_0 } => {
                            AliasTyKind::Opaque {
                                def_id: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                        AliasTyKind::Free { def_id: __binding_0 } => {
                            AliasTyKind::Free {
                                def_id: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
27#[cfg_attr(
28    feature = "nightly",
29    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for AliasTyKind<I> where
            I::DefId: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        AliasTyKind::Projection { def_id: ref __binding_0 } => {
                            0usize
                        }
                        AliasTyKind::Inherent { def_id: ref __binding_0 } => {
                            1usize
                        }
                        AliasTyKind::Opaque { def_id: ref __binding_0 } => {
                            2usize
                        }
                        AliasTyKind::Free { def_id: ref __binding_0 } => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    AliasTyKind::Projection { def_id: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    AliasTyKind::Inherent { def_id: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    AliasTyKind::Opaque { def_id: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    AliasTyKind::Free { def_id: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for AliasTyKind<I> where
            I::DefId: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        AliasTyKind::Projection {
                            def_id: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    1usize => {
                        AliasTyKind::Inherent {
                            def_id: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    2usize => {
                        AliasTyKind::Opaque {
                            def_id: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    3usize => {
                        AliasTyKind::Free {
                            def_id: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AliasTyKind`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            AliasTyKind<I> where
            I::DefId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    AliasTyKind::Projection { def_id: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    AliasTyKind::Inherent { def_id: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    AliasTyKind::Opaque { def_id: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    AliasTyKind::Free { def_id: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
30)]
31pub enum AliasTyKind<I: Interner> {
32    /// A projection `<Type as Trait>::AssocType`.
33    ///
34    /// Can get normalized away if monomorphic enough.
35    ///
36    /// The `def_id` is the `DefId` of the `TraitItem` for the associated type.
37    ///
38    /// Note that the `def_id` is not the `DefId` of the `TraitRef` containing this
39    /// associated type, which is in `interner.associated_item(def_id).container`,
40    /// aka. `interner.parent(def_id)`.
41    Projection { def_id: I::DefId },
42
43    /// An associated type in an inherent `impl`
44    ///
45    /// The `def_id` is the `DefId` of the `ImplItem` for the associated type.
46    Inherent { def_id: I::DefId },
47
48    /// An opaque type (usually from `impl Trait` in type aliases or function return types)
49    ///
50    /// `def_id` is the `DefId` of the `OpaqueType` item.
51    ///
52    ///
53    /// Can only be normalized away in `PostAnalysis` mode or its defining scope.
54    ///
55    /// During codegen, `interner.type_of(def_id)` can be used to get the type of the
56    /// underlying type if the type is an opaque.
57    Opaque { def_id: I::DefId },
58
59    /// A type alias that actually checks its trait bounds.
60    ///
61    /// Currently only used if the type alias references opaque types.
62    /// Can always be normalized away.
63    Free { def_id: I::DefId },
64}
65
66impl<I: Interner> AliasTyKind<I> {
67    pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self {
68        interner.alias_ty_kind_from_def_id(def_id)
69    }
70
71    pub fn descr(self) -> &'static str {
72        match self {
73            AliasTyKind::Projection { .. } => "associated type",
74            AliasTyKind::Inherent { .. } => "inherent associated type",
75            AliasTyKind::Opaque { .. } => "opaque type",
76            AliasTyKind::Free { .. } => "type alias",
77        }
78    }
79
80    pub fn def_id(self) -> I::DefId {
81        let (AliasTyKind::Projection { def_id }
82        | AliasTyKind::Inherent { def_id }
83        | AliasTyKind::Opaque { def_id }
84        | AliasTyKind::Free { def_id }) = self;
85
86        def_id
87    }
88}
89
90/// Defines the kinds of types used by the type system.
91///
92/// Types written by the user start out as `hir::TyKind` and get
93/// converted to this representation using `<dyn HirTyLowerer>::lower_ty`.
94#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")]
95#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for TyKind<I> where I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (TyKind::Int(ref __field_0), TyKind::Int(ref __other_field_0))
                    =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Uint(ref __field_0),
                    TyKind::Uint(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Float(ref __field_0),
                    TyKind::Float(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Adt(ref __field_0, ref __field_1),
                    TyKind::Adt(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Foreign(ref __field_0),
                    TyKind::Foreign(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Array(ref __field_0, ref __field_1),
                    TyKind::Array(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Pat(ref __field_0, ref __field_1),
                    TyKind::Pat(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Slice(ref __field_0),
                    TyKind::Slice(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::RawPtr(ref __field_0, ref __field_1),
                    TyKind::RawPtr(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Ref(ref __field_0, ref __field_1, ref __field_2),
                    TyKind::Ref(ref __other_field_0, ref __other_field_1,
                    ref __other_field_2)) =>
                    true &&
                                ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                            ::core::cmp::PartialEq::eq(__field_1, __other_field_1) &&
                        ::core::cmp::PartialEq::eq(__field_2, __other_field_2),
                (TyKind::FnDef(ref __field_0, ref __field_1),
                    TyKind::FnDef(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::FnPtr(ref __field_0, ref __field_1),
                    TyKind::FnPtr(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::UnsafeBinder(ref __field_0),
                    TyKind::UnsafeBinder(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Dynamic(ref __field_0, ref __field_1),
                    TyKind::Dynamic(ref __other_field_0, ref __other_field_1))
                    =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Closure(ref __field_0, ref __field_1),
                    TyKind::Closure(ref __other_field_0, ref __other_field_1))
                    =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::CoroutineClosure(ref __field_0, ref __field_1),
                    TyKind::CoroutineClosure(ref __other_field_0,
                    ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Coroutine(ref __field_0, ref __field_1),
                    TyKind::Coroutine(ref __other_field_0, ref __other_field_1))
                    =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::CoroutineWitness(ref __field_0, ref __field_1),
                    TyKind::CoroutineWitness(ref __other_field_0,
                    ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Tuple(ref __field_0),
                    TyKind::Tuple(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Alias(ref __field_0),
                    TyKind::Alias(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Param(ref __field_0),
                    TyKind::Param(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Bound(ref __field_0, ref __field_1),
                    TyKind::Bound(ref __other_field_0, ref __other_field_1)) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_0, __other_field_0) &&
                        ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
                (TyKind::Placeholder(ref __field_0),
                    TyKind::Placeholder(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Infer(ref __field_0),
                    TyKind::Infer(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (TyKind::Error(ref __field_0),
                    TyKind::Error(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                _ => true,
            }
        } else { false }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
96#[derive(GenericTypeVisitable)]
97#[cfg_attr(
98    feature = "nightly",
99    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for TyKind<I> where
            I::AdtDef: ::rustc_serialize::Encodable<__E>,
            I::GenericArgs: ::rustc_serialize::Encodable<__E>,
            I::ForeignId: ::rustc_serialize::Encodable<__E>,
            I::Ty: ::rustc_serialize::Encodable<__E>,
            I::Const: ::rustc_serialize::Encodable<__E>,
            I::Pat: ::rustc_serialize::Encodable<__E>,
            I::Region: ::rustc_serialize::Encodable<__E>,
            I::FunctionId: ::rustc_serialize::Encodable<__E>,
            ty::Binder<I, FnSigTys<I>>: ::rustc_serialize::Encodable<__E>,
            FnHeader<I>: ::rustc_serialize::Encodable<__E>,
            UnsafeBinderInner<I>: ::rustc_serialize::Encodable<__E>,
            I::BoundExistentialPredicates: ::rustc_serialize::Encodable<__E>,
            I::ClosureId: ::rustc_serialize::Encodable<__E>,
            I::CoroutineClosureId: ::rustc_serialize::Encodable<__E>,
            I::CoroutineId: ::rustc_serialize::Encodable<__E>,
            I::Tys: ::rustc_serialize::Encodable<__E>,
            AliasTy<I>: ::rustc_serialize::Encodable<__E>,
            I::ParamTy: ::rustc_serialize::Encodable<__E>,
            ty::BoundTy<I>: ::rustc_serialize::Encodable<__E>,
            ty::PlaceholderType<I>: ::rustc_serialize::Encodable<__E>,
            I::ErrorGuaranteed: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        TyKind::Bool => { 0usize }
                        TyKind::Char => { 1usize }
                        TyKind::Int(ref __binding_0) => { 2usize }
                        TyKind::Uint(ref __binding_0) => { 3usize }
                        TyKind::Float(ref __binding_0) => { 4usize }
                        TyKind::Adt(ref __binding_0, ref __binding_1) => { 5usize }
                        TyKind::Foreign(ref __binding_0) => { 6usize }
                        TyKind::Str => { 7usize }
                        TyKind::Array(ref __binding_0, ref __binding_1) => {
                            8usize
                        }
                        TyKind::Pat(ref __binding_0, ref __binding_1) => { 9usize }
                        TyKind::Slice(ref __binding_0) => { 10usize }
                        TyKind::RawPtr(ref __binding_0, ref __binding_1) => {
                            11usize
                        }
                        TyKind::Ref(ref __binding_0, ref __binding_1,
                            ref __binding_2) => {
                            12usize
                        }
                        TyKind::FnDef(ref __binding_0, ref __binding_1) => {
                            13usize
                        }
                        TyKind::FnPtr(ref __binding_0, ref __binding_1) => {
                            14usize
                        }
                        TyKind::UnsafeBinder(ref __binding_0) => { 15usize }
                        TyKind::Dynamic(ref __binding_0, ref __binding_1) => {
                            16usize
                        }
                        TyKind::Closure(ref __binding_0, ref __binding_1) => {
                            17usize
                        }
                        TyKind::CoroutineClosure(ref __binding_0, ref __binding_1)
                            => {
                            18usize
                        }
                        TyKind::Coroutine(ref __binding_0, ref __binding_1) => {
                            19usize
                        }
                        TyKind::CoroutineWitness(ref __binding_0, ref __binding_1)
                            => {
                            20usize
                        }
                        TyKind::Never => { 21usize }
                        TyKind::Tuple(ref __binding_0) => { 22usize }
                        TyKind::Alias(ref __binding_0) => { 23usize }
                        TyKind::Param(ref __binding_0) => { 24usize }
                        TyKind::Bound(ref __binding_0, ref __binding_1) => {
                            25usize
                        }
                        TyKind::Placeholder(ref __binding_0) => { 26usize }
                        TyKind::Infer(ref __binding_0) => { 27usize }
                        TyKind::Error(ref __binding_0) => { 28usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    TyKind::Bool => {}
                    TyKind::Char => {}
                    TyKind::Int(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Uint(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Float(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Adt(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Foreign(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Str => {}
                    TyKind::Array(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Pat(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Slice(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::RawPtr(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Ref(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);
                    }
                    TyKind::FnDef(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::FnPtr(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::UnsafeBinder(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Dynamic(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Closure(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::CoroutineClosure(ref __binding_0, ref __binding_1)
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Coroutine(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::CoroutineWitness(ref __binding_0, ref __binding_1)
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Never => {}
                    TyKind::Tuple(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Alias(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Param(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Bound(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TyKind::Placeholder(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Infer(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TyKind::Error(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for TyKind<I> where
            I::AdtDef: ::rustc_serialize::Decodable<__D>,
            I::GenericArgs: ::rustc_serialize::Decodable<__D>,
            I::ForeignId: ::rustc_serialize::Decodable<__D>,
            I::Ty: ::rustc_serialize::Decodable<__D>,
            I::Const: ::rustc_serialize::Decodable<__D>,
            I::Pat: ::rustc_serialize::Decodable<__D>,
            I::Region: ::rustc_serialize::Decodable<__D>,
            I::FunctionId: ::rustc_serialize::Decodable<__D>,
            ty::Binder<I, FnSigTys<I>>: ::rustc_serialize::Decodable<__D>,
            FnHeader<I>: ::rustc_serialize::Decodable<__D>,
            UnsafeBinderInner<I>: ::rustc_serialize::Decodable<__D>,
            I::BoundExistentialPredicates: ::rustc_serialize::Decodable<__D>,
            I::ClosureId: ::rustc_serialize::Decodable<__D>,
            I::CoroutineClosureId: ::rustc_serialize::Decodable<__D>,
            I::CoroutineId: ::rustc_serialize::Decodable<__D>,
            I::Tys: ::rustc_serialize::Decodable<__D>,
            AliasTy<I>: ::rustc_serialize::Decodable<__D>,
            I::ParamTy: ::rustc_serialize::Decodable<__D>,
            ty::BoundTy<I>: ::rustc_serialize::Decodable<__D>,
            ty::PlaceholderType<I>: ::rustc_serialize::Decodable<__D>,
            I::ErrorGuaranteed: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { TyKind::Bool }
                    1usize => { TyKind::Char }
                    2usize => {
                        TyKind::Int(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => {
                        TyKind::Uint(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        TyKind::Float(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    5usize => {
                        TyKind::Adt(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    6usize => {
                        TyKind::Foreign(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    7usize => { TyKind::Str }
                    8usize => {
                        TyKind::Array(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    9usize => {
                        TyKind::Pat(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    10usize => {
                        TyKind::Slice(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    11usize => {
                        TyKind::RawPtr(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    12usize => {
                        TyKind::Ref(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    13usize => {
                        TyKind::FnDef(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    14usize => {
                        TyKind::FnPtr(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    15usize => {
                        TyKind::UnsafeBinder(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    16usize => {
                        TyKind::Dynamic(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    17usize => {
                        TyKind::Closure(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    18usize => {
                        TyKind::CoroutineClosure(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    19usize => {
                        TyKind::Coroutine(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    20usize => {
                        TyKind::CoroutineWitness(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    21usize => { TyKind::Never }
                    22usize => {
                        TyKind::Tuple(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    23usize => {
                        TyKind::Alias(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    24usize => {
                        TyKind::Param(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    25usize => {
                        TyKind::Bound(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    26usize => {
                        TyKind::Placeholder(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    27usize => {
                        TyKind::Infer(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    28usize => {
                        TyKind::Error(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `TyKind`, expected 0..29, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            TyKind<I> where
            I::AdtDef: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::ForeignId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Ty: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Const: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Pat: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Region: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::FunctionId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            ty::Binder<I,
            FnSigTys<I>>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            FnHeader<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            UnsafeBinderInner<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::BoundExistentialPredicates: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::ClosureId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::CoroutineClosureId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::CoroutineId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Tys: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            AliasTy<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::ParamTy: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            ty::BoundTy<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            ty::PlaceholderType<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::ErrorGuaranteed: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    TyKind::Bool => {}
                    TyKind::Char => {}
                    TyKind::Int(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Uint(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Float(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Adt(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Foreign(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Str => {}
                    TyKind::Array(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Pat(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Slice(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::RawPtr(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Ref(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); }
                    }
                    TyKind::FnDef(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::FnPtr(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::UnsafeBinder(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Dynamic(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Closure(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::CoroutineClosure(ref __binding_0, ref __binding_1)
                        => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Coroutine(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::CoroutineWitness(ref __binding_0, ref __binding_1)
                        => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Never => {}
                    TyKind::Tuple(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Alias(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Param(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Bound(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Placeholder(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Infer(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TyKind::Error(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
100)]
101pub enum TyKind<I: Interner> {
102    /// The primitive boolean type. Written as `bool`.
103    Bool,
104
105    /// The primitive character type; holds a Unicode scalar value
106    /// (a non-surrogate code point). Written as `char`.
107    Char,
108
109    /// A primitive signed integer type. For example, `i32`.
110    Int(IntTy),
111
112    /// A primitive unsigned integer type. For example, `u32`.
113    Uint(UintTy),
114
115    /// A primitive floating-point type. For example, `f64`.
116    Float(FloatTy),
117
118    /// Algebraic data types (ADT). For example: structures, enumerations and unions.
119    ///
120    /// For example, the type `List<i32>` would be represented using the `AdtDef`
121    /// for `struct List<T>` and the args `[i32]`.
122    ///
123    /// Note that generic parameters in fields only get lazily instantiated
124    /// by using something like `adt_def.all_fields().map(|field| field.ty(interner, args))`.
125    Adt(I::AdtDef, I::GenericArgs),
126
127    /// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
128    Foreign(I::ForeignId),
129
130    /// The pointee of a string slice. Written as `str`.
131    Str,
132
133    /// An array with the given length. Written as `[T; N]`.
134    Array(I::Ty, I::Const),
135
136    /// A pattern newtype.
137    ///
138    /// Takes any type and restricts its valid values to its pattern.
139    /// This will also change the layout to take advantage of this restriction.
140    /// Only `Copy` and `Clone` will automatically get implemented for pattern types.
141    /// Auto-traits treat this as if it were an aggregate with a single nested type.
142    /// Only supports integer range patterns for now.
143    Pat(I::Ty, I::Pat),
144
145    /// The pointee of an array slice. Written as `[T]`.
146    Slice(I::Ty),
147
148    /// A raw pointer. Written as `*mut T` or `*const T`
149    RawPtr(I::Ty, Mutability),
150
151    /// A reference; a pointer with an associated lifetime. Written as
152    /// `&'a mut T` or `&'a T`.
153    Ref(I::Region, I::Ty, Mutability),
154
155    /// The anonymous type of a function declaration/definition.
156    ///
157    /// Each function has a unique type.
158    ///
159    /// For the function `fn foo() -> i32 { 3 }` this type would be
160    /// shown to the user as `fn() -> i32 {foo}`.
161    ///
162    /// For example the type of `bar` here:
163    /// ```rust
164    /// fn foo() -> i32 { 1 }
165    /// let bar = foo; // bar: fn() -> i32 {foo}
166    /// ```
167    FnDef(I::FunctionId, I::GenericArgs),
168
169    /// A pointer to a function.
170    ///
171    /// Written as `fn() -> i32`.
172    ///
173    /// Note that both functions and closures start out as either
174    /// [FnDef] or [Closure] which can be then be coerced to this variant.
175    ///
176    /// For example the type of `bar` here:
177    ///
178    /// ```rust
179    /// fn foo() -> i32 { 1 }
180    /// let bar: fn() -> i32 = foo;
181    /// ```
182    ///
183    /// These two fields are equivalent to a `ty::Binder<I, FnSig<I>>`. But by
184    /// splitting that into two pieces, we get a more compact data layout that
185    /// reduces the size of `TyKind` by 8 bytes. It is a very hot type, so it's
186    /// worth the mild inconvenience.
187    FnPtr(ty::Binder<I, FnSigTys<I>>, FnHeader<I>),
188
189    /// An unsafe binder type.
190    ///
191    /// A higher-ranked type used to represent a type which has had some of its
192    /// lifetimes erased. This can be used to represent types in positions where
193    /// a lifetime is literally inexpressible, such as self-referential types.
194    UnsafeBinder(UnsafeBinderInner<I>),
195
196    /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
197    Dynamic(I::BoundExistentialPredicates, I::Region),
198
199    /// The anonymous type of a closure. Used to represent the type of `|a| a`.
200    ///
201    /// Closure args contain both the - potentially instantiated - generic parameters
202    /// of its parent and some synthetic parameters. See the documentation for
203    /// `ClosureArgs` for more details.
204    Closure(I::ClosureId, I::GenericArgs),
205
206    /// The anonymous type of a closure. Used to represent the type of `async |a| a`.
207    ///
208    /// Coroutine-closure args contain both the - potentially instantiated - generic
209    /// parameters of its parent and some synthetic parameters. See the documentation
210    /// for `CoroutineClosureArgs` for more details.
211    CoroutineClosure(I::CoroutineClosureId, I::GenericArgs),
212
213    /// The anonymous type of a coroutine. Used to represent the type of
214    /// `|a| yield a`.
215    ///
216    /// For more info about coroutine args, visit the documentation for
217    /// `CoroutineArgs`.
218    Coroutine(I::CoroutineId, I::GenericArgs),
219
220    /// A type representing the types stored inside a coroutine.
221    ///
222    /// This should only appear as part of the `CoroutineArgs`.
223    ///
224    /// Unlike upvars, the witness can reference lifetimes from
225    /// inside of the coroutine itself. To deal with them in
226    /// the type of the coroutine, we convert them to higher ranked
227    /// lifetimes bound by the witness itself.
228    ///
229    /// This contains the `DefId` and the `GenericArgsRef` of the coroutine.
230    /// The actual witness types are computed on MIR by the `mir_coroutine_witnesses` query.
231    ///
232    /// Looking at the following example, the witness for this coroutine
233    /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
234    ///
235    /// ```
236    /// #![feature(coroutines)]
237    /// #[coroutine] static |a| {
238    ///     let x = &vec![3];
239    ///     yield a;
240    ///     yield x[0];
241    /// }
242    /// # ;
243    /// ```
244    CoroutineWitness(I::CoroutineId, I::GenericArgs),
245
246    /// The never type `!`.
247    Never,
248
249    /// A tuple type. For example, `(i32, bool)`.
250    Tuple(I::Tys),
251
252    /// A projection, opaque type, free type alias, or inherent associated type.
253    ///
254    /// All of these types are represented as pairs of def-id and args, and can
255    /// be normalized, so they are grouped conceptually.
256    Alias(AliasTy<I>),
257
258    /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
259    Param(I::ParamTy),
260
261    /// Bound type variable, used to represent the `'a` in `for<'a> fn(&'a ())`.
262    ///
263    /// For canonical queries, we replace inference variables with bound variables,
264    /// so e.g. when checking whether `&'_ (): Trait<_>` holds, we canonicalize that to
265    /// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
266    /// back to inference variables in a new inference context when inside of the query.
267    ///
268    /// It is conventional to render anonymous bound types like `^N` or `^D_N`,
269    /// where `N` is the bound variable's anonymous index into the binder, and
270    /// `D` is the debruijn index, or totally omitted if the debruijn index is zero.
271    ///
272    /// See the `rustc-dev-guide` for more details about
273    /// [higher-ranked trait bounds][1] and [canonical queries][2].
274    ///
275    /// [1]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
276    /// [2]: https://rustc-dev-guide.rust-lang.org/traits/canonical-queries.html
277    Bound(BoundVarIndexKind, ty::BoundTy<I>),
278
279    /// A placeholder type, used during higher ranked subtyping to instantiate
280    /// bound variables.
281    ///
282    /// It is conventional to render anonymous placeholder types like `!N` or `!U_N`,
283    /// where `N` is the placeholder variable's anonymous index (which corresponds
284    /// to the bound variable's index from the binder from which it was instantiated),
285    /// and `U` is the universe index in which it is instantiated, or totally omitted
286    /// if the universe index is zero.
287    Placeholder(ty::PlaceholderType<I>),
288
289    /// A type variable used during type checking.
290    ///
291    /// Similar to placeholders, inference variables also live in a universe to
292    /// correctly deal with higher ranked types. Though unlike placeholders,
293    /// that universe is stored in the `InferCtxt` instead of directly
294    /// inside of the type.
295    Infer(InferTy),
296
297    /// A placeholder for a type which could not be computed.
298    ///
299    /// This is propagated to avoid useless error messages.
300    Error(I::ErrorGuaranteed),
301}
302
303impl<I: Interner> Eq for TyKind<I> {}
304
305impl<I: Interner> TyKind<I> {
306    pub fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
307        match self {
308            ty::FnPtr(sig_tys, hdr) => sig_tys.with(hdr),
309            ty::FnDef(def_id, args) => {
310                interner.fn_sig(def_id).instantiate(interner, args).skip_norm_wip()
311            }
312            ty::Error(_) => {
313                // ignore errors (#54954)
314                ty::Binder::dummy(ty::FnSig::dummy())
315            }
316            ty::Closure(..) => {
    ::core::panicking::panic_fmt(format_args!("to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`"));
}panic!(
317                "to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`",
318            ),
319            _ => {
    ::core::panicking::panic_fmt(format_args!("Ty::fn_sig() called on non-fn type: {0:?}",
            self));
}panic!("Ty::fn_sig() called on non-fn type: {:?}", self),
320        }
321    }
322
323    /// Returns `true` when the outermost type cannot be further normalized,
324    /// resolved, or instantiated.
325    ///
326    /// This includes all primitive types, but also
327    /// things like ADTs and trait objects, since even if their arguments or
328    /// nested types may be further simplified, the outermost [`ty::TyKind`] or
329    /// type constructor remains the same.
330    pub fn is_known_rigid(self) -> bool {
331        match self {
332            ty::Bool
333            | ty::Char
334            | ty::Int(_)
335            | ty::Uint(_)
336            | ty::Float(_)
337            | ty::Adt(_, _)
338            | ty::Foreign(_)
339            | ty::Str
340            | ty::Array(_, _)
341            | ty::Pat(_, _)
342            | ty::Slice(_)
343            | ty::RawPtr(_, _)
344            | ty::Ref(_, _, _)
345            | ty::FnDef(_, _)
346            | ty::FnPtr(..)
347            | ty::UnsafeBinder(_)
348            | ty::Dynamic(_, _)
349            | ty::Closure(_, _)
350            | ty::CoroutineClosure(_, _)
351            | ty::Coroutine(_, _)
352            | ty::CoroutineWitness(..)
353            | ty::Never
354            | ty::Tuple(_) => true,
355
356            ty::Error(_)
357            | ty::Infer(_)
358            | ty::Alias(_)
359            | ty::Param(_)
360            | ty::Bound(_, _)
361            | ty::Placeholder(_) => false,
362        }
363    }
364}
365
366// This is manually implemented because a derive would require `I: Debug`
367impl<I: Interner> fmt::Debug for TyKind<I> {
368    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
369        match self {
370            Bool => f.write_fmt(format_args!("bool"))write!(f, "bool"),
371            Char => f.write_fmt(format_args!("char"))write!(f, "char"),
372            Int(i) => f.write_fmt(format_args!("{0:?}", i))write!(f, "{i:?}"),
373            Uint(u) => f.write_fmt(format_args!("{0:?}", u))write!(f, "{u:?}"),
374            Float(float) => f.write_fmt(format_args!("{0:?}", float))write!(f, "{float:?}"),
375            Adt(d, s) => {
376                f.write_fmt(format_args!("{0:?}", d))write!(f, "{d:?}")?;
377                let mut s = s.iter();
378                let first = s.next();
379                match first {
380                    Some(first) => f.write_fmt(format_args!("<{0:?}", first))write!(f, "<{:?}", first)?,
381                    None => return Ok(()),
382                };
383
384                for arg in s {
385                    f.write_fmt(format_args!(", {0:?}", arg))write!(f, ", {:?}", arg)?;
386                }
387
388                f.write_fmt(format_args!(">"))write!(f, ">")
389            }
390            Foreign(d) => f.debug_tuple("Foreign").field(d).finish(),
391            Str => f.write_fmt(format_args!("str"))write!(f, "str"),
392            Array(t, c) => f.write_fmt(format_args!("[{0:?}; {1:?}]", t, c))write!(f, "[{t:?}; {c:?}]"),
393            Pat(t, p) => f.write_fmt(format_args!("pattern_type!({0:?} is {1:?})", t, p))write!(f, "pattern_type!({t:?} is {p:?})"),
394            Slice(t) => f.write_fmt(format_args!("[{0:?}]", &t))write!(f, "[{:?}]", &t),
395            RawPtr(ty, mutbl) => f.write_fmt(format_args!("*{0} {1:?}", mutbl.ptr_str(), ty))write!(f, "*{} {:?}", mutbl.ptr_str(), ty),
396            Ref(r, t, m) => f.write_fmt(format_args!("&{0:?} {1}{2:?}", r, m.prefix_str(), t))write!(f, "&{:?} {}{:?}", r, m.prefix_str(), t),
397            FnDef(d, s) => f.debug_tuple("FnDef").field(d).field(&s).finish(),
398            FnPtr(sig_tys, hdr) => f.write_fmt(format_args!("{0:?}", sig_tys.with(*hdr)))write!(f, "{:?}", sig_tys.with(*hdr)),
399            // FIXME(unsafe_binder): print this like `unsafe<'a> T<'a>`.
400            UnsafeBinder(binder) => f.write_fmt(format_args!("{0:?}", binder))write!(f, "{:?}", binder),
401            Dynamic(p, r) => f.write_fmt(format_args!("dyn {0:?} + {1:?}", p, r))write!(f, "dyn {p:?} + {r:?}"),
402            Closure(d, s) => f.debug_tuple("Closure").field(d).field(&s).finish(),
403            CoroutineClosure(d, s) => f.debug_tuple("CoroutineClosure").field(d).field(&s).finish(),
404            Coroutine(d, s) => f.debug_tuple("Coroutine").field(d).field(&s).finish(),
405            CoroutineWitness(d, s) => f.debug_tuple("CoroutineWitness").field(d).field(&s).finish(),
406            Never => f.write_fmt(format_args!("!"))write!(f, "!"),
407            Tuple(t) => {
408                f.write_fmt(format_args!("("))write!(f, "(")?;
409                let mut count = 0;
410                for ty in t.iter() {
411                    if count > 0 {
412                        f.write_fmt(format_args!(", "))write!(f, ", ")?;
413                    }
414                    f.write_fmt(format_args!("{0:?}", ty))write!(f, "{ty:?}")?;
415                    count += 1;
416                }
417                // unary tuples need a trailing comma
418                if count == 1 {
419                    f.write_fmt(format_args!(","))write!(f, ",")?;
420                }
421                f.write_fmt(format_args!(")"))write!(f, ")")
422            }
423            Alias(a) => f.debug_tuple("Alias").field(&a).finish(),
424            Param(p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
425            Bound(d, b) => crate::debug_bound_var(f, *d, b),
426            Placeholder(p) => f.write_fmt(format_args!("{0:?}", p))write!(f, "{p:?}"),
427            Infer(t) => f.write_fmt(format_args!("{0:?}", t))write!(f, "{:?}", t),
428            TyKind::Error(_) => f.write_fmt(format_args!("{{type error}}"))write!(f, "{{type error}}"),
429        }
430    }
431}
432
433/// Represents the projection of an associated, opaque, or lazy-type-alias type.
434///
435/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.
436/// * For an inherent projection, this would be `Ty::N<...>`.
437/// * For an opaque type, there is no explicit syntax.
438#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for AliasTy<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            AliasTy {
                args: ref __field_args,
                kind: ref __field_kind,
                _use_alias_ty_new_instead: ref __field__use_alias_ty_new_instead
                } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "AliasTy");
                ::core::fmt::DebugStruct::field(&mut __builder, "args",
                    __field_args);
                ::core::fmt::DebugStruct::field(&mut __builder, "kind",
                    __field_kind);
                ::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
439#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for AliasTy<I>
            where I: Interner,
            I::GenericArgs: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    AliasTy {
                        args: ref __binding_0,
                        _use_alias_ty_new_instead: ref __binding_2, .. } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for AliasTy<I>
            where I: Interner,
            I::GenericArgs: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        AliasTy {
                            args: __binding_0,
                            kind: __binding_1,
                            _use_alias_ty_new_instead: __binding_2 } => {
                            AliasTy {
                                args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                kind: __binding_1,
                                _use_alias_ty_new_instead: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    AliasTy {
                        args: __binding_0,
                        kind: __binding_1,
                        _use_alias_ty_new_instead: __binding_2 } => {
                        AliasTy {
                            args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            kind: __binding_1,
                            _use_alias_ty_new_instead: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for AliasTy<I>
            where I: Interner, J: Interner,
            I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::GenericArgs>,
            AliasTyKind<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            AliasTyKind<J>>, (): ::rustc_type_ir::lift::Lift<J, Lifted = ()> {
            type Lifted = AliasTy<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        AliasTy {
                            args: __binding_0,
                            kind: __binding_1,
                            _use_alias_ty_new_instead: __binding_2 } => {
                            AliasTy {
                                args: __binding_0.lift_to_interner(interner)?,
                                kind: __binding_1.lift_to_interner(interner)?,
                                _use_alias_ty_new_instead: __binding_2.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
440#[cfg_attr(
441    feature = "nightly",
442    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for AliasTy<I> where
            I::GenericArgs: ::rustc_serialize::Decodable<__D>,
            AliasTyKind<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                AliasTy {
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                    _use_alias_ty_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for AliasTy<I> where
            I::GenericArgs: ::rustc_serialize::Encodable<__E>,
            AliasTyKind<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    AliasTy {
                        args: ref __binding_0,
                        kind: ref __binding_1,
                        _use_alias_ty_new_instead: 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);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            AliasTy<I> where
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            AliasTyKind<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    AliasTy {
                        args: ref __binding_0,
                        kind: ref __binding_1,
                        _use_alias_ty_new_instead: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
443)]
444pub struct AliasTy<I: Interner> {
445    /// The parameters of the associated or opaque type.
446    ///
447    /// For a projection, these are the generic parameters for the trait and the
448    /// GAT parameters, if there are any.
449    ///
450    /// For an inherent projection, they consist of the self type and the GAT parameters,
451    /// if there are any.
452    ///
453    /// For RPIT the generic parameters are for the generics of the function,
454    /// while for TAIT it is used for the generic parameters of the alias.
455    pub args: I::GenericArgs,
456
457    #[type_foldable(identity)]
458    #[type_visitable(ignore)]
459    pub kind: AliasTyKind<I>,
460
461    /// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new_from_args`].
462    #[derive_where(skip(Debug))]
463    pub(crate) _use_alias_ty_new_instead: (),
464}
465
466impl<I: Interner> Eq for AliasTy<I> {}
467
468impl<I: Interner> AliasTy<I> {
469    pub fn new_from_args(interner: I, kind: AliasTyKind<I>, args: I::GenericArgs) -> AliasTy<I> {
470        interner.debug_assert_args_compatible(kind.def_id(), args);
471        AliasTy { kind, args, _use_alias_ty_new_instead: () }
472    }
473
474    pub fn new(
475        interner: I,
476        kind: AliasTyKind<I>,
477        args: impl IntoIterator<Item: Into<I::GenericArg>>,
478    ) -> AliasTy<I> {
479        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
480        Self::new_from_args(interner, kind, args)
481    }
482
483    /// Whether this alias type is an opaque.
484    pub fn is_opaque(self) -> bool {
485        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    AliasTyKind::Opaque { .. } => true,
    _ => false,
}matches!(self.kind, AliasTyKind::Opaque { .. })
486    }
487
488    pub fn to_ty(self, interner: I) -> I::Ty {
489        Ty::new_alias(interner, self)
490    }
491}
492
493/// The following methods work only with (trait) associated type projections.
494impl<I: Interner> AliasTy<I> {
495    #[track_caller]
496    pub fn self_ty(self) -> I::Ty {
497        self.args.type_at(0)
498    }
499
500    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
501        AliasTy::new(
502            interner,
503            self.kind,
504            [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
505        )
506    }
507
508    pub fn trait_def_id(self, interner: I) -> I::DefId {
509        let AliasTyKind::Projection { def_id } = self.kind else { { ::core::panicking::panic_fmt(format_args!("expected a projection")); }panic!("expected a projection") };
510
511        interner.parent(def_id)
512    }
513
514    /// Extracts the underlying trait reference and own args from this projection.
515    ///
516    /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
517    /// then this function would return a `T: StreamingIterator` trait reference and
518    /// `['a]` as the own args.
519    pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) {
520        let AliasTyKind::Projection { def_id } = self.kind else { { ::core::panicking::panic_fmt(format_args!("expected a projection")); }panic!("expected a projection") };
521
522        interner.trait_ref_and_own_args_for_alias(def_id, self.args)
523    }
524
525    /// Extracts the underlying trait reference from this projection.
526    ///
527    /// For example, if this is a projection of `<T as Iterator>::Item`,
528    /// then this function would return a `T: Iterator` trait reference.
529    ///
530    /// WARNING: This will drop the args for generic associated types
531    /// consider calling [Self::trait_ref_and_own_args] to get those
532    /// as well.
533    pub fn trait_ref(self, interner: I) -> ty::TraitRef<I> {
534        self.trait_ref_and_own_args(interner).0
535    }
536}
537
538#[derive(#[automatically_derived]
impl ::core::clone::Clone for IntVarValue {
    #[inline]
    fn clone(&self) -> IntVarValue {
        let _: ::core::clone::AssertParamIsClone<IntTy>;
        let _: ::core::clone::AssertParamIsClone<UintTy>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IntVarValue { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for IntVarValue {
    #[inline]
    fn eq(&self, other: &IntVarValue) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (IntVarValue::IntType(__self_0),
                    IntVarValue::IntType(__arg1_0)) => __self_0 == __arg1_0,
                (IntVarValue::UintType(__self_0),
                    IntVarValue::UintType(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IntVarValue {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<IntTy>;
        let _: ::core::cmp::AssertParamIsEq<UintTy>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for IntVarValue {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            IntVarValue::Unknown =>
                ::core::fmt::Formatter::write_str(f, "Unknown"),
            IntVarValue::IntType(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "IntType", &__self_0),
            IntVarValue::UintType(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "UintType", &__self_0),
        }
    }
}Debug)]
539pub enum IntVarValue {
540    Unknown,
541    IntType(IntTy),
542    UintType(UintTy),
543}
544
545impl IntVarValue {
546    pub fn is_known(self) -> bool {
547        match self {
548            IntVarValue::IntType(_) | IntVarValue::UintType(_) => true,
549            IntVarValue::Unknown => false,
550        }
551    }
552
553    pub fn is_unknown(self) -> bool {
554        !self.is_known()
555    }
556}
557
558#[derive(#[automatically_derived]
impl ::core::clone::Clone for FloatVarValue {
    #[inline]
    fn clone(&self) -> FloatVarValue {
        let _: ::core::clone::AssertParamIsClone<FloatTy>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for FloatVarValue { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for FloatVarValue {
    #[inline]
    fn eq(&self, other: &FloatVarValue) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (FloatVarValue::Known(__self_0),
                    FloatVarValue::Known(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FloatVarValue {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<FloatTy>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for FloatVarValue {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            FloatVarValue::Unknown =>
                ::core::fmt::Formatter::write_str(f, "Unknown"),
            FloatVarValue::Known(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Known",
                    &__self_0),
        }
    }
}Debug)]
559pub enum FloatVarValue {
560    Unknown,
561    Known(FloatTy),
562}
563
564impl FloatVarValue {
565    pub fn is_known(self) -> bool {
566        match self {
567            FloatVarValue::Known(_) => true,
568            FloatVarValue::Unknown => false,
569        }
570    }
571
572    pub fn is_unknown(self) -> bool {
573        !self.is_known()
574    }
575}
576
577impl ::std::fmt::Debug for TyVid {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
        fmt.write_fmt(format_args!("?{0}t", self.as_u32()))
    }
}rustc_index::newtype_index! {
578    /// A **ty**pe **v**ariable **ID**.
579    #[encodable]
580    #[orderable]
581    #[debug_format = "?{}t"]
582    #[gate_rustc_only]
583    pub struct TyVid {}
584}
585
586impl ::std::fmt::Debug for IntVid {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
        fmt.write_fmt(format_args!("?{0}i", self.as_u32()))
    }
}rustc_index::newtype_index! {
587    /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
588    #[encodable]
589    #[orderable]
590    #[debug_format = "?{}i"]
591    #[gate_rustc_only]
592    pub struct IntVid {}
593}
594
595impl ::std::fmt::Debug for FloatVid {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
        fmt.write_fmt(format_args!("?{0}f", self.as_u32()))
    }
}rustc_index::newtype_index! {
596    /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
597    #[encodable]
598    #[orderable]
599    #[debug_format = "?{}f"]
600    #[gate_rustc_only]
601    pub struct FloatVid {}
602}
603
604/// A placeholder for a type that hasn't been inferred yet.
605///
606/// E.g., if we have an empty array (`[]`), then we create a fresh
607/// type variable for the element type since we won't know until it's
608/// used what the element type is supposed to be.
609#[derive(#[automatically_derived]
impl ::core::clone::Clone for InferTy {
    #[inline]
    fn clone(&self) -> InferTy {
        let _: ::core::clone::AssertParamIsClone<TyVid>;
        let _: ::core::clone::AssertParamIsClone<IntVid>;
        let _: ::core::clone::AssertParamIsClone<FloatVid>;
        let _: ::core::clone::AssertParamIsClone<u32>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for InferTy { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for InferTy {
    #[inline]
    fn eq(&self, other: &InferTy) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (InferTy::TyVar(__self_0), InferTy::TyVar(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (InferTy::IntVar(__self_0), InferTy::IntVar(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (InferTy::FloatVar(__self_0), InferTy::FloatVar(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (InferTy::FreshTy(__self_0), InferTy::FreshTy(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (InferTy::FreshIntTy(__self_0), InferTy::FreshIntTy(__arg1_0))
                    => __self_0 == __arg1_0,
                (InferTy::FreshFloatTy(__self_0),
                    InferTy::FreshFloatTy(__arg1_0)) => __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for InferTy {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<TyVid>;
        let _: ::core::cmp::AssertParamIsEq<IntVid>;
        let _: ::core::cmp::AssertParamIsEq<FloatVid>;
        let _: ::core::cmp::AssertParamIsEq<u32>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for InferTy {
    #[inline]
    fn partial_cmp(&self, other: &InferTy)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match (self, other) {
            (InferTy::TyVar(__self_0), InferTy::TyVar(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (InferTy::IntVar(__self_0), InferTy::IntVar(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (InferTy::FloatVar(__self_0), InferTy::FloatVar(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (InferTy::FreshTy(__self_0), InferTy::FreshTy(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (InferTy::FreshIntTy(__self_0), InferTy::FreshIntTy(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (InferTy::FreshFloatTy(__self_0), InferTy::FreshFloatTy(__arg1_0))
                => ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            _ =>
                ::core::cmp::PartialOrd::partial_cmp(&__self_discr,
                    &__arg1_discr),
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for InferTy {
    #[inline]
    fn cmp(&self, other: &InferTy) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
            ::core::cmp::Ordering::Equal =>
                match (self, other) {
                    (InferTy::TyVar(__self_0), InferTy::TyVar(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (InferTy::IntVar(__self_0), InferTy::IntVar(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (InferTy::FloatVar(__self_0), InferTy::FloatVar(__arg1_0))
                        => ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (InferTy::FreshTy(__self_0), InferTy::FreshTy(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (InferTy::FreshIntTy(__self_0),
                        InferTy::FreshIntTy(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (InferTy::FreshFloatTy(__self_0),
                        InferTy::FreshFloatTy(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    _ => unsafe { ::core::intrinsics::unreachable() }
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for InferTy {
    #[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 {
            InferTy::TyVar(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InferTy::IntVar(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InferTy::FloatVar(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InferTy::FreshTy(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InferTy::FreshIntTy(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            InferTy::FreshFloatTy(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
        }
    }
}Hash)]
610#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for InferTy {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        InferTy::TyVar(ref __binding_0) => { 0usize }
                        InferTy::IntVar(ref __binding_0) => { 1usize }
                        InferTy::FloatVar(ref __binding_0) => { 2usize }
                        InferTy::FreshTy(ref __binding_0) => { 3usize }
                        InferTy::FreshIntTy(ref __binding_0) => { 4usize }
                        InferTy::FreshFloatTy(ref __binding_0) => { 5usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    InferTy::TyVar(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InferTy::IntVar(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InferTy::FloatVar(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InferTy::FreshTy(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InferTy::FreshIntTy(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InferTy::FreshFloatTy(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for InferTy {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        InferTy::TyVar(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        InferTy::IntVar(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        InferTy::FloatVar(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => {
                        InferTy::FreshTy(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        InferTy::FreshIntTy(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    5usize => {
                        InferTy::FreshFloatTy(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InferTy`, expected 0..6, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext))]
611pub enum InferTy {
612    /// A type variable.
613    TyVar(TyVid),
614    /// An integral type variable (`{integer}`).
615    ///
616    /// These are created when the compiler sees an integer literal like
617    /// `1` that could be several different types (`u8`, `i32`, `u32`, etc.).
618    /// We don't know until it's used what type it's supposed to be, so
619    /// we create a fresh type variable.
620    IntVar(IntVid),
621    /// A floating-point type variable (`{float}`).
622    ///
623    /// These are created when the compiler sees an float literal like
624    /// `1.0` that could be either an `f32` or an `f64`.
625    /// We don't know until it's used what type it's supposed to be, so
626    /// we create a fresh type variable.
627    FloatVar(FloatVid),
628
629    /// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement
630    /// for an unbound type variable.
631    ///
632    /// This is convenient for caching etc. See `TypeFreshener` for more details.
633    ///
634    /// Compare with [`TyVar`][Self::TyVar].
635    FreshTy(u32),
636    /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar].
637    FreshIntTy(u32),
638    /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar].
639    FreshFloatTy(u32),
640}
641
642impl UnifyValue for IntVarValue {
643    type Error = NoError;
644
645    fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
646        match (*value1, *value2) {
647            (IntVarValue::Unknown, IntVarValue::Unknown) => Ok(IntVarValue::Unknown),
648            (
649                IntVarValue::Unknown,
650                known @ (IntVarValue::UintType(_) | IntVarValue::IntType(_)),
651            )
652            | (
653                known @ (IntVarValue::UintType(_) | IntVarValue::IntType(_)),
654                IntVarValue::Unknown,
655            ) => Ok(known),
656            _ => {
    ::core::panicking::panic_fmt(format_args!("differing ints should have been resolved first"));
}panic!("differing ints should have been resolved first"),
657        }
658    }
659}
660
661impl UnifyKey for IntVid {
662    type Value = IntVarValue;
663    #[inline] // make this function eligible for inlining - it is quite hot.
664    fn index(&self) -> u32 {
665        self.as_u32()
666    }
667    #[inline]
668    fn from_index(i: u32) -> IntVid {
669        IntVid::from_u32(i)
670    }
671    fn tag() -> &'static str {
672        "IntVid"
673    }
674}
675
676impl UnifyValue for FloatVarValue {
677    type Error = NoError;
678
679    fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
680        match (*value1, *value2) {
681            (FloatVarValue::Unknown, FloatVarValue::Unknown) => Ok(FloatVarValue::Unknown),
682            (FloatVarValue::Unknown, FloatVarValue::Known(known))
683            | (FloatVarValue::Known(known), FloatVarValue::Unknown) => {
684                Ok(FloatVarValue::Known(known))
685            }
686            (FloatVarValue::Known(_), FloatVarValue::Known(_)) => {
687                {
    ::core::panicking::panic_fmt(format_args!("differing floats should have been resolved first"));
}panic!("differing floats should have been resolved first")
688            }
689        }
690    }
691}
692
693impl UnifyKey for FloatVid {
694    type Value = FloatVarValue;
695    #[inline]
696    fn index(&self) -> u32 {
697        self.as_u32()
698    }
699    #[inline]
700    fn from_index(i: u32) -> FloatVid {
701        FloatVid::from_u32(i)
702    }
703    fn tag() -> &'static str {
704        "FloatVid"
705    }
706}
707
708#[cfg(feature = "nightly")]
709impl<Hcx> HashStable<Hcx> for InferTy {
710    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
711        use InferTy::*;
712        std::mem::discriminant(self).hash_stable(hcx, hasher);
713        match self {
714            TyVar(_) | IntVar(_) | FloatVar(_) => {
715                {
    ::core::panicking::panic_fmt(format_args!("type variables should not be hashed: {0:?}",
            self));
}panic!("type variables should not be hashed: {self:?}")
716            }
717            FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(hcx, hasher),
718        }
719    }
720}
721
722impl fmt::Display for InferTy {
723    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
724        use InferTy::*;
725        match *self {
726            TyVar(_) => f.write_fmt(format_args!("_"))write!(f, "_"),
727            IntVar(_) => f.write_fmt(format_args!("{0}", "{integer}"))write!(f, "{}", "{integer}"),
728            FloatVar(_) => f.write_fmt(format_args!("{0}", "{float}"))write!(f, "{}", "{float}"),
729            FreshTy(v) => f.write_fmt(format_args!("FreshTy({0})", v))write!(f, "FreshTy({v})"),
730            FreshIntTy(v) => f.write_fmt(format_args!("FreshIntTy({0})", v))write!(f, "FreshIntTy({v})"),
731            FreshFloatTy(v) => f.write_fmt(format_args!("FreshFloatTy({0})", v))write!(f, "FreshFloatTy({v})"),
732        }
733    }
734}
735
736impl fmt::Debug for InferTy {
737    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
738        use InferTy::*;
739        match *self {
740            TyVar(ref v) => v.fmt(f),
741            IntVar(ref v) => v.fmt(f),
742            FloatVar(ref v) => v.fmt(f),
743            FreshTy(v) => f.write_fmt(format_args!("FreshTy({0:?})", v))write!(f, "FreshTy({v:?})"),
744            FreshIntTy(v) => f.write_fmt(format_args!("FreshIntTy({0:?})", v))write!(f, "FreshIntTy({v:?})"),
745            FreshFloatTy(v) => f.write_fmt(format_args!("FreshFloatTy({0:?})", v))write!(f, "FreshFloatTy({v:?})"),
746        }
747    }
748}
749
750#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for TypeAndMut<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            TypeAndMut { ty: ref __field_ty, mutbl: ref __field_mutbl } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "TypeAndMut");
                ::core::fmt::DebugStruct::field(&mut __builder, "ty",
                    __field_ty);
                ::core::fmt::DebugStruct::field(&mut __builder, "mutbl",
                    __field_mutbl);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)]
751#[cfg_attr(
752    feature = "nightly",
753    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for TypeAndMut<I> where
            I::Ty: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    TypeAndMut { ty: ref __binding_0, mutbl: ref __binding_1 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for TypeAndMut<I> where
            I::Ty: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                TypeAndMut {
                    ty: ::rustc_serialize::Decodable::decode(__decoder),
                    mutbl: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            TypeAndMut<I> where
            I::Ty: ::rustc_data_structures::stable_hasher::HashStable<__CTX> {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    TypeAndMut { ty: ref __binding_0, mutbl: ref __binding_1 }
                        => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
754)]
755#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for TypeAndMut<I>
            where I: Interner, I::Ty: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    TypeAndMut { ty: ref __binding_0, mutbl: ref __binding_1 }
                        => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for TypeAndMut<I>
            where I: Interner, I::Ty: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        TypeAndMut { ty: __binding_0, mutbl: __binding_1 } => {
                            TypeAndMut {
                                ty: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                mutbl: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    TypeAndMut { ty: __binding_0, mutbl: __binding_1 } => {
                        TypeAndMut {
                            ty: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            mutbl: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
756pub struct TypeAndMut<I: Interner> {
757    pub ty: I::Ty,
758    pub mutbl: Mutability,
759}
760
761impl<I: Interner> Eq for TypeAndMut<I> {}
762
763/// Contains the packed non-type fields of a function signature.
764// FIXME(splat): add the splatted argument index as a u16
765#[derive(#[automatically_derived]
impl ::core::marker::Copy for FnSigKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FnSigKind {
    #[inline]
    fn clone(&self) -> FnSigKind {
        let _: ::core::clone::AssertParamIsClone<u8>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for FnSigKind {
    #[inline]
    fn eq(&self, other: &FnSigKind) -> bool { self.flags == other.flags }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FnSigKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<u8>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for FnSigKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.flags, state)
    }
}Hash)]
766#[cfg_attr(
767    feature = "nightly",
768    derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for FnSigKind {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FnSigKind { flags: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for FnSigKind {
            fn decode(__decoder: &mut __D) -> Self {
                FnSigKind {
                    flags: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for FnSigKind {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    FnSigKind { flags: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
769)]
770pub struct FnSigKind {
771    /// Holds the c_variadic and safety bitflags, and 6 bits for the `ExternAbi` variant and unwind
772    /// flag.
773    flags: u8,
774}
775
776impl fmt::Debug for FnSigKind {
777    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
778        let mut f = f.debug_tuple("FnSigKind");
779
780        if self.is_safe() {
781            f.field(&"Safe");
782        } else {
783            f.field(&"Unsafe");
784        }
785
786        f.field(&self.abi());
787
788        if self.c_variadic() {
789            f.field(&"CVariadic");
790        };
791
792        f.finish()
793    }
794}
795
796impl FnSigKind {
797    /// Mask for the `ExternAbi` variant, including the unwind flag.
798    const EXTERN_ABI_MASK: u8 = 0b111111;
799
800    /// Bitflag for `Safety::Safe`. The default is `Unsafe`.
801    const SAFE_FLAG: u8 = 1 << 6;
802
803    /// Bitflag for a trailing C-style variadic argument.
804    const C_VARIADIC_FLAG: u8 = 1 << 7;
805
806    /// Create a new FnSigKind with the "Rust" ABI, "Unsafe" safety, and no C-style variadic argument.
807    /// To modify these flags, use the `set_*` methods, for readability.
808    // FIXME: use Default instead when that trait is const stable.
809    pub const fn default() -> Self {
810        Self { flags: 0 }.set_abi(ExternAbi::Rust).set_safe(false).set_c_variadic(false)
811    }
812
813    /// Set the ABI, including the unwind flag.
814    #[must_use = "this method does not modify the receiver"]
815    pub const fn set_abi(mut self, abi: ExternAbi) -> Self {
816        let abi_index = abi.as_packed();
817        if !(abi_index <= Self::EXTERN_ABI_MASK) {
    ::core::panicking::panic("assertion failed: abi_index <= Self::EXTERN_ABI_MASK")
};assert!(abi_index <= Self::EXTERN_ABI_MASK);
818
819        self.flags &= !Self::EXTERN_ABI_MASK;
820        self.flags |= abi_index;
821
822        self
823    }
824
825    /// Set the safety flag, `true` is `Safe`.
826    #[must_use = "this method does not modify the receiver"]
827    pub const fn set_safe(mut self, is_safe: bool) -> Self {
828        if is_safe {
829            self.flags |= Self::SAFE_FLAG;
830        } else {
831            self.flags &= !Self::SAFE_FLAG;
832        }
833
834        self
835    }
836
837    /// Set the C-style variadic argument flag.
838    #[must_use = "this method does not modify the receiver"]
839    pub const fn set_c_variadic(mut self, c_variadic: bool) -> Self {
840        if c_variadic {
841            self.flags |= Self::C_VARIADIC_FLAG;
842        } else {
843            self.flags &= !Self::C_VARIADIC_FLAG;
844        }
845
846        self
847    }
848
849    /// Get the ABI, including the unwind flag.
850    pub const fn abi(self) -> ExternAbi {
851        let abi_index = self.flags & Self::EXTERN_ABI_MASK;
852        ExternAbi::from_packed(abi_index)
853    }
854
855    /// Get the safety flag.
856    pub const fn is_safe(self) -> bool {
857        self.flags & Self::SAFE_FLAG != 0
858    }
859
860    /// Do the function arguments end with a C-style variadic argument?
861    pub const fn c_variadic(self) -> bool {
862        self.flags & Self::C_VARIADIC_FLAG != 0
863    }
864}
865
866#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for FnSig<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            FnSig {
                inputs_and_output: ref __field_inputs_and_output,
                fn_sig_kind: ref __field_fn_sig_kind } => {
                ::core::hash::Hash::hash(__field_inputs_and_output, __state);
                ::core::hash::Hash::hash(__field_fn_sig_kind, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)]
867#[cfg_attr(
868    feature = "nightly",
869    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for FnSig<I> where
            I::Tys: ::rustc_serialize::Encodable<__E>,
            I::FSigKind: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FnSig {
                        inputs_and_output: ref __binding_0,
                        fn_sig_kind: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for FnSig<I> where
            I::Tys: ::rustc_serialize::Decodable<__D>,
            I::FSigKind: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                FnSig {
                    inputs_and_output: ::rustc_serialize::Decodable::decode(__decoder),
                    fn_sig_kind: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            FnSig<I> where
            I::Tys: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::FSigKind: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    FnSig {
                        inputs_and_output: ref __binding_0,
                        fn_sig_kind: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
870)]
871#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for FnSig<I> where
            I: Interner, I::Tys: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    FnSig { inputs_and_output: ref __binding_0, .. } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for FnSig<I> where
            I: Interner, I::Tys: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        FnSig {
                            inputs_and_output: __binding_0, fn_sig_kind: __binding_1 }
                            => {
                            FnSig {
                                inputs_and_output: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                fn_sig_kind: __binding_1,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    FnSig {
                        inputs_and_output: __binding_0, fn_sig_kind: __binding_1 }
                        => {
                        FnSig {
                            inputs_and_output: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            fn_sig_kind: __binding_1,
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for FnSig<I> where
            I: Interner, J: Interner,
            I::Tys: ::rustc_type_ir::lift::Lift<J, Lifted = J::Tys>,
            I::FSigKind: ::rustc_type_ir::lift::Lift<J, Lifted = J::FSigKind>
            {
            type Lifted = FnSig<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        FnSig {
                            inputs_and_output: __binding_0, fn_sig_kind: __binding_1 }
                            => {
                            FnSig {
                                inputs_and_output: __binding_0.lift_to_interner(interner)?,
                                fn_sig_kind: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
872pub struct FnSig<I: Interner> {
873    pub inputs_and_output: I::Tys,
874    #[type_visitable(ignore)]
875    #[type_foldable(identity)]
876    pub fn_sig_kind: I::FSigKind,
877}
878
879impl<I: Interner> Eq for FnSig<I> {}
880
881impl<I: Interner> FnSig<I> {
882    pub fn inputs(self) -> I::FnInputTys {
883        self.inputs_and_output.inputs()
884    }
885
886    pub fn output(self) -> I::Ty {
887        self.inputs_and_output.output()
888    }
889
890    pub fn is_fn_trait_compatible(self) -> bool {
891        !self.c_variadic() && self.safety().is_safe() && self.abi().is_rust()
892    }
893
894    pub fn set_safe(self, is_safe: bool) -> Self {
895        Self {
896            fn_sig_kind: I::FSigKind::new(
897                self.abi(),
898                if is_safe { I::Safety::safe() } else { I::Safety::unsafe_mode() },
899                self.c_variadic(),
900            ),
901            ..self
902        }
903    }
904
905    pub fn safety(self) -> I::Safety {
906        self.fn_sig_kind.safety()
907    }
908
909    pub fn abi(self) -> I::Abi {
910        self.fn_sig_kind.abi()
911    }
912
913    pub fn c_variadic(self) -> bool {
914        self.fn_sig_kind.c_variadic()
915    }
916
917    pub fn dummy() -> Self {
918        Self {
919            inputs_and_output: Default::default(),
920            fn_sig_kind: I::FSigKind::new(I::Abi::rust(), I::Safety::safe(), false),
921        }
922    }
923}
924
925impl<I: Interner> ty::Binder<I, FnSig<I>> {
926    #[inline]
927    pub fn inputs(self) -> ty::Binder<I, I::FnInputTys> {
928        self.map_bound(|fn_sig| fn_sig.inputs())
929    }
930
931    #[inline]
932    #[track_caller]
933    pub fn input(self, index: usize) -> ty::Binder<I, I::Ty> {
934        self.map_bound(|fn_sig| fn_sig.inputs().get(index).unwrap())
935    }
936
937    pub fn inputs_and_output(self) -> ty::Binder<I, I::Tys> {
938        self.map_bound(|fn_sig| fn_sig.inputs_and_output)
939    }
940
941    #[inline]
942    pub fn output(self) -> ty::Binder<I, I::Ty> {
943        self.map_bound(|fn_sig| fn_sig.output())
944    }
945
946    pub fn fn_sig_kind(self) -> I::FSigKind {
947        self.skip_binder().fn_sig_kind
948    }
949
950    pub fn c_variadic(self) -> bool {
951        self.skip_binder().c_variadic()
952    }
953
954    pub fn safety(self) -> I::Safety {
955        self.skip_binder().safety()
956    }
957
958    pub fn abi(self) -> I::Abi {
959        self.skip_binder().abi()
960    }
961
962    pub fn is_fn_trait_compatible(&self) -> bool {
963        self.skip_binder().is_fn_trait_compatible()
964    }
965
966    // Used to split a single value into the two fields in `TyKind::FnPtr`.
967    pub fn split(self) -> (ty::Binder<I, FnSigTys<I>>, FnHeader<I>) {
968        let hdr = FnHeader { fn_sig_kind: self.fn_sig_kind() };
969        (self.map_bound(|sig| FnSigTys { inputs_and_output: sig.inputs_and_output }), hdr)
970    }
971}
972
973impl<I: Interner> fmt::Debug for FnSig<I> {
974    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
975        let sig = self;
976        let FnSig { inputs_and_output: _, fn_sig_kind } = sig;
977
978        f.write_fmt(format_args!("{0}", fn_sig_kind.safety().prefix_str()))write!(f, "{}", fn_sig_kind.safety().prefix_str())?;
979        if !fn_sig_kind.abi().is_rust() {
980            f.write_fmt(format_args!("extern \"{0:?}\" ", fn_sig_kind.abi()))write!(f, "extern \"{:?}\" ", fn_sig_kind.abi())?;
981        }
982
983        f.write_fmt(format_args!("fn("))write!(f, "fn(")?;
984        let inputs = sig.inputs();
985        for (i, ty) in inputs.iter().enumerate() {
986            if i > 0 {
987                f.write_fmt(format_args!(", "))write!(f, ", ")?;
988            }
989            f.write_fmt(format_args!("{0:?}", ty))write!(f, "{ty:?}")?;
990        }
991        if fn_sig_kind.c_variadic() {
992            if inputs.is_empty() {
993                f.write_fmt(format_args!("..."))write!(f, "...")?;
994            } else {
995                f.write_fmt(format_args!(", ..."))write!(f, ", ...")?;
996            }
997        }
998        f.write_fmt(format_args!(")"))write!(f, ")")?;
999
1000        let output = sig.output();
1001        match output.kind() {
1002            Tuple(list) if list.is_empty() => Ok(()),
1003            _ => f.write_fmt(format_args!(" -> {0:?}", sig.output()))write!(f, " -> {:?}", sig.output()),
1004        }
1005    }
1006}
1007
1008// FIXME: this is a distinct type because we need to define `Encode`/`Decode`
1009// impls in this crate for `Binder<I, I::Ty>`.
1010#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for UnsafeBinderInner<I> where
    I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            UnsafeBinderInner(ref __field_0) => {
                ::core::hash::Hash::hash(__field_0, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)]
1011#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            UnsafeBinderInner<I> where
            ty::Binder<I,
            I::Ty>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    UnsafeBinderInner(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext))]
1012#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            UnsafeBinderInner<I> where I: Interner,
            ty::Binder<I, I::Ty>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    UnsafeBinderInner(ref __binding_0) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            UnsafeBinderInner<I> where I: Interner,
            ty::Binder<I, I::Ty>: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        UnsafeBinderInner(__binding_0) => {
                            UnsafeBinderInner(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    UnsafeBinderInner(__binding_0) => {
                        UnsafeBinderInner(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            UnsafeBinderInner<I> where I: Interner, J: Interner,
            ty::Binder<I,
            I::Ty>: ::rustc_type_ir::lift::Lift<J, Lifted =
            ty::Binder<J, J::Ty>> {
            type Lifted = UnsafeBinderInner<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        UnsafeBinderInner(__binding_0) => {
                            UnsafeBinderInner(__binding_0.lift_to_interner(interner)?)
                        }
                    })
            }
        }
    };Lift_Generic)]
1013pub struct UnsafeBinderInner<I: Interner>(ty::Binder<I, I::Ty>);
1014
1015impl<I: Interner> Eq for UnsafeBinderInner<I> {}
1016
1017impl<I: Interner> From<ty::Binder<I, I::Ty>> for UnsafeBinderInner<I> {
1018    fn from(value: ty::Binder<I, I::Ty>) -> Self {
1019        UnsafeBinderInner(value)
1020    }
1021}
1022
1023impl<I: Interner> From<UnsafeBinderInner<I>> for ty::Binder<I, I::Ty> {
1024    fn from(value: UnsafeBinderInner<I>) -> Self {
1025        value.0
1026    }
1027}
1028
1029impl<I: Interner> fmt::Debug for UnsafeBinderInner<I> {
1030    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1031        self.0.fmt(f)
1032    }
1033}
1034
1035impl<I: Interner> Deref for UnsafeBinderInner<I> {
1036    type Target = ty::Binder<I, I::Ty>;
1037
1038    fn deref(&self) -> &Self::Target {
1039        &self.0
1040    }
1041}
1042
1043#[cfg(feature = "nightly")]
1044impl<I: Interner, E: rustc_serialize::Encoder> rustc_serialize::Encodable<E>
1045    for UnsafeBinderInner<I>
1046where
1047    I::Ty: rustc_serialize::Encodable<E>,
1048    I::BoundVarKinds: rustc_serialize::Encodable<E>,
1049{
1050    fn encode(&self, e: &mut E) {
1051        self.bound_vars().encode(e);
1052        self.as_ref().skip_binder().encode(e);
1053    }
1054}
1055
1056#[cfg(feature = "nightly")]
1057impl<I: Interner, D: rustc_serialize::Decoder> rustc_serialize::Decodable<D>
1058    for UnsafeBinderInner<I>
1059where
1060    I::Ty: TypeVisitable<I> + rustc_serialize::Decodable<D>,
1061    I::BoundVarKinds: rustc_serialize::Decodable<D>,
1062{
1063    fn decode(decoder: &mut D) -> Self {
1064        let bound_vars = rustc_serialize::Decodable::decode(decoder);
1065        UnsafeBinderInner(ty::Binder::bind_with_vars(
1066            rustc_serialize::Decodable::decode(decoder),
1067            bound_vars,
1068        ))
1069    }
1070}
1071
1072// This is just a `FnSig` without the `FnHeader` fields.
1073#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for FnSigTys<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            FnSigTys { inputs_and_output: ref __field_inputs_and_output } => {
                ::core::hash::Hash::hash(__field_inputs_and_output, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)]
1074#[cfg_attr(
1075    feature = "nightly",
1076    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for FnSigTys<I> where
            I::Tys: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FnSigTys { inputs_and_output: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for FnSigTys<I> where
            I::Tys: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                FnSigTys {
                    inputs_and_output: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            FnSigTys<I> where
            I::Tys: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    FnSigTys { inputs_and_output: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
1077)]
1078#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for FnSigTys<I>
            where I: Interner, I::Tys: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    FnSigTys { inputs_and_output: ref __binding_0 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for FnSigTys<I>
            where I: Interner, I::Tys: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        FnSigTys { inputs_and_output: __binding_0 } => {
                            FnSigTys {
                                inputs_and_output: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    FnSigTys { inputs_and_output: __binding_0 } => {
                        FnSigTys {
                            inputs_and_output: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for FnSigTys<I>
            where I: Interner, J: Interner,
            I::Tys: ::rustc_type_ir::lift::Lift<J, Lifted = J::Tys> {
            type Lifted = FnSigTys<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        FnSigTys { inputs_and_output: __binding_0 } => {
                            FnSigTys {
                                inputs_and_output: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
1079pub struct FnSigTys<I: Interner> {
1080    pub inputs_and_output: I::Tys,
1081}
1082
1083impl<I: Interner> Eq for FnSigTys<I> {}
1084
1085impl<I: Interner> FnSigTys<I> {
1086    pub fn inputs(self) -> I::FnInputTys {
1087        self.inputs_and_output.inputs()
1088    }
1089
1090    pub fn output(self) -> I::Ty {
1091        self.inputs_and_output.output()
1092    }
1093}
1094
1095impl<I: Interner> ty::Binder<I, FnSigTys<I>> {
1096    // Used to combine the two fields in `TyKind::FnPtr` into a single value.
1097    pub fn with(self, hdr: FnHeader<I>) -> ty::Binder<I, FnSig<I>> {
1098        self.map_bound(|sig_tys| FnSig {
1099            inputs_and_output: sig_tys.inputs_and_output,
1100            fn_sig_kind: hdr.fn_sig_kind,
1101        })
1102    }
1103
1104    #[inline]
1105    pub fn inputs(self) -> ty::Binder<I, I::FnInputTys> {
1106        self.map_bound(|sig_tys| sig_tys.inputs())
1107    }
1108
1109    #[inline]
1110    #[track_caller]
1111    pub fn input(self, index: usize) -> ty::Binder<I, I::Ty> {
1112        self.map_bound(|sig_tys| sig_tys.inputs().get(index).unwrap())
1113    }
1114
1115    pub fn inputs_and_output(self) -> ty::Binder<I, I::Tys> {
1116        self.map_bound(|sig_tys| sig_tys.inputs_and_output)
1117    }
1118
1119    #[inline]
1120    pub fn output(self) -> ty::Binder<I, I::Ty> {
1121        self.map_bound(|sig_tys| sig_tys.output())
1122    }
1123}
1124
1125#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for FnHeader<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            FnHeader { fn_sig_kind: ref __field_fn_sig_kind } => {
                ::core::hash::Hash::hash(__field_fn_sig_kind, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)]
1126#[cfg_attr(
1127    feature = "nightly",
1128    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for FnHeader<I> where
            I::FSigKind: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FnHeader { fn_sig_kind: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for FnHeader<I> where
            I::FSigKind: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                FnHeader {
                    fn_sig_kind: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            FnHeader<I> where
            I::FSigKind: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    FnHeader { fn_sig_kind: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
1129)]
1130#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for FnHeader<I>
            where I: Interner {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self { FnHeader { .. } => {} }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for FnHeader<I>
            where I: Interner {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        FnHeader { fn_sig_kind: __binding_0 } => {
                            FnHeader { fn_sig_kind: __binding_0 }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    FnHeader { fn_sig_kind: __binding_0 } => {
                        FnHeader { fn_sig_kind: __binding_0 }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for FnHeader<I>
            where I: Interner, J: Interner,
            I::FSigKind: ::rustc_type_ir::lift::Lift<J, Lifted = J::FSigKind>
            {
            type Lifted = FnHeader<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        FnHeader { fn_sig_kind: __binding_0 } => {
                            FnHeader {
                                fn_sig_kind: __binding_0.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
1131pub struct FnHeader<I: Interner> {
1132    #[type_visitable(ignore)]
1133    #[type_foldable(identity)]
1134    pub fn_sig_kind: I::FSigKind,
1135}
1136
1137impl<I: Interner> FnHeader<I> {
1138    pub fn c_variadic(self) -> bool {
1139        self.fn_sig_kind.c_variadic()
1140    }
1141
1142    pub fn safety(self) -> I::Safety {
1143        self.fn_sig_kind.safety()
1144    }
1145
1146    pub fn abi(self) -> I::Abi {
1147        self.fn_sig_kind.abi()
1148    }
1149
1150    pub fn dummy() -> Self {
1151        Self { fn_sig_kind: I::FSigKind::new(I::Abi::rust(), I::Safety::safe(), false) }
1152    }
1153}
1154
1155impl<I: Interner> Eq for FnHeader<I> {}
1156
1157#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for CoroutineWitnessTypes<I> where
    I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            CoroutineWitnessTypes {
                types: ref __field_types, assumptions: ref __field_assumptions
                } => {
                ::core::hash::Hash::hash(__field_types, __state);
                ::core::hash::Hash::hash(__field_assumptions, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)]
1158#[cfg_attr(
1159    feature = "nightly",
1160    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for CoroutineWitnessTypes<I>
            where I::Tys: ::rustc_serialize::Encodable<__E>,
            I::RegionAssumptions: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    CoroutineWitnessTypes {
                        types: ref __binding_0, assumptions: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for CoroutineWitnessTypes<I>
            where I::Tys: ::rustc_serialize::Decodable<__D>,
            I::RegionAssumptions: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                CoroutineWitnessTypes {
                    types: ::rustc_serialize::Decodable::decode(__decoder),
                    assumptions: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            CoroutineWitnessTypes<I> where
            I::Tys: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::RegionAssumptions: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    CoroutineWitnessTypes {
                        types: ref __binding_0, assumptions: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
1161)]
1162#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            CoroutineWitnessTypes<I> where I: Interner,
            I::Tys: ::rustc_type_ir::TypeVisitable<I>,
            I::RegionAssumptions: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    CoroutineWitnessTypes {
                        types: ref __binding_0, assumptions: ref __binding_1 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            CoroutineWitnessTypes<I> where I: Interner,
            I::Tys: ::rustc_type_ir::TypeFoldable<I>,
            I::RegionAssumptions: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        CoroutineWitnessTypes {
                            types: __binding_0, assumptions: __binding_1 } => {
                            CoroutineWitnessTypes {
                                types: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                assumptions: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    CoroutineWitnessTypes {
                        types: __binding_0, assumptions: __binding_1 } => {
                        CoroutineWitnessTypes {
                            types: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            assumptions: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            CoroutineWitnessTypes<I> where I: Interner, J: Interner,
            I::Tys: ::rustc_type_ir::lift::Lift<J, Lifted = J::Tys>,
            I::RegionAssumptions: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::RegionAssumptions> {
            type Lifted = CoroutineWitnessTypes<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        CoroutineWitnessTypes {
                            types: __binding_0, assumptions: __binding_1 } => {
                            CoroutineWitnessTypes {
                                types: __binding_0.lift_to_interner(interner)?,
                                assumptions: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
1163pub struct CoroutineWitnessTypes<I: Interner> {
1164    pub types: I::Tys,
1165    pub assumptions: I::RegionAssumptions,
1166}
1167
1168impl<I: Interner> Eq for CoroutineWitnessTypes<I> {}