Skip to main content

rustc_type_ir/
generic_arg.rs

1use derive_where::derive_where;
2#[cfg(feature = "nightly")]
3use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash_NoContext};
4use rustc_type_ir_macros::GenericTypeVisitable;
5
6use crate::{Interner, Region};
7
8#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for GenericArgKind<I> where I: Interner
    {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for GenericArgKind<I> where I: Interner
    {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for GenericArgKind<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) {
                (GenericArgKind::Lifetime(ref __field_0),
                    GenericArgKind::Lifetime(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (GenericArgKind::Type(ref __field_0),
                    GenericArgKind::Type(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (GenericArgKind::Const(ref __field_0),
                    GenericArgKind::Const(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                _ => unsafe { ::core::hint::unreachable_unchecked() },
            }
        } else { false }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for GenericArgKind<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            GenericArgKind::Lifetime(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Lifetime");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            GenericArgKind::Type(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Type");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            GenericArgKind::Const(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Const");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
9#[derive(const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for GenericArgKind<I>
            where Region<I>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            I::Ty: ::rustc_type_ir::GenericTypeVisitable<__V>,
            I::Const: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    GenericArgKind::Lifetime(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    GenericArgKind::Type(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    GenericArgKind::Const(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable)]
10#[cfg_attr(
11    feature = "nightly",
12    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for GenericArgKind<I> where
            Region<I>: ::rustc_serialize::Decodable<__D>,
            I::Ty: ::rustc_serialize::Decodable<__D>,
            I::Const: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        GenericArgKind::Lifetime(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        GenericArgKind::Type(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        GenericArgKind::Const(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `GenericArgKind`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for GenericArgKind<I> where
            Region<I>: ::rustc_serialize::Encodable<__E>,
            I::Ty: ::rustc_serialize::Encodable<__E>,
            I::Const: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        GenericArgKind::Lifetime(ref __binding_0) => { 0usize }
                        GenericArgKind::Type(ref __binding_0) => { 1usize }
                        GenericArgKind::Const(ref __binding_0) => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    GenericArgKind::Lifetime(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    GenericArgKind::Type(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    GenericArgKind::Const(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            GenericArgKind<I> where
            Region<I>: ::rustc_data_structures::stable_hash::StableHash,
            I::Ty: ::rustc_data_structures::stable_hash::StableHash,
            I::Const: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    GenericArgKind::Lifetime(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    GenericArgKind::Type(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    GenericArgKind::Const(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
13)]
14pub enum GenericArgKind<I: Interner> {
15    Lifetime(Region<I>),
16    Type(I::Ty),
17    Const(I::Const),
18}
19
20impl<I: Interner> Eq for GenericArgKind<I> {}