1use std::fmt;
2
3use derive_where::derive_where;
4#[cfg(feature = "nightly")]
5use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6#[cfg(feature = "nightly")]
7use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
8use rustc_type_ir_macros::{
9 GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
10};
11
12use crate::{self as ty, BoundVarIndexKind, Interner};
13
14#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for ConstKind<I> where I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> bool {
if ::core::mem::discriminant(self) ==
::core::mem::discriminant(__other) {
match (self, __other) {
(ConstKind::Param(ref __field_0),
ConstKind::Param(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Infer(ref __field_0),
ConstKind::Infer(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Bound(ref __field_0, ref __field_1),
ConstKind::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),
(ConstKind::Placeholder(ref __field_0),
ConstKind::Placeholder(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Unevaluated(ref __field_0),
ConstKind::Unevaluated(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Value(ref __field_0),
ConstKind::Value(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Error(ref __field_0),
ConstKind::Error(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ConstKind::Expr(ref __field_0),
ConstKind::Expr(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => unsafe { ::core::hint::unreachable_unchecked() },
}
} else { false }
}
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
16#[derive(GenericTypeVisitable)]
17#[cfg_attr(
18 feature = "nightly",
19 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for ConstKind<I> where
I::ParamConst: ::rustc_serialize::Encodable<__E>,
I::BoundConst: ::rustc_serialize::Encodable<__E>,
I::PlaceholderConst: ::rustc_serialize::Encodable<__E>,
ty::UnevaluatedConst<I>: ::rustc_serialize::Encodable<__E>,
I::ValueConst: ::rustc_serialize::Encodable<__E>,
I::ErrorGuaranteed: ::rustc_serialize::Encodable<__E>,
I::ExprConst: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ConstKind::Param(ref __binding_0) => { 0usize }
ConstKind::Infer(ref __binding_0) => { 1usize }
ConstKind::Bound(ref __binding_0, ref __binding_1) => {
2usize
}
ConstKind::Placeholder(ref __binding_0) => { 3usize }
ConstKind::Unevaluated(ref __binding_0) => { 4usize }
ConstKind::Value(ref __binding_0) => { 5usize }
ConstKind::Error(ref __binding_0) => { 6usize }
ConstKind::Expr(ref __binding_0) => { 7usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ConstKind::Param(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Infer(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Bound(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ConstKind::Placeholder(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Unevaluated(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Value(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Error(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ConstKind::Expr(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 ConstKind<I> where
I::ParamConst: ::rustc_serialize::Decodable<__D>,
I::BoundConst: ::rustc_serialize::Decodable<__D>,
I::PlaceholderConst: ::rustc_serialize::Decodable<__D>,
ty::UnevaluatedConst<I>: ::rustc_serialize::Decodable<__D>,
I::ValueConst: ::rustc_serialize::Decodable<__D>,
I::ErrorGuaranteed: ::rustc_serialize::Decodable<__D>,
I::ExprConst: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ConstKind::Param(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
ConstKind::Infer(::rustc_serialize::Decodable::decode(__decoder))
}
2usize => {
ConstKind::Bound(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
ConstKind::Placeholder(::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
ConstKind::Unevaluated(::rustc_serialize::Decodable::decode(__decoder))
}
5usize => {
ConstKind::Value(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
ConstKind::Error(::rustc_serialize::Decodable::decode(__decoder))
}
7usize => {
ConstKind::Expr(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ConstKind`, expected 0..8, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
ConstKind<I> where
I::ParamConst: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::BoundConst: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::PlaceholderConst: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
ty::UnevaluatedConst<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::ValueConst: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::ErrorGuaranteed: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::ExprConst: ::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 {
ConstKind::Param(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Infer(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Bound(ref __binding_0, ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
ConstKind::Placeholder(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Unevaluated(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Value(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Error(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ConstKind::Expr(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
20)]
21pub enum ConstKind<I: Interner> {
22 Param(I::ParamConst),
24
25 Infer(InferConst),
27
28 Bound(BoundVarIndexKind, I::BoundConst),
30
31 Placeholder(I::PlaceholderConst),
33
34 Unevaluated(ty::UnevaluatedConst<I>),
38
39 Value(I::ValueConst),
41
42 Error(I::ErrorGuaranteed),
45
46 Expr(I::ExprConst),
49}
50
51impl<I: Interner> Eq for ConstKind<I> {}
52
53impl<I: Interner> fmt::Debug for ConstKind<I> {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 use ConstKind::*;
56
57 match self {
58 Param(param) => f.write_fmt(format_args!("{0:?}", param))write!(f, "{param:?}"),
59 Infer(var) => f.write_fmt(format_args!("{0:?}", var))write!(f, "{var:?}"),
60 Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var),
61 Placeholder(placeholder) => f.write_fmt(format_args!("{0:?}", placeholder))write!(f, "{placeholder:?}"),
62 Unevaluated(uv) => f.write_fmt(format_args!("{0:?}", uv))write!(f, "{uv:?}"),
63 Value(val) => f.write_fmt(format_args!("{0:?}", val))write!(f, "{val:?}"),
64 Error(_) => f.write_fmt(format_args!("{{const error}}"))write!(f, "{{const error}}"),
65 Expr(expr) => f.write_fmt(format_args!("{0:?}", expr))write!(f, "{expr:?}"),
66 }
67 }
68}
69
70#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for UnevaluatedConst<I> where
I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> bool {
match (self, __other) {
(UnevaluatedConst { def: ref __field_def, args: ref __field_args
}, UnevaluatedConst {
def: ref __other_field_def, args: ref __other_field_args }) =>
true &&
::core::cmp::PartialEq::eq(__field_def, __other_field_def)
&&
::core::cmp::PartialEq::eq(__field_args,
__other_field_args),
}
}
}#[derive_where(Clone, Copy, Debug, Hash, PartialEq; I: Interner)]
72#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
UnevaluatedConst<I> where I: Interner,
I::UnevaluatedConstId: ::rustc_type_ir::TypeVisitable<I>,
I::GenericArgs: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
UnevaluatedConst {
def: ref __binding_0, args: 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
UnevaluatedConst<I> where I: Interner,
I::UnevaluatedConstId: ::rustc_type_ir::TypeFoldable<I>,
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 {
UnevaluatedConst { def: __binding_0, args: __binding_1 } =>
{
UnevaluatedConst {
def: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
args: ::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 {
UnevaluatedConst { def: __binding_0, args: __binding_1 } =>
{
UnevaluatedConst {
def: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable_Generic, const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
UnevaluatedConst<I> where I: Interner, J: Interner,
I::UnevaluatedConstId: ::rustc_type_ir::lift::Lift<J, Lifted =
J::UnevaluatedConstId>,
I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
J::GenericArgs> {
type Lifted = UnevaluatedConst<J>;
fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
Some(match self {
UnevaluatedConst { def: __binding_0, args: __binding_1 } =>
{
UnevaluatedConst {
def: __binding_0.lift_to_interner(interner)?,
args: __binding_1.lift_to_interner(interner)?,
}
}
})
}
}
};Lift_Generic)]
73#[cfg_attr(
74 feature = "nightly",
75 derive(const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for UnevaluatedConst<I> where
I::UnevaluatedConstId: ::rustc_serialize::Decodable<__D>,
I::GenericArgs: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
UnevaluatedConst {
def: ::rustc_serialize::Decodable::decode(__decoder),
args: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for UnevaluatedConst<I> where
I::UnevaluatedConstId: ::rustc_serialize::Encodable<__E>,
I::GenericArgs: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
match *self {
UnevaluatedConst {
def: ref __binding_0, args: 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
UnevaluatedConst<I> where
I::UnevaluatedConstId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::GenericArgs: ::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 {
UnevaluatedConst {
def: ref __binding_0, args: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
76)]
77pub struct UnevaluatedConst<I: Interner> {
78 pub def: I::UnevaluatedConstId,
79 pub args: I::GenericArgs,
80}
81
82impl<I: Interner> Eq for UnevaluatedConst<I> {}
83
84impl<I: Interner> UnevaluatedConst<I> {
85 #[inline]
86 pub fn new(def: I::UnevaluatedConstId, args: I::GenericArgs) -> UnevaluatedConst<I> {
87 UnevaluatedConst { def, args }
88 }
89}
90
91impl ::std::fmt::Debug for ConstVid {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("?{0}c", self.as_u32()))
}
}rustc_index::newtype_index! {
92 #[encodable]
94 #[orderable]
95 #[debug_format = "?{}c"]
96 #[gate_rustc_only]
97 pub struct ConstVid {}
98}
99
100#[derive(#[automatically_derived]
impl ::core::marker::Copy for InferConst { }Copy, #[automatically_derived]
impl ::core::clone::Clone for InferConst {
#[inline]
fn clone(&self) -> InferConst {
let _: ::core::clone::AssertParamIsClone<ConstVid>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for InferConst {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<ConstVid>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for InferConst {
#[inline]
fn eq(&self, other: &InferConst) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(InferConst::Var(__self_0), InferConst::Var(__arg1_0)) =>
__self_0 == __arg1_0,
(InferConst::Fresh(__self_0), InferConst::Fresh(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for InferConst {
#[inline]
fn partial_cmp(&self, other: &InferConst)
-> ::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) {
(InferConst::Var(__self_0), InferConst::Var(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
(InferConst::Fresh(__self_0), InferConst::Fresh(__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 InferConst {
#[inline]
fn cmp(&self, other: &InferConst) -> ::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) {
(InferConst::Var(__self_0), InferConst::Var(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(InferConst::Fresh(__self_0), InferConst::Fresh(__arg1_0))
=> ::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ => unsafe { ::core::intrinsics::unreachable() }
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for InferConst {
#[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 {
InferConst::Var(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
InferConst::Fresh(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash)]
102#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for InferConst {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
InferConst::Var(ref __binding_0) => { 0usize }
InferConst::Fresh(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
InferConst::Var(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
InferConst::Fresh(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for InferConst {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
InferConst::Var(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
InferConst::Fresh(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InferConst`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable_NoContext))]
103pub enum InferConst {
104 Var(ConstVid),
106 Fresh(u32),
108}
109
110impl fmt::Debug for InferConst {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 match self {
113 InferConst::Var(var) => f.write_fmt(format_args!("{0:?}", var))write!(f, "{var:?}"),
114 InferConst::Fresh(var) => f.write_fmt(format_args!("Fresh({0:?})", var))write!(f, "Fresh({var:?})"),
115 }
116 }
117}
118
119#[cfg(feature = "nightly")]
120impl<CTX> HashStable<CTX> for InferConst {
121 fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
122 match self {
123 InferConst::Var(_) => {
124 {
::core::panicking::panic_fmt(format_args!("const variables should not be hashed: {0:?}",
self));
}panic!("const variables should not be hashed: {self:?}")
125 }
126 InferConst::Fresh(i) => i.hash_stable(hcx, hasher),
127 }
128 }
129}
130
131#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for ValTreeKind<I> where I: Interner
{
#[inline]
fn eq(&self, __other: &Self) -> bool {
if ::core::mem::discriminant(self) ==
::core::mem::discriminant(__other) {
match (self, __other) {
(ValTreeKind::Leaf(ref __field_0),
ValTreeKind::Leaf(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(ValTreeKind::Branch(ref __field_0),
ValTreeKind::Branch(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => unsafe { ::core::hint::unreachable_unchecked() },
}
} else { false }
}
}#[derive_where(Clone, Debug, Hash, Eq, PartialEq; I: Interner)]
144#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for ValTreeKind<I>
where I: Interner,
I::ScalarInt: ::rustc_type_ir::TypeVisitable<I>,
Box<[I::Const]>: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ValTreeKind::Leaf(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);
}
}
}
}
ValTreeKind::Branch(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, const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for ValTreeKind<I>
where I: Interner, I::ScalarInt: ::rustc_type_ir::TypeFoldable<I>,
Box<[I::Const]>: ::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 {
ValTreeKind::Leaf(__binding_0) => {
ValTreeKind::Leaf(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
ValTreeKind::Branch(__binding_0) => {
ValTreeKind::Branch(::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 {
ValTreeKind::Leaf(__binding_0) => {
ValTreeKind::Leaf(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder))
}
ValTreeKind::Branch(__binding_0) => {
ValTreeKind::Branch(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder))
}
}
}
}
};TypeFoldable_Generic)]
145#[cfg_attr(
146 feature = "nightly",
147 derive(const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for ValTreeKind<I> where
I::ScalarInt: ::rustc_serialize::Decodable<__D>,
Box<[I::Const]>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ValTreeKind::Leaf(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
ValTreeKind::Branch(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ValTreeKind`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for ValTreeKind<I> where
I::ScalarInt: ::rustc_serialize::Encodable<__E>,
Box<[I::Const]>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ValTreeKind::Leaf(ref __binding_0) => { 0usize }
ValTreeKind::Branch(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ValTreeKind::Leaf(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ValTreeKind::Branch(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
ValTreeKind<I> where
I::ScalarInt: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
Box<[I::Const]>: ::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 {
ValTreeKind::Leaf(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
ValTreeKind::Branch(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
148)]
149pub enum ValTreeKind<I: Interner> {
150 Leaf(I::ScalarInt),
154
155 Branch(Box<[I::Const]>),
164}
165
166impl<I: Interner> ValTreeKind<I> {
167 #[inline]
170 pub fn to_leaf(&self) -> I::ScalarInt {
171 match self {
172 ValTreeKind::Leaf(s) => *s,
173 ValTreeKind::Branch(..) => {
::core::panicking::panic_fmt(format_args!("expected leaf, got {0:?}",
self));
}panic!("expected leaf, got {:?}", self),
174 }
175 }
176
177 #[inline]
180 pub fn to_branch(&self) -> &[I::Const] {
181 match self {
182 ValTreeKind::Branch(branch) => &**branch,
183 ValTreeKind::Leaf(..) => {
::core::panicking::panic_fmt(format_args!("expected branch, got {0:?}",
self));
}panic!("expected branch, got {:?}", self),
184 }
185 }
186
187 pub fn try_to_leaf(&self) -> Option<I::ScalarInt> {
189 match self {
190 ValTreeKind::Leaf(s) => Some(*s),
191 ValTreeKind::Branch(_) => None,
192 }
193 }
194
195 pub fn try_to_branch(&self) -> Option<&[I::Const]> {
197 match self {
198 ValTreeKind::Branch(branch) => Some(&**branch),
199 ValTreeKind::Leaf(_) => None,
200 }
201 }
202}