1use std::fmt;
2
3use derive_where::derive_where;
4#[cfg(feature = "nightly")]
5use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
6#[cfg(feature = "nightly")]
7use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash, StableHash_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) -> ::core::primitive::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>,
ty::BoundConst<I>: ::rustc_serialize::Encodable<__E>,
ty::PlaceholderConst<I>: ::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>,
ty::BoundConst<I>: ::rustc_serialize::Decodable<__D>,
ty::PlaceholderConst<I>: ::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> ::rustc_data_structures::stable_hash::StableHash for
ConstKind<I> where
I::ParamConst: ::rustc_data_structures::stable_hash::StableHash,
ty::BoundConst<I>: ::rustc_data_structures::stable_hash::StableHash,
ty::PlaceholderConst<I>: ::rustc_data_structures::stable_hash::StableHash,
ty::UnevaluatedConst<I>: ::rustc_data_structures::stable_hash::StableHash,
I::ValueConst: ::rustc_data_structures::stable_hash::StableHash,
I::ErrorGuaranteed: ::rustc_data_structures::stable_hash::StableHash,
I::ExprConst: ::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 {
ConstKind::Param(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Infer(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Bound(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ConstKind::Placeholder(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Unevaluated(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Value(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Error(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ConstKind::Expr(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
20)]
21pub enum ConstKind<I: Interner> {
22 Param(I::ParamConst),
24
25 Infer(InferConst),
27
28 Bound(BoundVarIndexKind, ty::BoundConst<I>),
30
31 Placeholder(ty::PlaceholderConst<I>),
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) -> ::core::primitive::bool {
match (self, __other) {
(UnevaluatedConst {
kind: ref __field_kind,
args: ref __field_args,
_use_unevaluated_const_new_instead: ref __field__use_unevaluated_const_new_instead
}, UnevaluatedConst {
kind: ref __other_field_kind,
args: ref __other_field_args,
_use_unevaluated_const_new_instead: ref __other_field__use_unevaluated_const_new_instead
}) =>
true &&
::core::cmp::PartialEq::eq(__field_kind, __other_field_kind)
&&
::core::cmp::PartialEq::eq(__field_args, __other_field_args)
&&
::core::cmp::PartialEq::eq(__field__use_unevaluated_const_new_instead,
__other_field__use_unevaluated_const_new_instead),
}
}
}#[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::GenericArgs: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
UnevaluatedConst {
args: ref __binding_1,
_use_unevaluated_const_new_instead: ref __binding_2, .. } =>
{
{
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);
}
}
}
{
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
UnevaluatedConst<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 {
UnevaluatedConst {
kind: __binding_0,
args: __binding_1,
_use_unevaluated_const_new_instead: __binding_2 } => {
UnevaluatedConst {
kind: __binding_0,
args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
_use_unevaluated_const_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 {
UnevaluatedConst {
kind: __binding_0,
args: __binding_1,
_use_unevaluated_const_new_instead: __binding_2 } => {
UnevaluatedConst {
kind: __binding_0,
args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
__folder),
_use_unevaluated_const_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
UnevaluatedConst<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = UnevaluatedConst<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
UnevaluatedConst {
kind: __binding_0,
args: __binding_1,
_use_unevaluated_const_new_instead: __binding_2 } => {
UnevaluatedConst {
kind: __binding_0.lift_to_interner(interner),
args: __binding_1.lift_to_interner(interner),
_use_unevaluated_const_new_instead: __binding_2.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
UnevaluatedConstKind<I>: ::rustc_serialize::Decodable<__D>,
I::GenericArgs: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
UnevaluatedConst {
kind: ::rustc_serialize::Decodable::decode(__decoder),
args: ::rustc_serialize::Decodable::decode(__decoder),
_use_unevaluated_const_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for UnevaluatedConst<I> where
UnevaluatedConstKind<I>: ::rustc_serialize::Encodable<__E>,
I::GenericArgs: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
match *self {
UnevaluatedConst {
kind: ref __binding_0,
args: ref __binding_1,
_use_unevaluated_const_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> ::rustc_data_structures::stable_hash::StableHash for
UnevaluatedConst<I> where
UnevaluatedConstKind<I>: ::rustc_data_structures::stable_hash::StableHash,
I::GenericArgs: ::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) {
match *self {
UnevaluatedConst {
kind: ref __binding_0,
args: ref __binding_1,
_use_unevaluated_const_new_instead: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
76)]
77pub struct UnevaluatedConst<I: Interner> {
78 #[type_foldable(identity)]
79 #[type_visitable(ignore)]
80 pub kind: UnevaluatedConstKind<I>,
81 pub args: I::GenericArgs,
82
83 #[derive_where(skip(Debug))]
85 pub(crate) _use_unevaluated_const_new_instead: (),
86}
87
88impl<I: Interner> Eq for UnevaluatedConst<I> {}
89
90impl<I: Interner> UnevaluatedConst<I> {
91 #[inline]
92 pub fn new(
93 interner: I,
94 kind: UnevaluatedConstKind<I>,
95 args: I::GenericArgs,
96 ) -> UnevaluatedConst<I> {
97 if truecfg!(debug_assertions) {
98 let def_id = match kind {
99 ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(),
100 ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(),
101 ty::UnevaluatedConstKind::Free { def_id } => def_id.into(),
102 ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(),
103 };
104 interner.debug_assert_args_compatible(def_id, args);
105 }
106 UnevaluatedConst { kind, args, _use_unevaluated_const_new_instead: () }
107 }
108
109 pub fn type_of(self, interner: I) -> ty::Unnormalized<I, I::Ty> {
110 let def_id = match self.kind {
111 ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(),
112 ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(),
113 ty::UnevaluatedConstKind::Free { def_id } => def_id.into(),
114 ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(),
115 };
116 interner.type_of(def_id).instantiate(interner, self.args)
117 }
118}
119
120#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for UnevaluatedConstKind<I> where
I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
UnevaluatedConstKind::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)
}
UnevaluatedConstKind::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)
}
UnevaluatedConstKind::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)
}
UnevaluatedConstKind::Anon { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "Anon");
::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)]
124#[derive(GenericTypeVisitable, const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
UnevaluatedConstKind<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = UnevaluatedConstKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
UnevaluatedConstKind::Projection { def_id: __binding_0 } =>
{
UnevaluatedConstKind::Projection {
def_id: __binding_0.lift_to_interner(interner),
}
}
UnevaluatedConstKind::Inherent { def_id: __binding_0 } => {
UnevaluatedConstKind::Inherent {
def_id: __binding_0.lift_to_interner(interner),
}
}
UnevaluatedConstKind::Free { def_id: __binding_0 } => {
UnevaluatedConstKind::Free {
def_id: __binding_0.lift_to_interner(interner),
}
}
UnevaluatedConstKind::Anon { def_id: __binding_0 } => {
UnevaluatedConstKind::Anon {
def_id: __binding_0.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic)]
125#[cfg_attr(
126 feature = "nightly",
127 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for UnevaluatedConstKind<I>
where I::TraitAssocConstId: ::rustc_serialize::Encodable<__E>,
I::InherentAssocConstId: ::rustc_serialize::Encodable<__E>,
I::FreeConstAliasId: ::rustc_serialize::Encodable<__E>,
I::UnevaluatedConstId: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
UnevaluatedConstKind::Projection { def_id: ref __binding_0 }
=> {
0usize
}
UnevaluatedConstKind::Inherent { def_id: ref __binding_0 }
=> {
1usize
}
UnevaluatedConstKind::Free { def_id: ref __binding_0 } => {
2usize
}
UnevaluatedConstKind::Anon { def_id: ref __binding_0 } => {
3usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
UnevaluatedConstKind::Projection { def_id: ref __binding_0 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
UnevaluatedConstKind::Inherent { def_id: ref __binding_0 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
UnevaluatedConstKind::Free { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
UnevaluatedConstKind::Anon { 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 UnevaluatedConstKind<I>
where I::TraitAssocConstId: ::rustc_serialize::Decodable<__D>,
I::InherentAssocConstId: ::rustc_serialize::Decodable<__D>,
I::FreeConstAliasId: ::rustc_serialize::Decodable<__D>,
I::UnevaluatedConstId: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
UnevaluatedConstKind::Projection {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
UnevaluatedConstKind::Inherent {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
2usize => {
UnevaluatedConstKind::Free {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
3usize => {
UnevaluatedConstKind::Anon {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `UnevaluatedConstKind`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
UnevaluatedConstKind<I> where
I::TraitAssocConstId: ::rustc_data_structures::stable_hash::StableHash,
I::InherentAssocConstId: ::rustc_data_structures::stable_hash::StableHash,
I::FreeConstAliasId: ::rustc_data_structures::stable_hash::StableHash,
I::UnevaluatedConstId: ::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 {
UnevaluatedConstKind::Projection { def_id: ref __binding_0 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
UnevaluatedConstKind::Inherent { def_id: ref __binding_0 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
UnevaluatedConstKind::Free { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
UnevaluatedConstKind::Anon { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
128)]
129pub enum UnevaluatedConstKind<I: Interner> {
130 Projection { def_id: I::TraitAssocConstId },
132 Inherent { def_id: I::InherentAssocConstId },
134 Free { def_id: I::FreeConstAliasId },
136 Anon { def_id: I::UnevaluatedConstId },
138}
139
140impl<I: Interner> UnevaluatedConstKind<I> {
141 pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self {
142 interner.unevaluated_const_kind_from_def_id(def_id)
143 }
144
145 pub fn is_type_const(self, interner: I) -> bool {
146 match self {
147 UnevaluatedConstKind::Projection { def_id } => interner.is_type_const(def_id.into()),
148 UnevaluatedConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()),
149 UnevaluatedConstKind::Free { def_id } => interner.is_type_const(def_id.into()),
150 UnevaluatedConstKind::Anon { def_id } => interner.is_type_const(def_id.into()),
151 }
152 }
153
154 pub fn def_span(self, interner: I) -> I::Span {
155 match self {
156 UnevaluatedConstKind::Projection { def_id } => interner.def_span(def_id.into()),
157 UnevaluatedConstKind::Inherent { def_id } => interner.def_span(def_id.into()),
158 UnevaluatedConstKind::Free { def_id } => interner.def_span(def_id.into()),
159 UnevaluatedConstKind::Anon { def_id } => interner.def_span(def_id.into()),
160 }
161 }
162
163 pub fn opt_def_id(self) -> Option<I::DefId> {
164 match self {
165 UnevaluatedConstKind::Projection { def_id } => Some(def_id.into()),
166 UnevaluatedConstKind::Inherent { def_id } => Some(def_id.into()),
167 UnevaluatedConstKind::Free { def_id } => Some(def_id.into()),
168 UnevaluatedConstKind::Anon { def_id } => Some(def_id.into()),
169 }
170 }
171}
172
173impl ::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! {
174 #[encodable]
176 #[orderable]
177 #[debug_format = "?{}c"]
178 #[gate_rustc_only]
179 pub struct ConstVid {}
180}
181
182#[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_fields_are_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> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}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)]
184#[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))]
185pub enum InferConst {
186 Var(ConstVid),
188 Fresh(u32),
190}
191
192impl fmt::Debug for InferConst {
193 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
194 match self {
195 InferConst::Var(var) => f.write_fmt(format_args!("{0:?}", var))write!(f, "{var:?}"),
196 InferConst::Fresh(var) => f.write_fmt(format_args!("Fresh({0:?})", var))write!(f, "Fresh({var:?})"),
197 }
198 }
199}
200
201#[cfg(feature = "nightly")]
202impl StableHash for InferConst {
203 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
204 match self {
205 InferConst::Var(_) => {
206 {
::core::panicking::panic_fmt(format_args!("const variables should not be hashed: {0:?}",
self));
}panic!("const variables should not be hashed: {self:?}")
207 }
208 InferConst::Fresh(i) => i.stable_hash(hcx, hasher),
209 }
210 }
211}
212
213#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for ValTreeKind<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) {
(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, Copy, Debug, Hash, Eq, PartialEq; I: Interner)]
226#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for ValTreeKind<I>
where I: Interner,
I::ScalarInt: ::rustc_type_ir::TypeVisitable<I>,
I::Consts: ::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>,
I::Consts: ::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, GenericTypeVisitable)]
227#[cfg_attr(
228 feature = "nightly",
229 derive(const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for ValTreeKind<I> where
I::ScalarInt: ::rustc_serialize::Decodable<__D>,
I::Consts: ::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>,
I::Consts: ::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> ::rustc_data_structures::stable_hash::StableHash for
ValTreeKind<I> where
I::ScalarInt: ::rustc_data_structures::stable_hash::StableHash,
I::Consts: ::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 {
ValTreeKind::Leaf(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ValTreeKind::Branch(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
230)]
231pub enum ValTreeKind<I: Interner> {
232 Leaf(I::ScalarInt),
236
237 Branch(I::Consts),
245}
246
247impl<I: Interner> ValTreeKind<I> {
248 #[inline]
251 pub fn to_leaf(&self) -> I::ScalarInt {
252 match self {
253 ValTreeKind::Leaf(s) => *s,
254 ValTreeKind::Branch(..) => {
::core::panicking::panic_fmt(format_args!("expected leaf, got {0:?}",
self));
}panic!("expected leaf, got {:?}", self),
255 }
256 }
257
258 #[inline]
261 pub fn to_branch(&self) -> I::Consts {
262 match self {
263 ValTreeKind::Branch(branch) => *branch,
264 ValTreeKind::Leaf(..) => {
::core::panicking::panic_fmt(format_args!("expected branch, got {0:?}",
self));
}panic!("expected branch, got {:?}", self),
265 }
266 }
267
268 pub fn try_to_leaf(&self) -> Option<I::ScalarInt> {
270 match self {
271 ValTreeKind::Leaf(s) => Some(*s),
272 ValTreeKind::Branch(_) => None,
273 }
274 }
275
276 pub fn try_to_branch(&self) -> Option<I::Consts> {
278 match self {
279 ValTreeKind::Branch(branch) => Some(*branch),
280 ValTreeKind::Leaf(_) => None,
281 }
282 }
283}
284
285#[derive(#[automatically_derived]
impl ::core::marker::Copy for AnonConstKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AnonConstKind {
#[inline]
fn clone(&self) -> AnonConstKind { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for AnonConstKind {
#[inline]
fn eq(&self, other: &AnonConstKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AnonConstKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AnonConstKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for AnonConstKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AnonConstKind::GCE => "GCE",
AnonConstKind::MCG => "MCG",
AnonConstKind::RepeatExprCount => "RepeatExprCount",
AnonConstKind::NonTypeSystem => "NonTypeSystem",
})
}
}Debug)]
286#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for AnonConstKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AnonConstKind::GCE => { 0usize }
AnonConstKind::MCG => { 1usize }
AnonConstKind::RepeatExprCount => { 2usize }
AnonConstKind::NonTypeSystem => { 3usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AnonConstKind::GCE => {}
AnonConstKind::MCG => {}
AnonConstKind::RepeatExprCount => {}
AnonConstKind::NonTypeSystem => {}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for AnonConstKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { AnonConstKind::GCE }
1usize => { AnonConstKind::MCG }
2usize => { AnonConstKind::RepeatExprCount }
3usize => { AnonConstKind::NonTypeSystem }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AnonConstKind`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
AnonConstKind {
#[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 {
AnonConstKind::GCE => {}
AnonConstKind::MCG => {}
AnonConstKind::RepeatExprCount => {}
AnonConstKind::NonTypeSystem => {}
}
}
}
};StableHash))]
287pub enum AnonConstKind {
288 GCE,
290 MCG,
292 RepeatExprCount,
295 NonTypeSystem,
297}