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, AliasConst, 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::Alias(ref __field_0, ref __field_1),
ConstKind::Alias(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::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::AliasConst<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::Alias(ref __binding_0, ref __binding_1) => {
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::Alias(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__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::AliasConst<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::Alias(::rustc_serialize::Decodable::decode(__decoder),
::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::AliasConst<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::Alias(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.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 Alias(ty::IsRigid, ty::AliasConst<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 Alias(is_rigid, alias_const) => {
63 f.write_fmt(format_args!("AliasConst({0:?}, {1:?})", is_rigid, alias_const))write!(f, "AliasConst({is_rigid:?}, {alias_const:?})")
64 }
65 Value(val) => f.write_fmt(format_args!("{0:?}", val))write!(f, "{val:?}"),
66 Error(_) => f.write_fmt(format_args!("{{const error}}"))write!(f, "{{const error}}"),
67 Expr(expr) => f.write_fmt(format_args!("{0:?}", expr))write!(f, "{expr:?}"),
68 }
69 }
70}
71
72impl<I: Interner> AliasConst<I> {
73 #[inline]
74 pub fn new(interner: I, kind: AliasConstKind<I>, args: I::GenericArgs) -> AliasConst<I> {
75 if truecfg!(debug_assertions) {
76 let def_id = match kind {
77 ty::AliasConstKind::Projection { def_id } => def_id.into(),
78 ty::AliasConstKind::Inherent { def_id } => def_id.into(),
79 ty::AliasConstKind::Free { def_id } => def_id.into(),
80 ty::AliasConstKind::Anon { def_id } => def_id.into(),
81 };
82 interner.debug_assert_args_compatible(def_id, args);
83 }
84 AliasConst { kind, args, _use_alias_new_instead: () }
85 }
86
87 pub fn type_of(self, interner: I) -> ty::Unnormalized<I, I::Ty> {
88 let def_id = match self.kind {
89 ty::AliasConstKind::Projection { def_id } => def_id.into(),
90 ty::AliasConstKind::Inherent { def_id } => def_id.into(),
91 ty::AliasConstKind::Free { def_id } => def_id.into(),
92 ty::AliasConstKind::Anon { def_id } => def_id.into(),
93 };
94 interner.type_of(def_id).instantiate(interner, self.args)
95 }
96}
97
98#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for AliasConstKind<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
AliasConstKind::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)
}
AliasConstKind::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)
}
AliasConstKind::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)
}
AliasConstKind::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)]
102#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
AliasConstKind<I> where I: Interner,
I::TraitAssocConstId: ::rustc_type_ir::TypeVisitable<I>,
I::InherentAssocConstId: ::rustc_type_ir::TypeVisitable<I>,
I::FreeConstAliasId: ::rustc_type_ir::TypeVisitable<I>,
I::AnonConstId: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
AliasConstKind::Projection { def_id: 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);
}
}
}
}
AliasConstKind::Inherent { def_id: 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);
}
}
}
}
AliasConstKind::Free { def_id: 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);
}
}
}
}
AliasConstKind::Anon { def_id: 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
AliasConstKind<I> where I: Interner,
I::TraitAssocConstId: ::rustc_type_ir::TypeFoldable<I>,
I::InherentAssocConstId: ::rustc_type_ir::TypeFoldable<I>,
I::FreeConstAliasId: ::rustc_type_ir::TypeFoldable<I>,
I::AnonConstId: ::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 {
AliasConstKind::Projection { def_id: __binding_0 } => {
AliasConstKind::Projection {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasConstKind::Inherent { def_id: __binding_0 } => {
AliasConstKind::Inherent {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasConstKind::Free { def_id: __binding_0 } => {
AliasConstKind::Free {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasConstKind::Anon { def_id: __binding_0 } => {
AliasConstKind::Anon {
def_id: ::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 {
AliasConstKind::Projection { def_id: __binding_0 } => {
AliasConstKind::Projection {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasConstKind::Inherent { def_id: __binding_0 } => {
AliasConstKind::Inherent {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasConstKind::Free { def_id: __binding_0 } => {
AliasConstKind::Free {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasConstKind::Anon { def_id: __binding_0 } => {
AliasConstKind::Anon {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
}
}
}
};TypeFoldable_Generic, const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
AliasConstKind<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = AliasConstKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
AliasConstKind::Projection { def_id: __binding_0 } => {
AliasConstKind::Projection {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasConstKind::Inherent { def_id: __binding_0 } => {
AliasConstKind::Inherent {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasConstKind::Free { def_id: __binding_0 } => {
AliasConstKind::Free {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasConstKind::Anon { def_id: __binding_0 } => {
AliasConstKind::Anon {
def_id: __binding_0.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic)]
103#[cfg_attr(
104 feature = "nightly",
105 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for AliasConstKind<I> where
I::TraitAssocConstId: ::rustc_serialize::Encodable<__E>,
I::InherentAssocConstId: ::rustc_serialize::Encodable<__E>,
I::FreeConstAliasId: ::rustc_serialize::Encodable<__E>,
I::AnonConstId: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AliasConstKind::Projection { def_id: ref __binding_0 } => {
0usize
}
AliasConstKind::Inherent { def_id: ref __binding_0 } => {
1usize
}
AliasConstKind::Free { def_id: ref __binding_0 } => {
2usize
}
AliasConstKind::Anon { def_id: ref __binding_0 } => {
3usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AliasConstKind::Projection { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasConstKind::Inherent { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasConstKind::Free { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasConstKind::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 AliasConstKind<I> where
I::TraitAssocConstId: ::rustc_serialize::Decodable<__D>,
I::InherentAssocConstId: ::rustc_serialize::Decodable<__D>,
I::FreeConstAliasId: ::rustc_serialize::Decodable<__D>,
I::AnonConstId: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
AliasConstKind::Projection {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
AliasConstKind::Inherent {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
2usize => {
AliasConstKind::Free {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
3usize => {
AliasConstKind::Anon {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AliasConstKind`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
AliasConstKind<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::AnonConstId: ::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 {
AliasConstKind::Projection { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasConstKind::Inherent { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasConstKind::Free { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasConstKind::Anon { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
106)]
107pub enum AliasConstKind<I: Interner> {
108 Projection { def_id: I::TraitAssocConstId },
110 Inherent { def_id: I::InherentAssocConstId },
112 Free { def_id: I::FreeConstAliasId },
114 Anon { def_id: I::AnonConstId },
116}
117
118impl<I: Interner> AliasConstKind<I> {
119 pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self {
120 interner.alias_const_kind_from_def_id(def_id)
121 }
122
123 pub fn is_type_const(self, interner: I) -> bool {
124 match self {
125 AliasConstKind::Projection { def_id } => interner.is_type_const(def_id.into()),
126 AliasConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()),
127 AliasConstKind::Free { def_id } => interner.is_type_const(def_id.into()),
128 AliasConstKind::Anon { def_id } => interner.is_type_const(def_id.into()),
129 }
130 }
131
132 pub fn def_span(self, interner: I) -> I::Span {
133 match self {
134 AliasConstKind::Projection { def_id } => interner.def_span(def_id.into()),
135 AliasConstKind::Inherent { def_id } => interner.def_span(def_id.into()),
136 AliasConstKind::Free { def_id } => interner.def_span(def_id.into()),
137 AliasConstKind::Anon { def_id } => interner.def_span(def_id.into()),
138 }
139 }
140
141 pub fn opt_def_id(self) -> Option<I::DefId> {
142 match self {
143 AliasConstKind::Projection { def_id } => Some(def_id.into()),
144 AliasConstKind::Inherent { def_id } => Some(def_id.into()),
145 AliasConstKind::Free { def_id } => Some(def_id.into()),
146 AliasConstKind::Anon { def_id } => Some(def_id.into()),
147 }
148 }
149}
150
151impl ::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! {
152 #[encodable]
154 #[orderable]
155 #[debug_format = "?{}c"]
156 #[gate_rustc_only]
157 pub struct ConstVid {}
158}
159
160#[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)]
162#[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))]
163pub enum InferConst {
164 Var(ConstVid),
166 Fresh(u32),
168}
169
170impl fmt::Debug for InferConst {
171 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
172 match self {
173 InferConst::Var(var) => f.write_fmt(format_args!("{0:?}", var))write!(f, "{var:?}"),
174 InferConst::Fresh(var) => f.write_fmt(format_args!("Fresh({0:?})", var))write!(f, "Fresh({var:?})"),
175 }
176 }
177}
178
179#[cfg(feature = "nightly")]
180impl StableHash for InferConst {
181 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
182 match self {
183 InferConst::Var(_) => {
184 {
::core::panicking::panic_fmt(format_args!("const variables should not be hashed: {0:?}",
self));
}panic!("const variables should not be hashed: {self:?}")
185 }
186 InferConst::Fresh(i) => i.stable_hash(hcx, hasher),
187 }
188 }
189}
190
191#[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)]
204#[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)]
205#[cfg_attr(
206 feature = "nightly",
207 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)
208)]
209pub enum ValTreeKind<I: Interner> {
210 Leaf(I::ScalarInt),
214
215 Branch(I::Consts),
223}
224
225impl<I: Interner> ValTreeKind<I> {
226 #[inline]
229 pub fn to_leaf(&self) -> I::ScalarInt {
230 match self {
231 ValTreeKind::Leaf(s) => *s,
232 ValTreeKind::Branch(..) => {
::core::panicking::panic_fmt(format_args!("expected leaf, got {0:?}",
self));
}panic!("expected leaf, got {:?}", self),
233 }
234 }
235
236 #[inline]
239 pub fn to_branch(&self) -> I::Consts {
240 match self {
241 ValTreeKind::Branch(branch) => *branch,
242 ValTreeKind::Leaf(..) => {
::core::panicking::panic_fmt(format_args!("expected branch, got {0:?}",
self));
}panic!("expected branch, got {:?}", self),
243 }
244 }
245
246 pub fn try_to_leaf(&self) -> Option<I::ScalarInt> {
248 match self {
249 ValTreeKind::Leaf(s) => Some(*s),
250 ValTreeKind::Branch(_) => None,
251 }
252 }
253
254 pub fn try_to_branch(&self) -> Option<I::Consts> {
256 match self {
257 ValTreeKind::Branch(branch) => Some(*branch),
258 ValTreeKind::Leaf(_) => None,
259 }
260 }
261}
262
263#[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)]
264#[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))]
265pub enum AnonConstKind {
266 GCE,
268 MCG,
270 RepeatExprCount,
273 NonTypeSystem,
275}