1use std::debug_assert_matches;
2
3use derive_where::derive_where;
4#[cfg(feature = "nightly")]
5use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash_NoContext};
6use rustc_type_ir_macros::{
7 GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
8};
9
10use crate::inherent::*;
11use crate::{self as ty, AliasTerm, Interner};
12
13#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for TermKind<I> where I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for TermKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for TermKind<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) {
(TermKind::Ty(ref __field_0),
TermKind::Ty(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(TermKind::Const(ref __field_0),
TermKind::Const(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => unsafe { ::core::hint::unreachable_unchecked() },
}
} else { false }
}
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for TermKind<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
TermKind::Ty(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Ty");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TermKind::Const(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Const");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
14#[derive(const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for TermKind<I> where
I::Ty: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::Const: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
TermKind::Ty(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
TermKind::Const(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
}
}
}
};GenericTypeVisitable)]
15#[cfg_attr(
16 feature = "nightly",
17 derive(const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for TermKind<I> where
I::Ty: ::rustc_serialize::Decodable<__D>,
I::Const: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
TermKind::Ty(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
TermKind::Const(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `TermKind`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for TermKind<I> where
I::Ty: ::rustc_serialize::Encodable<__E>,
I::Const: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
TermKind::Ty(ref __binding_0) => { 0usize }
TermKind::Const(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
TermKind::Ty(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
TermKind::Const(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
TermKind<I> where
I::Ty: ::rustc_data_structures::stable_hash::StableHash,
I::Const: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
TermKind::Ty(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
TermKind::Const(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
18)]
19pub enum TermKind<I: Interner> {
20 Ty(I::Ty),
21 Const(I::Const),
22}
23
24impl<I: Interner> Eq for TermKind<I> {}
25
26#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for AliasTermKind<I> where I: Interner
{
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for AliasTermKind<I> where I: Interner
{
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for AliasTermKind<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) {
(AliasTermKind::ProjectionTy { def_id: ref __field_def_id },
AliasTermKind::ProjectionTy {
def_id: ref __other_field_def_id }) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::InherentTy { def_id: ref __field_def_id },
AliasTermKind::InherentTy { def_id: ref __other_field_def_id
}) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::OpaqueTy { def_id: ref __field_def_id },
AliasTermKind::OpaqueTy { def_id: ref __other_field_def_id
}) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::FreeTy { def_id: ref __field_def_id },
AliasTermKind::FreeTy { def_id: ref __other_field_def_id })
=>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::AnonConst { def_id: ref __field_def_id },
AliasTermKind::AnonConst { def_id: ref __other_field_def_id
}) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::ProjectionConst { def_id: ref __field_def_id
}, AliasTermKind::ProjectionConst {
def_id: ref __other_field_def_id }) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::FreeConst { def_id: ref __field_def_id },
AliasTermKind::FreeConst { def_id: ref __other_field_def_id
}) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::InherentConstSelf { def_id: ref __field_def_id
}, AliasTermKind::InherentConstSelf {
def_id: ref __other_field_def_id }) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
(AliasTermKind::InherentConstImpl { def_id: ref __field_def_id
}, AliasTermKind::InherentConstImpl {
def_id: ref __other_field_def_id }) =>
true &&
::core::cmp::PartialEq::eq(__field_def_id,
__other_field_def_id),
_ => unsafe { ::core::hint::unreachable_unchecked() },
}
} else { false }
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for AliasTermKind<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<I::TraitAssocTyId>;
let _: __AssertEq<I::InherentAssocTyId>;
let _: __AssertEq<I::OpaqueTyId>;
let _: __AssertEq<I::FreeTyAliasId>;
let _: __AssertEq<I::AnonConstId>;
let _: __AssertEq<I::TraitAssocConstId>;
let _: __AssertEq<I::FreeConstAliasId>;
let _: __AssertEq<I::InherentAssocConstId>;
let _: __AssertEq<I::InherentAssocConstId>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for AliasTermKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for AliasTermKind<I> where I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
AliasTermKind::ProjectionTy { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::InherentTy { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::OpaqueTy { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::FreeTy { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::AnonConst { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::ProjectionConst { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::FreeConst { def_id: ref __field_def_id } => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::InherentConstSelf { def_id: ref __field_def_id } =>
{
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
AliasTermKind::InherentConstImpl { def_id: ref __field_def_id } =>
{
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_def_id, __state);
}
}
}
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for AliasTermKind<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
AliasTermKind::ProjectionTy { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "ProjectionTy");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::InherentTy { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "InherentTy");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::OpaqueTy { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "OpaqueTy");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::FreeTy { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "FreeTy");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::AnonConst { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "AnonConst");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::ProjectionConst { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f,
"ProjectionConst");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::FreeConst { def_id: ref __field_def_id } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "FreeConst");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::InherentConstSelf { def_id: ref __field_def_id } =>
{
let mut __builder =
::core::fmt::Formatter::debug_struct(__f,
"InherentConstSelf");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
AliasTermKind::InherentConstImpl { def_id: ref __field_def_id } =>
{
let mut __builder =
::core::fmt::Formatter::debug_struct(__f,
"InherentConstImpl");
::core::fmt::DebugStruct::field(&mut __builder, "def_id",
__field_def_id);
::core::fmt::DebugStruct::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
27#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
AliasTermKind<I> where I: Interner,
I::TraitAssocTyId: ::rustc_type_ir::TypeVisitable<I>,
I::InherentAssocTyId: ::rustc_type_ir::TypeVisitable<I>,
I::OpaqueTyId: ::rustc_type_ir::TypeVisitable<I>,
I::FreeTyAliasId: ::rustc_type_ir::TypeVisitable<I>,
I::AnonConstId: ::rustc_type_ir::TypeVisitable<I>,
I::TraitAssocConstId: ::rustc_type_ir::TypeVisitable<I>,
I::FreeConstAliasId: ::rustc_type_ir::TypeVisitable<I>,
I::InherentAssocConstId: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
AliasTermKind::ProjectionTy { 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);
}
}
}
}
AliasTermKind::InherentTy { 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);
}
}
}
}
AliasTermKind::OpaqueTy { 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);
}
}
}
}
AliasTermKind::FreeTy { 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);
}
}
}
}
AliasTermKind::AnonConst { 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);
}
}
}
}
AliasTermKind::ProjectionConst { 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);
}
}
}
}
AliasTermKind::FreeConst { 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);
}
}
}
}
AliasTermKind::InherentConstSelf { 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);
}
}
}
}
AliasTermKind::InherentConstImpl { 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, const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
AliasTermKind<I> where I: Interner,
I::TraitAssocTyId: ::rustc_type_ir::TypeFoldable<I>,
I::InherentAssocTyId: ::rustc_type_ir::TypeFoldable<I>,
I::OpaqueTyId: ::rustc_type_ir::TypeFoldable<I>,
I::FreeTyAliasId: ::rustc_type_ir::TypeFoldable<I>,
I::AnonConstId: ::rustc_type_ir::TypeFoldable<I>,
I::TraitAssocConstId: ::rustc_type_ir::TypeFoldable<I>,
I::FreeConstAliasId: ::rustc_type_ir::TypeFoldable<I>,
I::InherentAssocConstId: ::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 {
AliasTermKind::ProjectionTy { def_id: __binding_0 } => {
AliasTermKind::ProjectionTy {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::InherentTy { def_id: __binding_0 } => {
AliasTermKind::InherentTy {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::OpaqueTy { def_id: __binding_0 } => {
AliasTermKind::OpaqueTy {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::FreeTy { def_id: __binding_0 } => {
AliasTermKind::FreeTy {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::AnonConst { def_id: __binding_0 } => {
AliasTermKind::AnonConst {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::ProjectionConst { def_id: __binding_0 } => {
AliasTermKind::ProjectionConst {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::FreeConst { def_id: __binding_0 } => {
AliasTermKind::FreeConst {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::InherentConstSelf { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstSelf {
def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
}
}
AliasTermKind::InherentConstImpl { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstImpl {
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 {
AliasTermKind::ProjectionTy { def_id: __binding_0 } => {
AliasTermKind::ProjectionTy {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::InherentTy { def_id: __binding_0 } => {
AliasTermKind::InherentTy {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::OpaqueTy { def_id: __binding_0 } => {
AliasTermKind::OpaqueTy {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::FreeTy { def_id: __binding_0 } => {
AliasTermKind::FreeTy {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::AnonConst { def_id: __binding_0 } => {
AliasTermKind::AnonConst {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::ProjectionConst { def_id: __binding_0 } => {
AliasTermKind::ProjectionConst {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::FreeConst { def_id: __binding_0 } => {
AliasTermKind::FreeConst {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::InherentConstSelf { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstSelf {
def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
AliasTermKind::InherentConstImpl { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstImpl {
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
AliasTermKind<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = AliasTermKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
AliasTermKind::ProjectionTy { def_id: __binding_0 } => {
AliasTermKind::ProjectionTy {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::InherentTy { def_id: __binding_0 } => {
AliasTermKind::InherentTy {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::OpaqueTy { def_id: __binding_0 } => {
AliasTermKind::OpaqueTy {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::FreeTy { def_id: __binding_0 } => {
AliasTermKind::FreeTy {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::AnonConst { def_id: __binding_0 } => {
AliasTermKind::AnonConst {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::ProjectionConst { def_id: __binding_0 } => {
AliasTermKind::ProjectionConst {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::FreeConst { def_id: __binding_0 } => {
AliasTermKind::FreeConst {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::InherentConstSelf { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstSelf {
def_id: __binding_0.lift_to_interner(interner),
}
}
AliasTermKind::InherentConstImpl { def_id: __binding_0 } =>
{
AliasTermKind::InherentConstImpl {
def_id: __binding_0.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic, const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for AliasTermKind<I>
where
I::TraitAssocTyId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::InherentAssocTyId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::OpaqueTyId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::FreeTyAliasId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::AnonConstId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::TraitAssocConstId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::FreeConstAliasId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::InherentAssocConstId: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::InherentAssocConstId: ::rustc_type_ir::GenericTypeVisitable<__V>
{
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
AliasTermKind::ProjectionTy { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::InherentTy { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::OpaqueTy { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::FreeTy { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::AnonConst { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::ProjectionConst { def_id: ref __binding_0 }
=> {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::FreeConst { def_id: ref __binding_0 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::InherentConstSelf { def_id: ref __binding_0 }
=> {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
AliasTermKind::InherentConstImpl { def_id: ref __binding_0 }
=> {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
}
}
}
};GenericTypeVisitable)]
28#[cfg_attr(
29 feature = "nightly",
30 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for AliasTermKind<I> where
I::TraitAssocTyId: ::rustc_serialize::Encodable<__E>,
I::InherentAssocTyId: ::rustc_serialize::Encodable<__E>,
I::OpaqueTyId: ::rustc_serialize::Encodable<__E>,
I::FreeTyAliasId: ::rustc_serialize::Encodable<__E>,
I::AnonConstId: ::rustc_serialize::Encodable<__E>,
I::TraitAssocConstId: ::rustc_serialize::Encodable<__E>,
I::FreeConstAliasId: ::rustc_serialize::Encodable<__E>,
I::InherentAssocConstId: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AliasTermKind::ProjectionTy { def_id: ref __binding_0 } => {
0usize
}
AliasTermKind::InherentTy { def_id: ref __binding_0 } => {
1usize
}
AliasTermKind::OpaqueTy { def_id: ref __binding_0 } => {
2usize
}
AliasTermKind::FreeTy { def_id: ref __binding_0 } => {
3usize
}
AliasTermKind::AnonConst { def_id: ref __binding_0 } => {
4usize
}
AliasTermKind::ProjectionConst { def_id: ref __binding_0 }
=> {
5usize
}
AliasTermKind::FreeConst { def_id: ref __binding_0 } => {
6usize
}
AliasTermKind::InherentConstSelf { def_id: ref __binding_0 }
=> {
7usize
}
AliasTermKind::InherentConstImpl { def_id: ref __binding_0 }
=> {
8usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AliasTermKind::ProjectionTy { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::InherentTy { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::OpaqueTy { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::FreeTy { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::AnonConst { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::ProjectionConst { def_id: ref __binding_0 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::FreeConst { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::InherentConstSelf { def_id: ref __binding_0 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AliasTermKind::InherentConstImpl { 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 AliasTermKind<I> where
I::TraitAssocTyId: ::rustc_serialize::Decodable<__D>,
I::InherentAssocTyId: ::rustc_serialize::Decodable<__D>,
I::OpaqueTyId: ::rustc_serialize::Decodable<__D>,
I::FreeTyAliasId: ::rustc_serialize::Decodable<__D>,
I::AnonConstId: ::rustc_serialize::Decodable<__D>,
I::TraitAssocConstId: ::rustc_serialize::Decodable<__D>,
I::FreeConstAliasId: ::rustc_serialize::Decodable<__D>,
I::InherentAssocConstId: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
AliasTermKind::ProjectionTy {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
AliasTermKind::InherentTy {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
2usize => {
AliasTermKind::OpaqueTy {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
3usize => {
AliasTermKind::FreeTy {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
4usize => {
AliasTermKind::AnonConst {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
5usize => {
AliasTermKind::ProjectionConst {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
6usize => {
AliasTermKind::FreeConst {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
7usize => {
AliasTermKind::InherentConstSelf {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
8usize => {
AliasTermKind::InherentConstImpl {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AliasTermKind`, expected 0..9, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
AliasTermKind<I> where
I::TraitAssocTyId: ::rustc_data_structures::stable_hash::StableHash,
I::InherentAssocTyId: ::rustc_data_structures::stable_hash::StableHash,
I::OpaqueTyId: ::rustc_data_structures::stable_hash::StableHash,
I::FreeTyAliasId: ::rustc_data_structures::stable_hash::StableHash,
I::AnonConstId: ::rustc_data_structures::stable_hash::StableHash,
I::TraitAssocConstId: ::rustc_data_structures::stable_hash::StableHash,
I::FreeConstAliasId: ::rustc_data_structures::stable_hash::StableHash,
I::InherentAssocConstId: ::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 {
AliasTermKind::ProjectionTy { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::InherentTy { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::OpaqueTy { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::FreeTy { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::AnonConst { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::ProjectionConst { def_id: ref __binding_0 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::FreeConst { def_id: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::InherentConstSelf { def_id: ref __binding_0 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AliasTermKind::InherentConstImpl { def_id: ref __binding_0 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
31)]
32pub enum AliasTermKind<I: Interner> {
33 ProjectionTy { def_id: I::TraitAssocTyId },
43
44 InherentTy { def_id: I::InherentAssocTyId },
48
49 OpaqueTy { def_id: I::OpaqueTyId },
58
59 FreeTy { def_id: I::FreeTyAliasId },
64
65 AnonConst { def_id: I::AnonConstId },
67 ProjectionConst { def_id: I::TraitAssocConstId },
69 FreeConst { def_id: I::FreeConstAliasId },
71 InherentConstSelf { def_id: I::InherentAssocConstId },
74 InherentConstImpl { def_id: I::InherentAssocConstId },
77}
78
79impl<I: Interner> AliasTermKind<I> {
80 pub fn descr(self) -> &'static str {
81 match self {
82 AliasTermKind::ProjectionTy { .. } => "associated type",
83 AliasTermKind::ProjectionConst { .. } => "associated const",
84 AliasTermKind::InherentTy { .. } => "inherent associated type",
85 AliasTermKind::InherentConstSelf { .. } | AliasTermKind::InherentConstImpl { .. } => {
86 "inherent associated const"
87 }
88 AliasTermKind::OpaqueTy { .. } => "opaque type",
89 AliasTermKind::FreeTy { .. } => "type alias",
90 AliasTermKind::FreeConst { .. } => "const alias",
91 AliasTermKind::AnonConst { .. } => "anonymous constant",
92 }
93 }
94
95 pub fn is_type(self) -> bool {
96 match self {
97 AliasTermKind::ProjectionTy { .. }
98 | AliasTermKind::InherentTy { .. }
99 | AliasTermKind::OpaqueTy { .. }
100 | AliasTermKind::FreeTy { .. } => true,
101
102 AliasTermKind::AnonConst { .. }
103 | AliasTermKind::ProjectionConst { .. }
104 | AliasTermKind::InherentConstSelf { .. }
105 | AliasTermKind::InherentConstImpl { .. }
106 | AliasTermKind::FreeConst { .. } => false,
107 }
108 }
109
110 pub fn is_trait_projection(self) -> bool {
111 match self {
112 AliasTermKind::ProjectionTy { .. } | AliasTermKind::ProjectionConst { .. } => true,
113 AliasTermKind::InherentTy { .. }
114 | AliasTermKind::OpaqueTy { .. }
115 | AliasTermKind::FreeTy { .. }
116 | AliasTermKind::AnonConst { .. }
117 | AliasTermKind::FreeConst { .. }
118 | AliasTermKind::InherentConstSelf { .. }
119 | AliasTermKind::InherentConstImpl { .. } => false,
120 }
121 }
122}
123
124impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind<I> {
125 fn from(value: ty::AliasTyKind<I>) -> Self {
126 match value {
127 ty::Projection { def_id } => AliasTermKind::ProjectionTy { def_id },
128 ty::Opaque { def_id } => AliasTermKind::OpaqueTy { def_id },
129 ty::Free { def_id } => AliasTermKind::FreeTy { def_id },
130 ty::Inherent { def_id } => AliasTermKind::InherentTy { def_id },
131 }
132 }
133}
134
135impl<I: Interner> From<ty::AliasConstKind<I>> for AliasTermKind<I> {
136 fn from(value: ty::AliasConstKind<I>) -> Self {
137 match value {
138 ty::AliasConstKind::Projection { def_id } => AliasTermKind::ProjectionConst { def_id },
139 ty::AliasConstKind::InherentSelf { def_id } => {
140 AliasTermKind::InherentConstSelf { def_id }
141 }
142 ty::AliasConstKind::InherentImpl { def_id } => {
143 AliasTermKind::InherentConstImpl { def_id }
144 }
145 ty::AliasConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id },
146 ty::AliasConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id },
147 }
148 }
149}
150
151impl<I: Interner> AliasTerm<I> {
152 pub fn new_from_args(
153 interner: I,
154 kind: AliasTermKind<I>,
155 args: I::GenericArgs,
156 ) -> AliasTerm<I> {
157 if truecfg!(debug_assertions) {
158 interner.debug_assert_alias_term_args_compatible(kind, args);
159 }
160 AliasTerm { kind, args, _use_alias_new_instead: () }
161 }
162
163 pub fn new(
164 interner: I,
165 kind: AliasTermKind<I>,
166 args: impl IntoIterator<Item: Into<I::GenericArg>>,
167 ) -> AliasTerm<I> {
168 let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
169 Self::new_from_args(interner, kind, args)
170 }
171
172 pub fn new_from_def_id(
173 interner: I,
174 def_id: I::DefId,
175 args: I::GenericArgs,
176 inherent_args: ty::AliasConstInherentArgsKind,
177 ) -> AliasTerm<I> {
178 let kind = interner.alias_term_kind_from_def_id(def_id, inherent_args);
179 Self::new_from_args(interner, kind, args)
180 }
181
182 pub fn expect_ty(self) -> ty::AliasTy<I> {
183 let kind = match self.kind {
184 AliasTermKind::ProjectionTy { def_id } => ty::AliasTyKind::Projection { def_id },
185 AliasTermKind::InherentTy { def_id } => ty::AliasTyKind::Inherent { def_id },
186 AliasTermKind::OpaqueTy { def_id } => ty::AliasTyKind::Opaque { def_id },
187 AliasTermKind::FreeTy { def_id } => ty::AliasTyKind::Free { def_id },
188 kind @ (AliasTermKind::InherentConstSelf { .. }
189 | AliasTermKind::InherentConstImpl { .. }
190 | AliasTermKind::FreeConst { .. }
191 | AliasTermKind::AnonConst { .. }
192 | AliasTermKind::ProjectionConst { .. }) => {
193 {
::core::panicking::panic_fmt(format_args!("Cannot turn `{0}` into `AliasTy`",
kind.descr()));
}panic!("Cannot turn `{}` into `AliasTy`", kind.descr())
194 }
195 };
196 ty::AliasTy { kind, args: self.args, _use_alias_new_instead: () }
197 }
198
199 pub fn expect_ct(self) -> ty::AliasConst<I> {
200 let kind = match self.kind {
201 AliasTermKind::InherentConstSelf { def_id } => {
202 ty::AliasConstKind::InherentSelf { def_id }
203 }
204 AliasTermKind::InherentConstImpl { def_id } => {
205 ty::AliasConstKind::InherentImpl { def_id }
206 }
207 AliasTermKind::FreeConst { def_id } => ty::AliasConstKind::Free { def_id },
208 AliasTermKind::AnonConst { def_id } => ty::AliasConstKind::Anon { def_id },
209 AliasTermKind::ProjectionConst { def_id } => ty::AliasConstKind::Projection { def_id },
210 kind @ (AliasTermKind::ProjectionTy { .. }
211 | AliasTermKind::InherentTy { .. }
212 | AliasTermKind::OpaqueTy { .. }
213 | AliasTermKind::FreeTy { .. }) => {
214 {
::core::panicking::panic_fmt(format_args!("Cannot turn `{0}` into `AliasConst`",
kind.descr()));
}panic!("Cannot turn `{}` into `AliasConst`", kind.descr())
215 }
216 };
217 ty::AliasConst { kind, args: self.args, _use_alias_new_instead: () }
218 }
219
220 pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term {
221 let alias_ty = |kind| {
222 Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args))
223 .into()
224 };
225 let alias_const = |kind| {
226 I::Const::new_alias(interner, is_rigid, ty::AliasConst::new(interner, kind, self.args))
227 .into()
228 };
229 match self.kind {
230 AliasTermKind::FreeConst { def_id } => alias_const(ty::AliasConstKind::Free { def_id }),
231 AliasTermKind::InherentConstSelf { def_id } => {
232 alias_const(ty::AliasConstKind::InherentSelf { def_id })
233 }
234 AliasTermKind::InherentConstImpl { def_id } => {
235 alias_const(ty::AliasConstKind::InherentImpl { def_id })
236 }
237 AliasTermKind::AnonConst { def_id } => alias_const(ty::AliasConstKind::Anon { def_id }),
238 AliasTermKind::ProjectionConst { def_id } => {
239 alias_const(ty::AliasConstKind::Projection { def_id })
240 }
241 AliasTermKind::ProjectionTy { def_id } => alias_ty(ty::Projection { def_id }),
242 AliasTermKind::InherentTy { def_id } => alias_ty(ty::Inherent { def_id }),
243 AliasTermKind::OpaqueTy { def_id } => alias_ty(ty::Opaque { def_id }),
244 AliasTermKind::FreeTy { def_id } => alias_ty(ty::Free { def_id }),
245 }
246 }
247
248 pub fn with_args(self, interner: I, args: I::GenericArgs) -> Self {
249 Self::new_from_args(interner, self.kind, args)
250 }
251
252 pub fn expect_projection_ty_def_id(self) -> I::TraitAssocTyId {
253 match self.kind {
254 AliasTermKind::ProjectionTy { def_id } => def_id,
255 kind => {
::core::panicking::panic_fmt(format_args!("expected projection ty, found {0:?}",
kind));
}panic!("expected projection ty, found {kind:?}"),
256 }
257 }
258
259 pub fn expect_opaque_ty_def_id(self) -> I::OpaqueTyId {
260 match self.kind {
261 AliasTermKind::OpaqueTy { def_id } => def_id,
262 kind => {
::core::panicking::panic_fmt(format_args!("expected opaque ty, found {0:?}",
kind));
}panic!("expected opaque ty, found {kind:?}"),
263 }
264 }
265}
266
267impl<I: Interner> AliasTerm<I> {
270 fn debug_assert_has_self(self) {
271 if true {
{
match self.kind {
AliasTermKind::ProjectionTy { .. } |
AliasTermKind::ProjectionConst { .. } |
AliasTermKind::InherentTy { .. } |
AliasTermKind::InherentConstSelf { .. } => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"AliasTermKind::ProjectionTy { .. } | AliasTermKind::ProjectionConst { .. } |\nAliasTermKind::InherentTy { .. } | AliasTermKind::InherentConstSelf { .. }",
::core::option::Option::Some(format_args!("AliasTerm::self_ty is only valid on projection and inherent aliases")));
}
}
};
};debug_assert_matches!(
273 self.kind,
274 AliasTermKind::ProjectionTy { .. }
275 | AliasTermKind::ProjectionConst { .. }
276 | AliasTermKind::InherentTy { .. }
277 | AliasTermKind::InherentConstSelf { .. },
278 "AliasTerm::self_ty is only valid on projection and inherent aliases"
279 );
280 }
281
282 pub fn self_ty(self) -> I::Ty {
283 self.debug_assert_has_self();
284 self.args.type_at(0)
285 }
286
287 pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
288 self.debug_assert_has_self();
289 AliasTerm::new(
290 interner,
291 self.kind,
292 [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
293 )
294 }
295
296 pub fn expect_projection_def_id(self) -> I::TraitAssocTermId {
297 match self.kind {
298 AliasTermKind::ProjectionTy { def_id } => def_id.into(),
299 AliasTermKind::ProjectionConst { def_id } => def_id.into(),
300 kind => {
::core::panicking::panic_fmt(format_args!("expected projection alias, found {0:?}",
kind));
}panic!("expected projection alias, found {kind:?}"),
301 }
302 }
303
304 pub fn trait_def_id(self, interner: I) -> I::TraitId {
305 interner.projection_parent(self.expect_projection_def_id())
306 }
307
308 pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) {
313 interner.trait_ref_and_own_args_for_alias(self.expect_projection_def_id(), self.args)
314 }
315
316 pub fn trait_ref(self, interner: I) -> ty::TraitRef<I> {
324 self.trait_ref_and_own_args(interner).0
325 }
326
327 pub fn own_args(self, interner: I) -> I::GenericArgsSlice {
331 self.trait_ref_and_own_args(interner).1
332 }
333}
334
335impl<I: Interner> AliasTerm<I> {
338 pub fn expect_inherent_def_id(self) -> I::InherentAssocTermId {
339 match self.kind {
340 AliasTermKind::InherentTy { def_id } => def_id.into(),
341 AliasTermKind::InherentConstSelf { def_id } => def_id.into(),
342 AliasTermKind::InherentConstImpl { def_id } => def_id.into(),
343 kind => {
::core::panicking::panic_fmt(format_args!("expected inherent alias, found {0:?}",
kind));
}panic!("expected inherent alias, found {kind:?}"),
344 }
345 }
346
347 pub fn rebase_inherent_args_onto_impl(
358 self,
359 impl_args: I::GenericArgs,
360 interner: I,
361 ) -> I::GenericArgs {
362 if true {
if !#[allow(non_exhaustive_omitted_patterns)] match self.kind {
AliasTermKind::InherentTy { .. } |
AliasTermKind::InherentConstSelf { .. } => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(self.kind, AliasTermKind::InherentTy { .. } |\n AliasTermKind::InherentConstSelf { .. })")
};
};debug_assert!(matches!(
363 self.kind,
364 AliasTermKind::InherentTy { .. } | AliasTermKind::InherentConstSelf { .. }
365 ));
366 interner.mk_args_from_iter(impl_args.iter().chain(self.args.iter().skip(1)))
367 }
368}
369
370impl<I: Interner> AliasTerm<I> {
373 pub fn expect_free_def_id(self) -> I::FreeTermAliasId {
374 match self.kind {
375 AliasTermKind::FreeTy { def_id } => def_id.into(),
376 AliasTermKind::FreeConst { def_id } => def_id.into(),
377 kind => {
::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
kind));
}panic!("expected free alias, found {kind:?}"),
378 }
379 }
380}
381
382impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
383 fn from(ty: ty::AliasTy<I>) -> Self {
384 AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () }
385 }
386}
387
388impl<I: Interner> From<ty::AliasConst<I>> for AliasTerm<I> {
389 fn from(ty: ty::AliasConst<I>) -> Self {
390 AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () }
391 }
392}