rustc_type_ir/
pattern.rs

1use derive_where::derive_where;
2#[cfg(feature = "nightly")]
3use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
4use rustc_type_ir_macros::{
5    GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
6};
7
8use crate::Interner;
9
10#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for PatternKind<I> where I: Interner
    {
    #[inline]
    fn eq(&self, __other: &Self) -> bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (PatternKind::Range {
                    start: ref __field_start, end: ref __field_end },
                    PatternKind::Range {
                    start: ref __other_field_start, end: ref __other_field_end
                    }) =>
                    true &&
                            ::core::cmp::PartialEq::eq(__field_start,
                                __other_field_start) &&
                        ::core::cmp::PartialEq::eq(__field_end, __other_field_end),
                (PatternKind::Or(ref __field_0),
                    PatternKind::Or(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)]
11#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for PatternKind<I>
            where I: Interner, I::Const: ::rustc_type_ir::TypeVisitable<I>,
            I::PatList: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    PatternKind::Range {
                        start: ref __binding_0, end: 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);
                                }
                            }
                        }
                    }
                    PatternKind::Or(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);
                                }
                            }
                        }
                    }
                    PatternKind::NotNull => {}
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for PatternKind<I>
            where I: Interner, I::Const: ::rustc_type_ir::TypeFoldable<I>,
            I::PatList: ::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 {
                        PatternKind::Range { start: __binding_0, end: __binding_1 }
                            => {
                            PatternKind::Range {
                                start: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                end: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                        PatternKind::Or(__binding_0) => {
                            PatternKind::Or(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        PatternKind::NotNull => { PatternKind::NotNull }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    PatternKind::Range { start: __binding_0, end: __binding_1 }
                        => {
                        PatternKind::Range {
                            start: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            end: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                    PatternKind::Or(__binding_0) => {
                        PatternKind::Or(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    PatternKind::NotNull => { PatternKind::NotNull }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for PatternKind<I>
            where I: Interner, J: Interner,
            I::Const: ::rustc_type_ir::lift::Lift<J, Lifted = J::Const>,
            I::Const: ::rustc_type_ir::lift::Lift<J, Lifted = J::Const>,
            I::PatList: ::rustc_type_ir::lift::Lift<J, Lifted = J::PatList> {
            type Lifted = PatternKind<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        PatternKind::Range { start: __binding_0, end: __binding_1 }
                            => {
                            PatternKind::Range {
                                start: __binding_0.lift_to_interner(interner)?,
                                end: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                        PatternKind::Or(__binding_0) => {
                            PatternKind::Or(__binding_0.lift_to_interner(interner)?)
                        }
                        PatternKind::NotNull => { PatternKind::NotNull }
                    })
            }
        }
    };Lift_Generic)]
12#[cfg_attr(
13    feature = "nightly",
14    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for PatternKind<I> where
            I::Const: ::rustc_serialize::Decodable<__D>,
            I::PatList: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        PatternKind::Range {
                            start: ::rustc_serialize::Decodable::decode(__decoder),
                            end: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    1usize => {
                        PatternKind::Or(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => { PatternKind::NotNull }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `PatternKind`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for PatternKind<I> where
            I::Const: ::rustc_serialize::Encodable<__E>,
            I::PatList: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        PatternKind::Range {
                            start: ref __binding_0, end: ref __binding_1 } => {
                            0usize
                        }
                        PatternKind::Or(ref __binding_0) => { 1usize }
                        PatternKind::NotNull => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    PatternKind::Range {
                        start: ref __binding_0, end: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    PatternKind::Or(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    PatternKind::NotNull => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            PatternKind<I> where
            I::Const: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::PatList: ::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 {
                    PatternKind::Range {
                        start: ref __binding_0, end: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    PatternKind::Or(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    PatternKind::NotNull => {}
                }
            }
        }
    };HashStable_NoContext)
15)]
16pub enum PatternKind<I: Interner> {
17    Range { start: I::Const, end: I::Const },
18    Or(I::PatList),
19    NotNull,
20}
21
22impl<I: Interner> Eq for PatternKind<I> {}