Skip to main content

rustc_type_ir/
term_kind.rs

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, Const, 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>,
            Const<I>: ::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>,
            Const<I>: ::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>,
            Const<I>: ::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,
            Const<I>: ::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(Const<I>),
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    /// A projection `<Type as Trait>::AssocType`.
34    ///
35    /// Can get normalized away if monomorphic enough.
36    ///
37    /// The `def_id` is the `DefId` of the `TraitItem` for the associated type.
38    ///
39    /// Note that the `def_id` is not the `DefId` of the `TraitRef` containing this
40    /// associated type, which is in `interner.associated_item(def_id).container`,
41    /// aka. `interner.parent(def_id)`.
42    ProjectionTy { def_id: I::TraitAssocTyId },
43
44    /// An associated type in an inherent `impl`
45    ///
46    /// The `def_id` is the `DefId` of the `ImplItem` for the associated type.
47    InherentTy { def_id: I::InherentAssocTyId },
48
49    /// An opaque type (usually from `impl Trait` in type aliases or function return types)
50    ///
51    /// `def_id` is the `DefId` of the `OpaqueType` item.
52    ///
53    /// Can only be normalized away in `PostAnalysis` mode or its defining scope.
54    ///
55    /// During codegen, `interner.type_of(def_id)` can be used to get the type of the
56    /// underlying type if the type is an opaque.
57    OpaqueTy { def_id: I::OpaqueTyId },
58
59    /// A type alias that actually checks its trait bounds.
60    ///
61    /// Currently only used if the type alias references opaque types.
62    /// Can always be normalized away.
63    FreeTy { def_id: I::FreeTyAliasId },
64
65    /// An anonymous constant.
66    AnonConst { def_id: I::AnonConstId },
67    /// A const alias coming from an associated const.
68    ProjectionConst { def_id: I::TraitAssocConstId },
69    /// A top level const item not part of a trait or impl.
70    FreeConst { def_id: I::FreeConstAliasId },
71    /// An associated const in an inherent `impl`. See [`ty::AliasConstKind::InherentSelf`] for a
72    /// description on the difference between `InherentConstSelf` and `InherentConstImpl`.
73    InherentConstSelf { def_id: I::InherentAssocConstId },
74    /// An associated const in an inherent `impl`. See [`ty::AliasConstKind::InherentSelf`] for a
75    /// description on the difference between `InherentConstSelf` and `InherentConstImpl`.
76    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 expect_ty(self) -> ty::AliasTy<I> {
173        let kind = match self.kind {
174            AliasTermKind::ProjectionTy { def_id } => ty::AliasTyKind::Projection { def_id },
175            AliasTermKind::InherentTy { def_id } => ty::AliasTyKind::Inherent { def_id },
176            AliasTermKind::OpaqueTy { def_id } => ty::AliasTyKind::Opaque { def_id },
177            AliasTermKind::FreeTy { def_id } => ty::AliasTyKind::Free { def_id },
178            kind @ (AliasTermKind::InherentConstSelf { .. }
179            | AliasTermKind::InherentConstImpl { .. }
180            | AliasTermKind::FreeConst { .. }
181            | AliasTermKind::AnonConst { .. }
182            | AliasTermKind::ProjectionConst { .. }) => {
183                {
    ::core::panicking::panic_fmt(format_args!("Cannot turn `{0}` into `AliasTy`",
            kind.descr()));
}panic!("Cannot turn `{}` into `AliasTy`", kind.descr())
184            }
185        };
186        ty::AliasTy { kind, args: self.args, _use_alias_new_instead: () }
187    }
188
189    pub fn expect_ct(self) -> ty::AliasConst<I> {
190        let kind = match self.kind {
191            AliasTermKind::InherentConstSelf { def_id } => {
192                ty::AliasConstKind::InherentSelf { def_id }
193            }
194            AliasTermKind::InherentConstImpl { def_id } => {
195                ty::AliasConstKind::InherentImpl { def_id }
196            }
197            AliasTermKind::FreeConst { def_id } => ty::AliasConstKind::Free { def_id },
198            AliasTermKind::AnonConst { def_id } => ty::AliasConstKind::Anon { def_id },
199            AliasTermKind::ProjectionConst { def_id } => ty::AliasConstKind::Projection { def_id },
200            kind @ (AliasTermKind::ProjectionTy { .. }
201            | AliasTermKind::InherentTy { .. }
202            | AliasTermKind::OpaqueTy { .. }
203            | AliasTermKind::FreeTy { .. }) => {
204                {
    ::core::panicking::panic_fmt(format_args!("Cannot turn `{0}` into `AliasConst`",
            kind.descr()));
}panic!("Cannot turn `{}` into `AliasConst`", kind.descr())
205            }
206        };
207        ty::AliasConst { kind, args: self.args, _use_alias_new_instead: () }
208    }
209
210    pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term {
211        let alias_ty = |kind| {
212            Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args))
213                .into()
214        };
215        let alias_const = |kind| {
216            Const::new_alias(interner, is_rigid, ty::AliasConst::new(interner, kind, self.args))
217                .into()
218        };
219        match self.kind {
220            AliasTermKind::FreeConst { def_id } => alias_const(ty::AliasConstKind::Free { def_id }),
221            AliasTermKind::InherentConstSelf { def_id } => {
222                alias_const(ty::AliasConstKind::InherentSelf { def_id })
223            }
224            AliasTermKind::InherentConstImpl { def_id } => {
225                alias_const(ty::AliasConstKind::InherentImpl { def_id })
226            }
227            AliasTermKind::AnonConst { def_id } => alias_const(ty::AliasConstKind::Anon { def_id }),
228            AliasTermKind::ProjectionConst { def_id } => {
229                alias_const(ty::AliasConstKind::Projection { def_id })
230            }
231            AliasTermKind::ProjectionTy { def_id } => alias_ty(ty::Projection { def_id }),
232            AliasTermKind::InherentTy { def_id } => alias_ty(ty::Inherent { def_id }),
233            AliasTermKind::OpaqueTy { def_id } => alias_ty(ty::Opaque { def_id }),
234            AliasTermKind::FreeTy { def_id } => alias_ty(ty::Free { def_id }),
235        }
236    }
237
238    pub fn with_args(self, interner: I, args: I::GenericArgs) -> Self {
239        Self::new_from_args(interner, self.kind, args)
240    }
241
242    pub fn expect_projection_ty_def_id(self) -> I::TraitAssocTyId {
243        match self.kind {
244            AliasTermKind::ProjectionTy { def_id } => def_id,
245            kind => {
    ::core::panicking::panic_fmt(format_args!("expected projection ty, found {0:?}",
            kind));
}panic!("expected projection ty, found {kind:?}"),
246        }
247    }
248
249    pub fn expect_opaque_ty_def_id(self) -> I::OpaqueTyId {
250        match self.kind {
251            AliasTermKind::OpaqueTy { def_id } => def_id,
252            kind => {
    ::core::panicking::panic_fmt(format_args!("expected opaque ty, found {0:?}",
            kind));
}panic!("expected opaque ty, found {kind:?}"),
253        }
254    }
255}
256
257/// The following methods work only with (trait) associated term projections.
258// FIXME: Replace by an impl on Alias<ProjectionAliasTermKind>
259impl<I: Interner> AliasTerm<I> {
260    fn debug_assert_has_self(self) {
261        // InherentConstImpl is deliberately omitted here, it is not self-format args
262        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!(
263            self.kind,
264            AliasTermKind::ProjectionTy { .. }
265                | AliasTermKind::ProjectionConst { .. }
266                | AliasTermKind::InherentTy { .. }
267                | AliasTermKind::InherentConstSelf { .. },
268            "AliasTerm::self_ty is only valid on projection and inherent aliases"
269        );
270    }
271
272    pub fn self_ty(self) -> I::Ty {
273        self.debug_assert_has_self();
274        self.args.type_at(0)
275    }
276
277    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
278        self.debug_assert_has_self();
279        AliasTerm::new(
280            interner,
281            self.kind,
282            [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
283        )
284    }
285
286    pub fn expect_projection_def_id(self) -> I::TraitAssocTermId {
287        match self.kind {
288            AliasTermKind::ProjectionTy { def_id } => def_id.into(),
289            AliasTermKind::ProjectionConst { def_id } => def_id.into(),
290            kind => {
    ::core::panicking::panic_fmt(format_args!("expected projection alias, found {0:?}",
            kind));
}panic!("expected projection alias, found {kind:?}"),
291        }
292    }
293
294    pub fn trait_def_id(self, interner: I) -> I::TraitId {
295        interner.projection_parent(self.expect_projection_def_id())
296    }
297
298    /// Extracts the underlying trait reference and own args from this projection.
299    /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
300    /// then this function would return a `T: StreamingIterator` trait reference and
301    /// `['a]` as the own args.
302    pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) {
303        interner.trait_ref_and_own_args_for_alias(self.expect_projection_def_id(), self.args)
304    }
305
306    /// Extracts the underlying trait reference from this projection.
307    /// For example, if this is a projection of `<T as Iterator>::Item`,
308    /// then this function would return a `T: Iterator` trait reference.
309    ///
310    /// WARNING: This will drop the args for generic associated types
311    /// consider calling [Self::trait_ref_and_own_args] to get those
312    /// as well.
313    pub fn trait_ref(self, interner: I) -> ty::TraitRef<I> {
314        self.trait_ref_and_own_args(interner).0
315    }
316
317    /// Extract the own args from this projection.
318    /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
319    /// then this function would return the slice `['a]` as the own args.
320    pub fn own_args(self, interner: I) -> I::GenericArgsSlice {
321        self.trait_ref_and_own_args(interner).1
322    }
323}
324
325/// The following methods work only with inherent associated term projections.
326// FIXME: Replace by an impl on Alias<InherentAliasTermKind>
327impl<I: Interner> AliasTerm<I> {
328    pub fn expect_inherent_def_id(self) -> I::InherentAssocTermId {
329        match self.kind {
330            AliasTermKind::InherentTy { def_id } => def_id.into(),
331            AliasTermKind::InherentConstSelf { def_id } => def_id.into(),
332            AliasTermKind::InherentConstImpl { def_id } => def_id.into(),
333            kind => {
    ::core::panicking::panic_fmt(format_args!("expected inherent alias, found {0:?}",
            kind));
}panic!("expected inherent alias, found {kind:?}"),
334        }
335    }
336
337    /// Transform the generic parameters to have the given `impl` args as the base and the GAT args on top of that.
338    ///
339    /// Does the following transformation:
340    ///
341    /// ```text
342    /// [Self, P_0...P_m] -> [I_0...I_n, P_0...P_m]
343    ///
344    ///     I_i impl args
345    ///     P_j GAT args
346    /// ```
347    pub fn rebase_inherent_args_onto_impl(
348        self,
349        impl_args: I::GenericArgs,
350        interner: I,
351    ) -> I::GenericArgs {
352        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!(
353            self.kind,
354            AliasTermKind::InherentTy { .. } | AliasTermKind::InherentConstSelf { .. }
355        ));
356        interner.mk_args_from_iter(impl_args.iter().chain(self.args.iter().skip(1)))
357    }
358}
359
360/// The following methods work only with free term aliases.
361// FIXME: Replace by an impl on Alias<FreeAliasTermKind>
362impl<I: Interner> AliasTerm<I> {
363    pub fn expect_free_def_id(self) -> I::FreeTermAliasId {
364        match self.kind {
365            AliasTermKind::FreeTy { def_id } => def_id.into(),
366            AliasTermKind::FreeConst { def_id } => def_id.into(),
367            kind => {
    ::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
            kind));
}panic!("expected free alias, found {kind:?}"),
368        }
369    }
370}
371
372impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
373    fn from(ty: ty::AliasTy<I>) -> Self {
374        AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () }
375    }
376}
377
378impl<I: Interner> From<ty::AliasConst<I>> for AliasTerm<I> {
379    fn from(ty: ty::AliasConst<I>) -> Self {
380        AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () }
381    }
382}