Skip to main content

rustc_type_ir/
predicate.rs

1use std::hash::Hash;
2use std::{fmt, iter};
3
4use derive_where::derive_where;
5#[cfg(feature = "nightly")]
6use rustc_macros::{
7    Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, HashStable_NoContext,
8};
9use rustc_type_ir_macros::{
10    GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
11};
12
13use crate::inherent::*;
14use crate::lift::Lift;
15use crate::upcast::{Upcast, UpcastFrom};
16use crate::visit::TypeVisitableExt as _;
17use crate::{self as ty, AliasTyKind, Interner};
18
19/// `A: 'region`
20#[automatically_derived]
impl<I: Interner, A> ::core::marker::Copy for OutlivesPredicate<I, A> where
    I: Interner, A: Copy {
}#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)]
21#[derive_where(Copy; I: Interner, A: Copy)]
22#[derive(const _: () =
    {
        impl<I: Interner, A> ::rustc_type_ir::TypeVisitable<I> for
            OutlivesPredicate<I, A> where I: Interner,
            A: ::rustc_type_ir::TypeVisitable<I>,
            I::Region: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    OutlivesPredicate(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, A> ::rustc_type_ir::TypeFoldable<I> for
            OutlivesPredicate<I, A> where I: Interner,
            A: ::rustc_type_ir::TypeFoldable<I>,
            I::Region: ::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 {
                        OutlivesPredicate(__binding_0, __binding_1) => {
                            OutlivesPredicate(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    OutlivesPredicate(__binding_0, __binding_1) => {
                        OutlivesPredicate(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
23#[cfg_attr(
24    feature = "nightly",
25    derive(const _: () =
    {
        impl<I: Interner, A, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for OutlivesPredicate<I, A>
            where A: ::rustc_serialize::Decodable<__D>,
            I::Region: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                OutlivesPredicate(::rustc_serialize::Decodable::decode(__decoder),
                    ::rustc_serialize::Decodable::decode(__decoder))
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, A, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for OutlivesPredicate<I, A>
            where A: ::rustc_serialize::Encodable<__E>,
            I::Region: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    OutlivesPredicate(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, A, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            OutlivesPredicate<I, A> where
            A: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Region: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    OutlivesPredicate(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
26)]
27pub struct OutlivesPredicate<I: Interner, A>(pub A, pub I::Region);
28
29impl<I: Interner, A: Eq> Eq for OutlivesPredicate<I, A> {}
30
31// FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't
32// understand how to turn `A` to `A::Lifted` in the output `type Lifted`.
33impl<I: Interner, U: Interner, A> Lift<U> for OutlivesPredicate<I, A>
34where
35    A: Lift<U>,
36    I::Region: Lift<U, Lifted = U::Region>,
37{
38    type Lifted = OutlivesPredicate<U, A::Lifted>;
39
40    fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
41        Some(OutlivesPredicate(self.0.lift_to_interner(cx)?, self.1.lift_to_interner(cx)?))
42    }
43}
44
45/// `'a == 'b`.
46/// For the rationale behind having this instead of a pair of bidirectional
47/// `'a: 'b` and `'b: 'a`, see
48/// [this discusstion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/A.20question.20on.20.23251/near/584167074).
49#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for RegionEqPredicate<I> where
    I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            RegionEqPredicate(ref __field_0, ref __field_1) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f,
                        "RegionEqPredicate");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::field(&mut __builder, __field_1);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
50#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            RegionEqPredicate<I> where I: Interner,
            I::Region: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    RegionEqPredicate(ref __binding_0, ref __binding_1) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            RegionEqPredicate<I> where I: Interner,
            I::Region: ::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 {
                        RegionEqPredicate(__binding_0, __binding_1) => {
                            RegionEqPredicate(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?)
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    RegionEqPredicate(__binding_0, __binding_1) => {
                        RegionEqPredicate(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            RegionEqPredicate<I> where I: Interner, J: Interner,
            I::Region: ::rustc_type_ir::lift::Lift<J, Lifted = J::Region>,
            I::Region: ::rustc_type_ir::lift::Lift<J, Lifted = J::Region> {
            type Lifted = RegionEqPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        RegionEqPredicate(__binding_0, __binding_1) => {
                            RegionEqPredicate(__binding_0.lift_to_interner(interner)?,
                                __binding_1.lift_to_interner(interner)?)
                        }
                    })
            }
        }
    };Lift_Generic)]
51#[cfg_attr(
52    feature = "nightly",
53    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for RegionEqPredicate<I> where
            I::Region: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                RegionEqPredicate(::rustc_serialize::Decodable::decode(__decoder),
                    ::rustc_serialize::Decodable::decode(__decoder))
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for RegionEqPredicate<I> where
            I::Region: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    RegionEqPredicate(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            RegionEqPredicate<I> where
            I::Region: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    RegionEqPredicate(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
54)]
55pub struct RegionEqPredicate<I: Interner>(pub I::Region, pub I::Region);
56
57impl<I: Interner> RegionEqPredicate<I> {
58    /// Decompose `'a == 'b` into `['a: 'b, 'b: 'a]`
59    pub fn into_bidirectional_outlives(self) -> [OutlivesPredicate<I, I::GenericArg>; 2] {
60        [OutlivesPredicate(self.0.into(), self.1), OutlivesPredicate(self.1.into(), self.0)]
61    }
62}
63
64#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for RegionConstraint<I> where I: Interner
    {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            RegionConstraint::Outlives(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Outlives");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            RegionConstraint::Eq(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Eq");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
65#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            RegionConstraint<I> where I: Interner,
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_type_ir::TypeVisitable<I>,
            RegionEqPredicate<I>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    RegionConstraint::Outlives(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);
                                }
                            }
                        }
                    }
                    RegionConstraint::Eq(ref __binding_0) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            RegionConstraint<I> where I: Interner,
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_type_ir::TypeFoldable<I>,
            RegionEqPredicate<I>: ::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 {
                        RegionConstraint::Outlives(__binding_0) => {
                            RegionConstraint::Outlives(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        RegionConstraint::Eq(__binding_0) => {
                            RegionConstraint::Eq(::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 {
                    RegionConstraint::Outlives(__binding_0) => {
                        RegionConstraint::Outlives(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    RegionConstraint::Eq(__binding_0) => {
                        RegionConstraint::Eq(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            RegionConstraint<I> where I: Interner, J: Interner,
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_type_ir::lift::Lift<J, Lifted =
            OutlivesPredicate<J, J::GenericArg>>,
            RegionEqPredicate<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            RegionEqPredicate<J>> {
            type Lifted = RegionConstraint<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        RegionConstraint::Outlives(__binding_0) => {
                            RegionConstraint::Outlives(__binding_0.lift_to_interner(interner)?)
                        }
                        RegionConstraint::Eq(__binding_0) => {
                            RegionConstraint::Eq(__binding_0.lift_to_interner(interner)?)
                        }
                    })
            }
        }
    };Lift_Generic)]
66#[cfg_attr(
67    feature = "nightly",
68    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for RegionConstraint<I> where
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_serialize::Decodable<__D>,
            RegionEqPredicate<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        RegionConstraint::Outlives(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        RegionConstraint::Eq(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `RegionConstraint`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for RegionConstraint<I> where
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_serialize::Encodable<__E>,
            RegionEqPredicate<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        RegionConstraint::Outlives(ref __binding_0) => { 0usize }
                        RegionConstraint::Eq(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    RegionConstraint::Outlives(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    RegionConstraint::Eq(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            RegionConstraint<I> where
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            RegionEqPredicate<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    RegionConstraint::Outlives(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    RegionConstraint::Eq(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
69)]
70pub enum RegionConstraint<I: Interner> {
71    Outlives(OutlivesPredicate<I, I::GenericArg>),
72    Eq(RegionEqPredicate<I>),
73}
74
75impl<I: Interner> From<OutlivesPredicate<I, I::GenericArg>> for RegionConstraint<I> {
76    fn from(value: OutlivesPredicate<I, I::GenericArg>) -> Self {
77        RegionConstraint::Outlives(value)
78    }
79}
80
81impl<I: Interner> From<RegionEqPredicate<I>> for RegionConstraint<I> {
82    fn from(value: RegionEqPredicate<I>) -> Self {
83        RegionConstraint::Eq(value)
84    }
85}
86
87impl<I: Interner> RegionConstraint<I> {
88    /// Whether the given constraint is either `'a: 'a` or `'a == 'a`.
89    pub fn is_trivial(self) -> bool {
90        match self {
91            RegionConstraint::Outlives(outlives) => {
92                outlives.0.as_region().is_some_and(|re| re == outlives.1)
93            }
94            RegionConstraint::Eq(eq) => eq.0 == eq.1,
95        }
96    }
97
98    /// If `self` is an eq constraint, iterate through its decomposed bidirectional outlives
99    /// bounds and if not, just iterate once for the outlives bound itself.
100    pub fn iter_outlives(self) -> impl Iterator<Item = OutlivesPredicate<I, I::GenericArg>> {
101        match self {
102            RegionConstraint::Outlives(outlives) => iter::once(outlives).chain(None),
103            RegionConstraint::Eq(eq) => {
104                let [outlives1, outlives2] = eq.into_bidirectional_outlives();
105                iter::once(outlives1).chain(Some(outlives2))
106            }
107        }
108    }
109}
110
111/// A complete reference to a trait.
112///
113/// These take numerous guises in syntax,
114/// but perhaps the most recognizable form is in a where-clause:
115/// ```ignore (illustrative)
116/// T: Foo<U>
117/// ```
118/// This would be represented by a trait-reference where the `DefId` is the
119/// `DefId` for the trait `Foo` and the args define `T` as parameter 0,
120/// and `U` as parameter 1.
121///
122/// Trait references also appear in object types like `Foo<U>`, but in
123/// that case the `Self` parameter is absent from the generic parameters.
124#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for TraitRef<I> where I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (TraitRef {
                def_id: ref __field_def_id,
                args: ref __field_args,
                _use_trait_ref_new_instead: ref __field__use_trait_ref_new_instead
                }, TraitRef {
                def_id: ref __other_field_def_id,
                args: ref __other_field_args,
                _use_trait_ref_new_instead: ref __other_field__use_trait_ref_new_instead
                }) =>
                true &&
                            ::core::cmp::PartialEq::eq(__field_def_id,
                                __other_field_def_id) &&
                        ::core::cmp::PartialEq::eq(__field_args, __other_field_args)
                    &&
                    ::core::cmp::PartialEq::eq(__field__use_trait_ref_new_instead,
                        __other_field__use_trait_ref_new_instead),
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
125#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for TraitRef<I>
            where I: Interner, I::TraitId: ::rustc_type_ir::TypeVisitable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    TraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_trait_ref_new_instead: ref __binding_2 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for TraitRef<I>
            where I: Interner, I::TraitId: ::rustc_type_ir::TypeFoldable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        TraitRef {
                            def_id: __binding_0,
                            args: __binding_1,
                            _use_trait_ref_new_instead: __binding_2 } => {
                            TraitRef {
                                def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                _use_trait_ref_new_instead: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    TraitRef {
                        def_id: __binding_0,
                        args: __binding_1,
                        _use_trait_ref_new_instead: __binding_2 } => {
                        TraitRef {
                            def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            _use_trait_ref_new_instead: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for TraitRef<I>
            where I: Interner, J: Interner,
            I::TraitId: ::rustc_type_ir::lift::Lift<J, Lifted = J::TraitId>,
            I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::GenericArgs>, (): ::rustc_type_ir::lift::Lift<J, Lifted = ()> {
            type Lifted = TraitRef<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        TraitRef {
                            def_id: __binding_0,
                            args: __binding_1,
                            _use_trait_ref_new_instead: __binding_2 } => {
                            TraitRef {
                                def_id: __binding_0.lift_to_interner(interner)?,
                                args: __binding_1.lift_to_interner(interner)?,
                                _use_trait_ref_new_instead: __binding_2.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
126#[cfg_attr(
127    feature = "nightly",
128    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for TraitRef<I> where
            I::TraitId: ::rustc_serialize::Decodable<__D>,
            I::GenericArgs: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                TraitRef {
                    def_id: ::rustc_serialize::Decodable::decode(__decoder),
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                    _use_trait_ref_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for TraitRef<I> where
            I::TraitId: ::rustc_serialize::Encodable<__E>,
            I::GenericArgs: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    TraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_trait_ref_new_instead: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            TraitRef<I> where
            I::TraitId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    TraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_trait_ref_new_instead: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
129)]
130pub struct TraitRef<I: Interner> {
131    pub def_id: I::TraitId,
132    pub args: I::GenericArgs,
133    /// This field exists to prevent the creation of `TraitRef` without
134    /// calling [`TraitRef::new_from_args`].
135    _use_trait_ref_new_instead: (),
136}
137
138impl<I: Interner> Eq for TraitRef<I> {}
139
140impl<I: Interner> TraitRef<I> {
141    pub fn new_from_args(interner: I, trait_def_id: I::TraitId, args: I::GenericArgs) -> Self {
142        interner.debug_assert_args_compatible(trait_def_id.into(), args);
143        Self { def_id: trait_def_id, args, _use_trait_ref_new_instead: () }
144    }
145
146    pub fn new(
147        interner: I,
148        trait_def_id: I::TraitId,
149        args: impl IntoIterator<Item: Into<I::GenericArg>>,
150    ) -> Self {
151        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
152        Self::new_from_args(interner, trait_def_id, args)
153    }
154
155    pub fn from_assoc(interner: I, trait_id: I::TraitId, args: I::GenericArgs) -> TraitRef<I> {
156        let generics = interner.generics_of(trait_id.into());
157        TraitRef::new(interner, trait_id, args.iter().take(generics.count()))
158    }
159
160    /// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
161    /// are the parameters defined on trait.
162    pub fn identity(interner: I, def_id: I::TraitId) -> TraitRef<I> {
163        TraitRef::new_from_args(
164            interner,
165            def_id,
166            I::GenericArgs::identity_for_item(interner, def_id.into()),
167        )
168    }
169
170    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
171        TraitRef::new(
172            interner,
173            self.def_id,
174            [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
175        )
176    }
177
178    #[inline]
179    pub fn self_ty(&self) -> I::Ty {
180        self.args.type_at(0)
181    }
182}
183
184impl<I: Interner> ty::Binder<I, TraitRef<I>> {
185    pub fn self_ty(&self) -> ty::Binder<I, I::Ty> {
186        self.map_bound_ref(|tr| tr.self_ty())
187    }
188
189    pub fn def_id(&self) -> I::TraitId {
190        self.skip_binder().def_id
191    }
192
193    pub fn to_host_effect_clause(self, cx: I, constness: BoundConstness) -> I::Clause {
194        self.map_bound(|trait_ref| {
195            ty::ClauseKind::HostEffect(HostEffectPredicate { trait_ref, constness })
196        })
197        .upcast(cx)
198    }
199}
200
201#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for TraitPredicate<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (TraitPredicate {
                trait_ref: ref __field_trait_ref,
                polarity: ref __field_polarity }, TraitPredicate {
                trait_ref: ref __other_field_trait_ref,
                polarity: ref __other_field_polarity }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_trait_ref,
                            __other_field_trait_ref) &&
                    ::core::cmp::PartialEq::eq(__field_polarity,
                        __other_field_polarity),
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
202#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            TraitPredicate<I> where I: Interner,
            TraitRef<I>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    TraitPredicate {
                        trait_ref: ref __binding_0, polarity: ref __binding_1 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            TraitPredicate<I> where I: Interner,
            TraitRef<I>: ::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 {
                        TraitPredicate {
                            trait_ref: __binding_0, polarity: __binding_1 } => {
                            TraitPredicate {
                                trait_ref: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                polarity: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    TraitPredicate {
                        trait_ref: __binding_0, polarity: __binding_1 } => {
                        TraitPredicate {
                            trait_ref: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            polarity: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            TraitPredicate<I> where I: Interner, J: Interner,
            TraitRef<I>: ::rustc_type_ir::lift::Lift<J, Lifted = TraitRef<J>>,
            PredicatePolarity: ::rustc_type_ir::lift::Lift<J, Lifted =
            PredicatePolarity> {
            type Lifted = TraitPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        TraitPredicate {
                            trait_ref: __binding_0, polarity: __binding_1 } => {
                            TraitPredicate {
                                trait_ref: __binding_0.lift_to_interner(interner)?,
                                polarity: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
203#[cfg_attr(
204    feature = "nightly",
205    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for TraitPredicate<I> where
            TraitRef<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                TraitPredicate {
                    trait_ref: ::rustc_serialize::Decodable::decode(__decoder),
                    polarity: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for TraitPredicate<I> where
            TraitRef<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    TraitPredicate {
                        trait_ref: ref __binding_0, polarity: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            TraitPredicate<I> where
            TraitRef<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    TraitPredicate {
                        trait_ref: ref __binding_0, polarity: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
206)]
207pub struct TraitPredicate<I: Interner> {
208    pub trait_ref: TraitRef<I>,
209
210    /// If polarity is Positive: we are proving that the trait is implemented.
211    ///
212    /// If polarity is Negative: we are proving that a negative impl of this trait
213    /// exists. (Note that coherence also checks whether negative impls of supertraits
214    /// exist via a series of predicates.)
215    pub polarity: PredicatePolarity,
216}
217
218impl<I: Interner> Eq for TraitPredicate<I> {}
219
220impl<I: Interner> TraitPredicate<I> {
221    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
222        Self {
223            trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty),
224            polarity: self.polarity,
225        }
226    }
227
228    pub fn def_id(self) -> I::TraitId {
229        self.trait_ref.def_id
230    }
231
232    pub fn self_ty(self) -> I::Ty {
233        self.trait_ref.self_ty()
234    }
235}
236
237impl<I: Interner> ty::Binder<I, TraitPredicate<I>> {
238    pub fn def_id(self) -> I::TraitId {
239        // Ok to skip binder since trait `DefId` does not care about regions.
240        self.skip_binder().def_id()
241    }
242
243    pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
244        self.map_bound(|trait_ref| trait_ref.self_ty())
245    }
246
247    #[inline]
248    pub fn polarity(self) -> PredicatePolarity {
249        self.skip_binder().polarity
250    }
251}
252
253impl<I: Interner> UpcastFrom<I, TraitRef<I>> for TraitPredicate<I> {
254    fn upcast_from(from: TraitRef<I>, _tcx: I) -> Self {
255        TraitPredicate { trait_ref: from, polarity: PredicatePolarity::Positive }
256    }
257}
258
259impl<I: Interner> UpcastFrom<I, ty::Binder<I, TraitRef<I>>> for ty::Binder<I, TraitPredicate<I>> {
260    fn upcast_from(from: ty::Binder<I, TraitRef<I>>, _tcx: I) -> Self {
261        from.map_bound(|trait_ref| TraitPredicate {
262            trait_ref,
263            polarity: PredicatePolarity::Positive,
264        })
265    }
266}
267
268impl<I: Interner> fmt::Debug for TraitPredicate<I> {
269    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270        f.write_fmt(format_args!("TraitPredicate({0:?}, polarity:{1:?})",
        self.trait_ref, self.polarity))write!(f, "TraitPredicate({:?}, polarity:{:?})", self.trait_ref, self.polarity)
271    }
272}
273
274#[derive(#[automatically_derived]
impl ::core::clone::Clone for ImplPolarity {
    #[inline]
    fn clone(&self) -> ImplPolarity { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ImplPolarity { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplPolarity {
    #[inline]
    fn eq(&self, other: &ImplPolarity) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplPolarity {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for ImplPolarity {
    #[inline]
    fn partial_cmp(&self, other: &ImplPolarity)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for ImplPolarity {
    #[inline]
    fn cmp(&self, other: &ImplPolarity) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for ImplPolarity {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for ImplPolarity {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ImplPolarity::Positive => "Positive",
                ImplPolarity::Negative => "Negative",
                ImplPolarity::Reservation => "Reservation",
            })
    }
}Debug)]
275#[cfg_attr(
276    feature = "nightly",
277    derive(const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ImplPolarity {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { ImplPolarity::Positive }
                    1usize => { ImplPolarity::Negative }
                    2usize => { ImplPolarity::Reservation }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ImplPolarity`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for ImplPolarity {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        ImplPolarity::Positive => { 0usize }
                        ImplPolarity::Negative => { 1usize }
                        ImplPolarity::Reservation => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    ImplPolarity::Positive => {}
                    ImplPolarity::Negative => {}
                    ImplPolarity::Reservation => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for ImplPolarity {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    ImplPolarity::Positive => {}
                    ImplPolarity::Negative => {}
                    ImplPolarity::Reservation => {}
                }
            }
        }
    };HashStable_NoContext)
278)]
279pub enum ImplPolarity {
280    /// `impl Trait for Type`
281    Positive,
282    /// `impl !Trait for Type`
283    Negative,
284    /// `#[rustc_reservation_impl] impl Trait for Type`
285    ///
286    /// This is a "stability hack", not a real Rust feature.
287    /// See #64631 for details.
288    Reservation,
289}
290
291impl fmt::Display for ImplPolarity {
292    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
293        match self {
294            Self::Positive => f.write_str("positive"),
295            Self::Negative => f.write_str("negative"),
296            Self::Reservation => f.write_str("reservation"),
297        }
298    }
299}
300
301impl ImplPolarity {
302    /// The polarity marker in front of the impl trait ref if applicable.
303    pub fn as_str(self) -> &'static str {
304        match self {
305            Self::Positive => "",
306            Self::Negative => "!",
307            Self::Reservation => "",
308        }
309    }
310}
311
312/// Polarity for a trait predicate.
313///
314/// May either be negative or positive.
315/// Distinguished from [`ImplPolarity`] since we never compute goals with
316/// "reservation" level.
317#[derive(#[automatically_derived]
impl ::core::clone::Clone for PredicatePolarity {
    #[inline]
    fn clone(&self) -> PredicatePolarity { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PredicatePolarity { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for PredicatePolarity {
    #[inline]
    fn eq(&self, other: &PredicatePolarity) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PredicatePolarity {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for PredicatePolarity {
    #[inline]
    fn partial_cmp(&self, other: &PredicatePolarity)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for PredicatePolarity {
    #[inline]
    fn cmp(&self, other: &PredicatePolarity) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for PredicatePolarity {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for PredicatePolarity {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                PredicatePolarity::Positive => "Positive",
                PredicatePolarity::Negative => "Negative",
            })
    }
}Debug)]
318#[cfg_attr(
319    feature = "nightly",
320    derive(const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for PredicatePolarity {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { PredicatePolarity::Positive }
                    1usize => { PredicatePolarity::Negative }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `PredicatePolarity`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for PredicatePolarity {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        PredicatePolarity::Positive => { 0usize }
                        PredicatePolarity::Negative => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    PredicatePolarity::Positive => {}
                    PredicatePolarity::Negative => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for PredicatePolarity {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    PredicatePolarity::Positive => {}
                    PredicatePolarity::Negative => {}
                }
            }
        }
    };HashStable_NoContext)
321)]
322pub enum PredicatePolarity {
323    /// `Type: Trait`
324    Positive,
325    /// `Type: !Trait`
326    Negative,
327}
328
329impl PredicatePolarity {
330    /// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
331    pub fn flip(&self) -> PredicatePolarity {
332        match self {
333            PredicatePolarity::Positive => PredicatePolarity::Negative,
334            PredicatePolarity::Negative => PredicatePolarity::Positive,
335        }
336    }
337}
338
339impl fmt::Display for PredicatePolarity {
340    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
341        match self {
342            Self::Positive => f.write_str("positive"),
343            Self::Negative => f.write_str("negative"),
344        }
345    }
346}
347
348#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for ExistentialPredicate<I> where
    I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            ExistentialPredicate::Trait(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Trait");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            ExistentialPredicate::Projection(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Projection");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            ExistentialPredicate::AutoTrait(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "AutoTrait");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
349#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ExistentialPredicate<I> where I: Interner,
            ExistentialTraitRef<I>: ::rustc_type_ir::TypeVisitable<I>,
            ExistentialProjection<I>: ::rustc_type_ir::TypeVisitable<I>,
            I::TraitId: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ExistentialPredicate::Trait(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);
                                }
                            }
                        }
                    }
                    ExistentialPredicate::Projection(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);
                                }
                            }
                        }
                    }
                    ExistentialPredicate::AutoTrait(ref __binding_0) => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            ExistentialPredicate<I> where I: Interner,
            ExistentialTraitRef<I>: ::rustc_type_ir::TypeFoldable<I>,
            ExistentialProjection<I>: ::rustc_type_ir::TypeFoldable<I>,
            I::TraitId: ::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 {
                        ExistentialPredicate::Trait(__binding_0) => {
                            ExistentialPredicate::Trait(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        ExistentialPredicate::Projection(__binding_0) => {
                            ExistentialPredicate::Projection(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        ExistentialPredicate::AutoTrait(__binding_0) => {
                            ExistentialPredicate::AutoTrait(::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 {
                    ExistentialPredicate::Trait(__binding_0) => {
                        ExistentialPredicate::Trait(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    ExistentialPredicate::Projection(__binding_0) => {
                        ExistentialPredicate::Projection(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    ExistentialPredicate::AutoTrait(__binding_0) => {
                        ExistentialPredicate::AutoTrait(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            ExistentialPredicate<I> where I: Interner, J: Interner,
            ExistentialTraitRef<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            ExistentialTraitRef<J>>,
            ExistentialProjection<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            ExistentialProjection<J>>,
            I::TraitId: ::rustc_type_ir::lift::Lift<J, Lifted = J::TraitId> {
            type Lifted = ExistentialPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        ExistentialPredicate::Trait(__binding_0) => {
                            ExistentialPredicate::Trait(__binding_0.lift_to_interner(interner)?)
                        }
                        ExistentialPredicate::Projection(__binding_0) => {
                            ExistentialPredicate::Projection(__binding_0.lift_to_interner(interner)?)
                        }
                        ExistentialPredicate::AutoTrait(__binding_0) => {
                            ExistentialPredicate::AutoTrait(__binding_0.lift_to_interner(interner)?)
                        }
                    })
            }
        }
    };Lift_Generic)]
350#[cfg_attr(
351    feature = "nightly",
352    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ExistentialPredicate<I>
            where ExistentialTraitRef<I>: ::rustc_serialize::Decodable<__D>,
            ExistentialProjection<I>: ::rustc_serialize::Decodable<__D>,
            I::TraitId: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        ExistentialPredicate::Trait(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        ExistentialPredicate::Projection(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        ExistentialPredicate::AutoTrait(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ExistentialPredicate`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for ExistentialPredicate<I>
            where ExistentialTraitRef<I>: ::rustc_serialize::Encodable<__E>,
            ExistentialProjection<I>: ::rustc_serialize::Encodable<__E>,
            I::TraitId: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        ExistentialPredicate::Trait(ref __binding_0) => { 0usize }
                        ExistentialPredicate::Projection(ref __binding_0) => {
                            1usize
                        }
                        ExistentialPredicate::AutoTrait(ref __binding_0) => {
                            2usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    ExistentialPredicate::Trait(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    ExistentialPredicate::Projection(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    ExistentialPredicate::AutoTrait(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            ExistentialPredicate<I> where
            ExistentialTraitRef<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            ExistentialProjection<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::TraitId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    ExistentialPredicate::Trait(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    ExistentialPredicate::Projection(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    ExistentialPredicate::AutoTrait(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
353)]
354pub enum ExistentialPredicate<I: Interner> {
355    /// E.g., `Iterator`.
356    Trait(ExistentialTraitRef<I>),
357    /// E.g., `Iterator::Item = T`.
358    Projection(ExistentialProjection<I>),
359    /// E.g., `Send`.
360    AutoTrait(I::TraitId),
361}
362
363impl<I: Interner> Eq for ExistentialPredicate<I> {}
364
365impl<I: Interner> ty::Binder<I, ExistentialPredicate<I>> {
366    pub fn def_id(&self) -> I::DefId {
367        match self.skip_binder() {
368            ExistentialPredicate::Trait(tr) => tr.def_id.into(),
369            ExistentialPredicate::Projection(p) => p.def_id.into(),
370            ExistentialPredicate::AutoTrait(did) => did.into(),
371        }
372    }
373    /// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`),
374    /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self`
375    /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq<u32>`, in our example).
376    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> I::Clause {
377        match self.skip_binder() {
378            ExistentialPredicate::Trait(tr) => self.rebind(tr).with_self_ty(cx, self_ty).upcast(cx),
379            ExistentialPredicate::Projection(p) => {
380                self.rebind(p.with_self_ty(cx, self_ty)).upcast(cx)
381            }
382            ExistentialPredicate::AutoTrait(did) => {
383                let generics = cx.generics_of(did.into());
384                let trait_ref = if generics.count() == 1 {
385                    ty::TraitRef::new(cx, did, [self_ty])
386                } else {
387                    // If this is an ill-formed auto trait, then synthesize
388                    // new error args for the missing generics.
389                    let err_args =
390                        GenericArgs::extend_with_error(cx, did.into(), &[self_ty.into()]);
391                    ty::TraitRef::new_from_args(cx, did, err_args)
392                };
393                self.rebind(trait_ref).upcast(cx)
394            }
395        }
396    }
397}
398
399/// An existential reference to a trait, where `Self` is erased.
400///
401/// For example, the trait object `Trait<'a, 'b, X, Y>` is:
402/// ```ignore (illustrative)
403/// exists T. T: Trait<'a, 'b, X, Y>
404/// ```
405/// The generic parameters don't include the erased `Self`, only trait
406/// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above).
407#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for ExistentialTraitRef<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (ExistentialTraitRef {
                def_id: ref __field_def_id,
                args: ref __field_args,
                _use_existential_trait_ref_new_instead: ref __field__use_existential_trait_ref_new_instead
                }, ExistentialTraitRef {
                def_id: ref __other_field_def_id,
                args: ref __other_field_args,
                _use_existential_trait_ref_new_instead: ref __other_field__use_existential_trait_ref_new_instead
                }) =>
                true &&
                            ::core::cmp::PartialEq::eq(__field_def_id,
                                __other_field_def_id) &&
                        ::core::cmp::PartialEq::eq(__field_args, __other_field_args)
                    &&
                    ::core::cmp::PartialEq::eq(__field__use_existential_trait_ref_new_instead,
                        __other_field__use_existential_trait_ref_new_instead),
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
408#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ExistentialTraitRef<I> where I: Interner,
            I::TraitId: ::rustc_type_ir::TypeVisitable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ExistentialTraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_existential_trait_ref_new_instead: ref __binding_2 } =>
                        {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            ExistentialTraitRef<I> where I: Interner,
            I::TraitId: ::rustc_type_ir::TypeFoldable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeFoldable<I> {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        ExistentialTraitRef {
                            def_id: __binding_0,
                            args: __binding_1,
                            _use_existential_trait_ref_new_instead: __binding_2 } => {
                            ExistentialTraitRef {
                                def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                _use_existential_trait_ref_new_instead: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    ExistentialTraitRef {
                        def_id: __binding_0,
                        args: __binding_1,
                        _use_existential_trait_ref_new_instead: __binding_2 } => {
                        ExistentialTraitRef {
                            def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            _use_existential_trait_ref_new_instead: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            ExistentialTraitRef<I> where I: Interner, J: Interner,
            I::TraitId: ::rustc_type_ir::lift::Lift<J, Lifted = J::TraitId>,
            I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::GenericArgs>, (): ::rustc_type_ir::lift::Lift<J, Lifted = ()> {
            type Lifted = ExistentialTraitRef<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        ExistentialTraitRef {
                            def_id: __binding_0,
                            args: __binding_1,
                            _use_existential_trait_ref_new_instead: __binding_2 } => {
                            ExistentialTraitRef {
                                def_id: __binding_0.lift_to_interner(interner)?,
                                args: __binding_1.lift_to_interner(interner)?,
                                _use_existential_trait_ref_new_instead: __binding_2.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
409#[cfg_attr(
410    feature = "nightly",
411    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ExistentialTraitRef<I> where
            I::TraitId: ::rustc_serialize::Decodable<__D>,
            I::GenericArgs: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                ExistentialTraitRef {
                    def_id: ::rustc_serialize::Decodable::decode(__decoder),
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                    _use_existential_trait_ref_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for ExistentialTraitRef<I> where
            I::TraitId: ::rustc_serialize::Encodable<__E>,
            I::GenericArgs: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    ExistentialTraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_existential_trait_ref_new_instead: ref __binding_2 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            ExistentialTraitRef<I> where
            I::TraitId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    ExistentialTraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_existential_trait_ref_new_instead: ref __binding_2 } =>
                        {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
412)]
413pub struct ExistentialTraitRef<I: Interner> {
414    pub def_id: I::TraitId,
415    pub args: I::GenericArgs,
416    /// This field exists to prevent the creation of `ExistentialTraitRef` without
417    /// calling [`ExistentialTraitRef::new_from_args`].
418    _use_existential_trait_ref_new_instead: (),
419}
420
421impl<I: Interner> Eq for ExistentialTraitRef<I> {}
422
423impl<I: Interner> ExistentialTraitRef<I> {
424    pub fn new_from_args(interner: I, trait_def_id: I::TraitId, args: I::GenericArgs) -> Self {
425        interner.debug_assert_existential_args_compatible(trait_def_id.into(), args);
426        Self { def_id: trait_def_id, args, _use_existential_trait_ref_new_instead: () }
427    }
428
429    pub fn new(
430        interner: I,
431        trait_def_id: I::TraitId,
432        args: impl IntoIterator<Item: Into<I::GenericArg>>,
433    ) -> Self {
434        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
435        Self::new_from_args(interner, trait_def_id, args)
436    }
437
438    pub fn erase_self_ty(interner: I, trait_ref: TraitRef<I>) -> ExistentialTraitRef<I> {
439        // Assert there is a Self.
440        trait_ref.args.type_at(0);
441
442        ExistentialTraitRef {
443            def_id: trait_ref.def_id,
444            args: interner.mk_args(&trait_ref.args.as_slice()[1..]),
445            _use_existential_trait_ref_new_instead: (),
446        }
447    }
448
449    /// Object types don't have a self type specified. Therefore, when
450    /// we convert the principal trait-ref into a normal trait-ref,
451    /// you must give *some* self type. A common choice is `mk_err()`
452    /// or some placeholder type.
453    pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> TraitRef<I> {
454        // otherwise the escaping vars would be captured by the binder
455        // debug_assert!(!self_ty.has_escaping_bound_vars());
456
457        TraitRef::new(interner, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter()))
458    }
459}
460
461impl<I: Interner> ty::Binder<I, ExistentialTraitRef<I>> {
462    pub fn def_id(&self) -> I::TraitId {
463        self.skip_binder().def_id
464    }
465
466    /// Object types don't have a self type specified. Therefore, when
467    /// we convert the principal trait-ref into a normal trait-ref,
468    /// you must give *some* self type. A common choice is `mk_err()`
469    /// or some placeholder type.
470    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder<I, TraitRef<I>> {
471        self.map_bound(|trait_ref| trait_ref.with_self_ty(cx, self_ty))
472    }
473}
474
475/// A `ProjectionPredicate` for an `ExistentialTraitRef`.
476#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for ExistentialProjection<I> where
    I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            ExistentialProjection {
                def_id: ref __field_def_id,
                args: ref __field_args,
                term: ref __field_term,
                use_existential_projection_new_instead: ref __field_use_existential_projection_new_instead
                } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f,
                        "ExistentialProjection");
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::field(&mut __builder, "args",
                    __field_args);
                ::core::fmt::DebugStruct::field(&mut __builder, "term",
                    __field_term);
                ::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
477#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ExistentialProjection<I> where I: Interner,
            I::DefId: ::rustc_type_ir::TypeVisitable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeVisitable<I>,
            I::Term: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ExistentialProjection {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        term: ref __binding_2,
                        use_existential_projection_new_instead: ref __binding_3 } =>
                        {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_3,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            ExistentialProjection<I> where I: Interner,
            I::DefId: ::rustc_type_ir::TypeFoldable<I>,
            I::GenericArgs: ::rustc_type_ir::TypeFoldable<I>,
            I::Term: ::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 {
                        ExistentialProjection {
                            def_id: __binding_0,
                            args: __binding_1,
                            term: __binding_2,
                            use_existential_projection_new_instead: __binding_3 } => {
                            ExistentialProjection {
                                def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                term: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                                use_existential_projection_new_instead: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_3,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    ExistentialProjection {
                        def_id: __binding_0,
                        args: __binding_1,
                        term: __binding_2,
                        use_existential_projection_new_instead: __binding_3 } => {
                        ExistentialProjection {
                            def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            term: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                            use_existential_projection_new_instead: ::rustc_type_ir::TypeFoldable::fold_with(__binding_3,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            ExistentialProjection<I> where I: Interner, J: Interner,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId>,
            I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::GenericArgs>,
            I::Term: ::rustc_type_ir::lift::Lift<J, Lifted = J::Term>,
            (): ::rustc_type_ir::lift::Lift<J, Lifted = ()> {
            type Lifted = ExistentialProjection<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        ExistentialProjection {
                            def_id: __binding_0,
                            args: __binding_1,
                            term: __binding_2,
                            use_existential_projection_new_instead: __binding_3 } => {
                            ExistentialProjection {
                                def_id: __binding_0.lift_to_interner(interner)?,
                                args: __binding_1.lift_to_interner(interner)?,
                                term: __binding_2.lift_to_interner(interner)?,
                                use_existential_projection_new_instead: __binding_3.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
478#[cfg_attr(
479    feature = "nightly",
480    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ExistentialProjection<I>
            where I::DefId: ::rustc_serialize::Decodable<__D>,
            I::GenericArgs: ::rustc_serialize::Decodable<__D>,
            I::Term: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                ExistentialProjection {
                    def_id: ::rustc_serialize::Decodable::decode(__decoder),
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                    term: ::rustc_serialize::Decodable::decode(__decoder),
                    use_existential_projection_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for ExistentialProjection<I>
            where I::DefId: ::rustc_serialize::Encodable<__E>,
            I::GenericArgs: ::rustc_serialize::Encodable<__E>,
            I::Term: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    ExistentialProjection {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        term: ref __binding_2,
                        use_existential_projection_new_instead: ref __binding_3 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_3,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            ExistentialProjection<I> where
            I::DefId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Term: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    ExistentialProjection {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        term: ref __binding_2,
                        use_existential_projection_new_instead: ref __binding_3 } =>
                        {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                        { __binding_3.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
481)]
482pub struct ExistentialProjection<I: Interner> {
483    pub def_id: I::DefId,
484    pub args: I::GenericArgs,
485    pub term: I::Term,
486
487    /// This field exists to prevent the creation of `ExistentialProjection`
488    /// without using [`ExistentialProjection::new_from_args`].
489    #[derive_where(skip(Debug))]
490    use_existential_projection_new_instead: (),
491}
492
493impl<I: Interner> Eq for ExistentialProjection<I> {}
494
495impl<I: Interner> ExistentialProjection<I> {
496    pub fn new_from_args(
497        interner: I,
498        def_id: I::DefId,
499        args: I::GenericArgs,
500        term: I::Term,
501    ) -> ExistentialProjection<I> {
502        interner.debug_assert_existential_args_compatible(def_id, args);
503        Self { def_id, args, term, use_existential_projection_new_instead: () }
504    }
505
506    pub fn new(
507        interner: I,
508        def_id: I::DefId,
509        args: impl IntoIterator<Item: Into<I::GenericArg>>,
510        term: I::Term,
511    ) -> ExistentialProjection<I> {
512        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
513        Self::new_from_args(interner, def_id, args, term)
514    }
515
516    /// Extracts the underlying existential trait reference from this projection.
517    ///
518    /// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`,
519    /// then this function would return an `exists T. T: Iterator` existential trait
520    /// reference.
521    pub fn trait_ref(&self, interner: I) -> ExistentialTraitRef<I> {
522        let def_id = interner.parent(self.def_id);
523        let args_count = interner.generics_of(def_id).count() - 1;
524        let args = interner.mk_args(&self.args.as_slice()[..args_count]);
525        ExistentialTraitRef::new_from_args(interner, def_id.try_into().unwrap(), args)
526    }
527
528    pub fn with_self_ty(&self, interner: I, self_ty: I::Ty) -> ProjectionPredicate<I> {
529        // otherwise the escaping regions would be captured by the binders
530        if true {
    if !!self_ty.has_escaping_bound_vars() {
        ::core::panicking::panic("assertion failed: !self_ty.has_escaping_bound_vars()")
    };
};debug_assert!(!self_ty.has_escaping_bound_vars());
531
532        ProjectionPredicate {
533            projection_term: AliasTerm::new(
534                interner,
535                self.def_id,
536                [self_ty.into()].iter().chain(self.args.iter()),
537            ),
538            term: self.term,
539        }
540    }
541
542    pub fn erase_self_ty(interner: I, projection_predicate: ProjectionPredicate<I>) -> Self {
543        // Assert there is a Self.
544        projection_predicate.projection_term.args.type_at(0);
545
546        Self {
547            def_id: projection_predicate.projection_term.def_id,
548            args: interner.mk_args(&projection_predicate.projection_term.args.as_slice()[1..]),
549            term: projection_predicate.term,
550            use_existential_projection_new_instead: (),
551        }
552    }
553}
554
555impl<I: Interner> ty::Binder<I, ExistentialProjection<I>> {
556    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder<I, ProjectionPredicate<I>> {
557        self.map_bound(|p| p.with_self_ty(cx, self_ty))
558    }
559
560    pub fn item_def_id(&self) -> I::DefId {
561        self.skip_binder().def_id
562    }
563}
564
565#[derive(#[automatically_derived]
impl ::core::clone::Clone for AliasTermKind {
    #[inline]
    fn clone(&self) -> AliasTermKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AliasTermKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for AliasTermKind {
    #[inline]
    fn eq(&self, other: &AliasTermKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AliasTermKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for AliasTermKind {
    #[inline]
    fn partial_cmp(&self, other: &AliasTermKind)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for AliasTermKind {
    #[inline]
    fn cmp(&self, other: &AliasTermKind) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for AliasTermKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for AliasTermKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                AliasTermKind::ProjectionTy => "ProjectionTy",
                AliasTermKind::InherentTy => "InherentTy",
                AliasTermKind::OpaqueTy => "OpaqueTy",
                AliasTermKind::FreeTy => "FreeTy",
                AliasTermKind::UnevaluatedConst => "UnevaluatedConst",
                AliasTermKind::ProjectionConst => "ProjectionConst",
                AliasTermKind::FreeConst => "FreeConst",
                AliasTermKind::InherentConst => "InherentConst",
            })
    }
}Debug)]
566#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for AliasTermKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        AliasTermKind::ProjectionTy => { 0usize }
                        AliasTermKind::InherentTy => { 1usize }
                        AliasTermKind::OpaqueTy => { 2usize }
                        AliasTermKind::FreeTy => { 3usize }
                        AliasTermKind::UnevaluatedConst => { 4usize }
                        AliasTermKind::ProjectionConst => { 5usize }
                        AliasTermKind::FreeConst => { 6usize }
                        AliasTermKind::InherentConst => { 7usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    AliasTermKind::ProjectionTy => {}
                    AliasTermKind::InherentTy => {}
                    AliasTermKind::OpaqueTy => {}
                    AliasTermKind::FreeTy => {}
                    AliasTermKind::UnevaluatedConst => {}
                    AliasTermKind::ProjectionConst => {}
                    AliasTermKind::FreeConst => {}
                    AliasTermKind::InherentConst => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for AliasTermKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { AliasTermKind::ProjectionTy }
                    1usize => { AliasTermKind::InherentTy }
                    2usize => { AliasTermKind::OpaqueTy }
                    3usize => { AliasTermKind::FreeTy }
                    4usize => { AliasTermKind::UnevaluatedConst }
                    5usize => { AliasTermKind::ProjectionConst }
                    6usize => { AliasTermKind::FreeConst }
                    7usize => { AliasTermKind::InherentConst }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AliasTermKind`, expected 0..8, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for AliasTermKind {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    AliasTermKind::ProjectionTy => {}
                    AliasTermKind::InherentTy => {}
                    AliasTermKind::OpaqueTy => {}
                    AliasTermKind::FreeTy => {}
                    AliasTermKind::UnevaluatedConst => {}
                    AliasTermKind::ProjectionConst => {}
                    AliasTermKind::FreeConst => {}
                    AliasTermKind::InherentConst => {}
                }
            }
        }
    };HashStable_NoContext))]
567pub enum AliasTermKind {
568    /// A projection `<Type as Trait>::AssocType`.
569    ///
570    /// Can get normalized away if monomorphic enough.
571    ProjectionTy,
572    /// An associated type in an inherent `impl`
573    InherentTy,
574    /// An opaque type (usually from `impl Trait` in type aliases or function return types)
575    ///
576    /// Can only be normalized away in PostAnalysis mode or its defining scope.
577    OpaqueTy,
578    /// A free type alias that actually checks its trait bounds.
579    ///
580    /// Currently only used if the type alias references opaque types.
581    /// Can always be normalized away.
582    FreeTy,
583
584    /// An unevaluated anonymous constants.
585    UnevaluatedConst,
586    /// An unevaluated const coming from an associated const.
587    ProjectionConst,
588    /// A top level const item not part of a trait or impl.
589    FreeConst,
590    /// An associated const in an inherent `impl`
591    InherentConst,
592}
593
594impl AliasTermKind {
595    pub fn descr(self) -> &'static str {
596        match self {
597            AliasTermKind::ProjectionTy => "associated type",
598            AliasTermKind::ProjectionConst => "associated const",
599            AliasTermKind::InherentTy => "inherent associated type",
600            AliasTermKind::InherentConst => "inherent associated const",
601            AliasTermKind::OpaqueTy => "opaque type",
602            AliasTermKind::FreeTy => "type alias",
603            AliasTermKind::FreeConst => "unevaluated constant",
604            AliasTermKind::UnevaluatedConst => "unevaluated constant",
605        }
606    }
607
608    pub fn is_type(self) -> bool {
609        match self {
610            AliasTermKind::ProjectionTy
611            | AliasTermKind::InherentTy
612            | AliasTermKind::OpaqueTy
613            | AliasTermKind::FreeTy => true,
614
615            AliasTermKind::UnevaluatedConst
616            | AliasTermKind::ProjectionConst
617            | AliasTermKind::InherentConst
618            | AliasTermKind::FreeConst => false,
619        }
620    }
621}
622
623impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind {
624    fn from(value: ty::AliasTyKind<I>) -> Self {
625        match value {
626            ty::Projection { .. } => AliasTermKind::ProjectionTy,
627            ty::Opaque { .. } => AliasTermKind::OpaqueTy,
628            ty::Free { .. } => AliasTermKind::FreeTy,
629            ty::Inherent { .. } => AliasTermKind::InherentTy,
630        }
631    }
632}
633
634/// Represents the unprojected term of a projection goal.
635///
636/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.
637/// * For an inherent projection, this would be `Ty::N<...>`.
638/// * For an opaque type, there is no explicit syntax.
639#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for AliasTerm<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            AliasTerm {
                args: ref __field_args,
                def_id: ref __field_def_id,
                _use_alias_term_new_instead: ref __field__use_alias_term_new_instead
                } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "AliasTerm");
                ::core::fmt::DebugStruct::field(&mut __builder, "args",
                    __field_args);
                ::core::fmt::DebugStruct::field(&mut __builder, "def_id",
                    __field_def_id);
                ::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
640#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for AliasTerm<I>
            where I: Interner,
            I::GenericArgs: ::rustc_type_ir::TypeVisitable<I>,
            I::DefId: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    AliasTerm {
                        args: ref __binding_0,
                        def_id: ref __binding_1,
                        _use_alias_term_new_instead: ref __binding_2 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for AliasTerm<I>
            where I: Interner,
            I::GenericArgs: ::rustc_type_ir::TypeFoldable<I>,
            I::DefId: ::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 {
                        AliasTerm {
                            args: __binding_0,
                            def_id: __binding_1,
                            _use_alias_term_new_instead: __binding_2 } => {
                            AliasTerm {
                                args: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                def_id: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                _use_alias_term_new_instead: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    AliasTerm {
                        args: __binding_0,
                        def_id: __binding_1,
                        _use_alias_term_new_instead: __binding_2 } => {
                        AliasTerm {
                            args: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            def_id: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            _use_alias_term_new_instead: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for AliasTerm<I>
            where I: Interner, J: Interner,
            I::GenericArgs: ::rustc_type_ir::lift::Lift<J, Lifted =
            J::GenericArgs>,
            I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId>,
            (): ::rustc_type_ir::lift::Lift<J, Lifted = ()> {
            type Lifted = AliasTerm<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        AliasTerm {
                            args: __binding_0,
                            def_id: __binding_1,
                            _use_alias_term_new_instead: __binding_2 } => {
                            AliasTerm {
                                args: __binding_0.lift_to_interner(interner)?,
                                def_id: __binding_1.lift_to_interner(interner)?,
                                _use_alias_term_new_instead: __binding_2.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
641#[cfg_attr(
642    feature = "nightly",
643    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for AliasTerm<I> where
            I::GenericArgs: ::rustc_serialize::Decodable<__D>,
            I::DefId: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                AliasTerm {
                    args: ::rustc_serialize::Decodable::decode(__decoder),
                    def_id: ::rustc_serialize::Decodable::decode(__decoder),
                    _use_alias_term_new_instead: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for AliasTerm<I> where
            I::GenericArgs: ::rustc_serialize::Encodable<__E>,
            I::DefId: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    AliasTerm {
                        args: ref __binding_0,
                        def_id: ref __binding_1,
                        _use_alias_term_new_instead: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            AliasTerm<I> where
            I::GenericArgs: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::DefId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    AliasTerm {
                        args: ref __binding_0,
                        def_id: ref __binding_1,
                        _use_alias_term_new_instead: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
644)]
645pub struct AliasTerm<I: Interner> {
646    /// The parameters of the associated or opaque item.
647    ///
648    /// For a projection, these are the generic parameters for the trait and the
649    /// GAT parameters, if there are any.
650    ///
651    /// For an inherent projection, they consist of the self type and the GAT parameters,
652    /// if there are any.
653    ///
654    /// For RPIT the generic parameters are for the generics of the function,
655    /// while for TAIT it is used for the generic parameters of the alias.
656    pub args: I::GenericArgs,
657
658    /// The `DefId` of the `TraitItem` or `ImplItem` for the associated type `N` depending on whether
659    /// this is a projection or an inherent projection or the `DefId` of the `OpaqueType` item if
660    /// this is an opaque.
661    ///
662    /// During codegen, `interner.type_of(def_id)` can be used to get the type of the
663    /// underlying type if the type is an opaque.
664    ///
665    /// Note that if this is an associated type, this is not the `DefId` of the
666    /// `TraitRef` containing this associated type, which is in `interner.associated_item(def_id).container`,
667    /// aka. `interner.parent(def_id)`.
668    pub def_id: I::DefId,
669
670    /// This field exists to prevent the creation of `AliasTerm` without using [`AliasTerm::new_from_args`].
671    #[derive_where(skip(Debug))]
672    _use_alias_term_new_instead: (),
673}
674
675impl<I: Interner> Eq for AliasTerm<I> {}
676
677impl<I: Interner> AliasTerm<I> {
678    pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm<I> {
679        interner.debug_assert_args_compatible(def_id, args);
680        AliasTerm { def_id, args, _use_alias_term_new_instead: () }
681    }
682
683    pub fn new(
684        interner: I,
685        def_id: I::DefId,
686        args: impl IntoIterator<Item: Into<I::GenericArg>>,
687    ) -> AliasTerm<I> {
688        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
689        Self::new_from_args(interner, def_id, args)
690    }
691
692    pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> {
693        let kind = match self.kind(interner) {
694            AliasTermKind::ProjectionTy => AliasTyKind::Projection { def_id: self.def_id },
695            AliasTermKind::InherentTy => AliasTyKind::Inherent { def_id: self.def_id },
696            AliasTermKind::OpaqueTy => AliasTyKind::Opaque { def_id: self.def_id },
697            AliasTermKind::FreeTy => AliasTyKind::Free { def_id: self.def_id },
698            AliasTermKind::InherentConst
699            | AliasTermKind::FreeConst
700            | AliasTermKind::UnevaluatedConst
701            | AliasTermKind::ProjectionConst => {
702                {
    ::core::panicking::panic_fmt(format_args!("Cannot turn `UnevaluatedConst` into `AliasTy`"));
}panic!("Cannot turn `UnevaluatedConst` into `AliasTy`")
703            }
704        };
705        ty::AliasTy { kind, args: self.args, _use_alias_ty_new_instead: () }
706    }
707
708    pub fn kind(self, interner: I) -> AliasTermKind {
709        interner.alias_term_kind(self)
710    }
711
712    pub fn to_term(self, interner: I) -> I::Term {
713        let alias_ty_kind = match self.kind(interner) {
714            AliasTermKind::FreeConst
715            | AliasTermKind::InherentConst
716            | AliasTermKind::UnevaluatedConst
717            | AliasTermKind::ProjectionConst => {
718                return I::Const::new_unevaluated(
719                    interner,
720                    ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args),
721                )
722                .into();
723            }
724
725            AliasTermKind::ProjectionTy => ty::Projection { def_id: self.def_id },
726            AliasTermKind::InherentTy => ty::Inherent { def_id: self.def_id },
727            AliasTermKind::OpaqueTy => ty::Opaque { def_id: self.def_id },
728            AliasTermKind::FreeTy => ty::Free { def_id: self.def_id },
729        };
730
731        Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args))
732            .into()
733    }
734}
735
736/// The following methods work only with (trait) associated term projections.
737impl<I: Interner> AliasTerm<I> {
738    pub fn self_ty(self) -> I::Ty {
739        self.args.type_at(0)
740    }
741
742    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
743        AliasTerm::new(
744            interner,
745            self.def_id,
746            [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
747        )
748    }
749
750    pub fn trait_def_id(self, interner: I) -> I::TraitId {
751        if !#[allow(non_exhaustive_omitted_patterns)] match self.kind(interner) {
            AliasTermKind::ProjectionTy | AliasTermKind::ProjectionConst =>
                true,
            _ => false,
        } {
    { ::core::panicking::panic_fmt(format_args!("expected a projection")); }
};assert!(
752            matches!(
753                self.kind(interner),
754                AliasTermKind::ProjectionTy | AliasTermKind::ProjectionConst
755            ),
756            "expected a projection"
757        );
758        interner.parent(self.def_id).try_into().unwrap()
759    }
760
761    /// Extracts the underlying trait reference and own args from this projection.
762    /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
763    /// then this function would return a `T: StreamingIterator` trait reference and
764    /// `['a]` as the own args.
765    pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
766        interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
767    }
768
769    /// Extracts the underlying trait reference from this projection.
770    /// For example, if this is a projection of `<T as Iterator>::Item`,
771    /// then this function would return a `T: Iterator` trait reference.
772    ///
773    /// WARNING: This will drop the args for generic associated types
774    /// consider calling [Self::trait_ref_and_own_args] to get those
775    /// as well.
776    pub fn trait_ref(self, interner: I) -> TraitRef<I> {
777        self.trait_ref_and_own_args(interner).0
778    }
779
780    /// Extract the own args from this projection.
781    /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
782    /// then this function would return the slice `['a]` as the own args.
783    pub fn own_args(self, interner: I) -> I::GenericArgsSlice {
784        self.trait_ref_and_own_args(interner).1
785    }
786}
787
788/// The following methods work only with inherent associated term projections.
789impl<I: Interner> AliasTerm<I> {
790    /// Transform the generic parameters to have the given `impl` args as the base and the GAT args on top of that.
791    ///
792    /// Does the following transformation:
793    ///
794    /// ```text
795    /// [Self, P_0...P_m] -> [I_0...I_n, P_0...P_m]
796    ///
797    ///     I_i impl args
798    ///     P_j GAT args
799    /// ```
800    pub fn rebase_inherent_args_onto_impl(
801        self,
802        impl_args: I::GenericArgs,
803        interner: I,
804    ) -> I::GenericArgs {
805        if true {
    if !#[allow(non_exhaustive_omitted_patterns)] match self.kind(interner) {
                AliasTermKind::InherentTy | AliasTermKind::InherentConst =>
                    true,
                _ => false,
            } {
        ::core::panicking::panic("assertion failed: matches!(self.kind(interner), AliasTermKind::InherentTy |\n    AliasTermKind::InherentConst)")
    };
};debug_assert!(matches!(
806            self.kind(interner),
807            AliasTermKind::InherentTy | AliasTermKind::InherentConst
808        ));
809        interner.mk_args_from_iter(impl_args.iter().chain(self.args.iter().skip(1)))
810    }
811}
812
813impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
814    fn from(ty: ty::AliasTy<I>) -> Self {
815        AliasTerm { args: ty.args, def_id: ty.kind.def_id(), _use_alias_term_new_instead: () }
816    }
817}
818
819impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> {
820    fn from(ct: ty::UnevaluatedConst<I>) -> Self {
821        AliasTerm { args: ct.args, def_id: ct.def.into(), _use_alias_term_new_instead: () }
822    }
823}
824
825/// This kind of predicate has no *direct* correspondent in the
826/// syntax, but it roughly corresponds to the syntactic forms:
827///
828/// 1. `T: TraitRef<..., Item = Type>`
829/// 2. `<T as TraitRef<...>>::Item == Type` (NYI)
830///
831/// In particular, form #1 is "desugared" to the combination of a
832/// normal trait predicate (`T: TraitRef<...>`) and one of these
833/// predicates. Form #2 is a broader form in that it also permits
834/// equality between arbitrary types. Processing an instance of
835/// Form #2 eventually yields one of these `ProjectionPredicate`
836/// instances to normalize the LHS.
837#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for ProjectionPredicate<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (ProjectionPredicate {
                projection_term: ref __field_projection_term,
                term: ref __field_term }, ProjectionPredicate {
                projection_term: ref __other_field_projection_term,
                term: ref __other_field_term }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_projection_term,
                            __other_field_projection_term) &&
                    ::core::cmp::PartialEq::eq(__field_term,
                        __other_field_term),
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
838#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ProjectionPredicate<I> where I: Interner,
            AliasTerm<I>: ::rustc_type_ir::TypeVisitable<I>,
            I::Term: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ProjectionPredicate {
                        projection_term: ref __binding_0, term: ref __binding_1 } =>
                        {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            ProjectionPredicate<I> where I: Interner,
            AliasTerm<I>: ::rustc_type_ir::TypeFoldable<I>,
            I::Term: ::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 {
                        ProjectionPredicate {
                            projection_term: __binding_0, term: __binding_1 } => {
                            ProjectionPredicate {
                                projection_term: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                term: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    ProjectionPredicate {
                        projection_term: __binding_0, term: __binding_1 } => {
                        ProjectionPredicate {
                            projection_term: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            term: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            ProjectionPredicate<I> where I: Interner, J: Interner,
            AliasTerm<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            AliasTerm<J>>,
            I::Term: ::rustc_type_ir::lift::Lift<J, Lifted = J::Term> {
            type Lifted = ProjectionPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        ProjectionPredicate {
                            projection_term: __binding_0, term: __binding_1 } => {
                            ProjectionPredicate {
                                projection_term: __binding_0.lift_to_interner(interner)?,
                                term: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
839#[cfg_attr(
840    feature = "nightly",
841    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ProjectionPredicate<I> where
            AliasTerm<I>: ::rustc_serialize::Decodable<__D>,
            I::Term: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                ProjectionPredicate {
                    projection_term: ::rustc_serialize::Decodable::decode(__decoder),
                    term: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for ProjectionPredicate<I> where
            AliasTerm<I>: ::rustc_serialize::Encodable<__E>,
            I::Term: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    ProjectionPredicate {
                        projection_term: ref __binding_0, term: ref __binding_1 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            ProjectionPredicate<I> where
            AliasTerm<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Term: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    ProjectionPredicate {
                        projection_term: ref __binding_0, term: ref __binding_1 } =>
                        {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
842)]
843pub struct ProjectionPredicate<I: Interner> {
844    pub projection_term: AliasTerm<I>,
845    pub term: I::Term,
846}
847
848impl<I: Interner> Eq for ProjectionPredicate<I> {}
849
850impl<I: Interner> ProjectionPredicate<I> {
851    pub fn self_ty(self) -> I::Ty {
852        self.projection_term.self_ty()
853    }
854
855    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> ProjectionPredicate<I> {
856        Self {
857            projection_term: self.projection_term.with_replaced_self_ty(interner, self_ty),
858            ..self
859        }
860    }
861
862    pub fn trait_def_id(self, interner: I) -> I::TraitId {
863        self.projection_term.trait_def_id(interner)
864    }
865
866    pub fn def_id(self) -> I::DefId {
867        self.projection_term.def_id
868    }
869}
870
871impl<I: Interner> ty::Binder<I, ProjectionPredicate<I>> {
872    /// Returns the `DefId` of the trait of the associated item being projected.
873    #[inline]
874    pub fn trait_def_id(&self, cx: I) -> I::TraitId {
875        self.skip_binder().projection_term.trait_def_id(cx)
876    }
877
878    pub fn term(&self) -> ty::Binder<I, I::Term> {
879        self.map_bound(|predicate| predicate.term)
880    }
881
882    /// The `DefId` of the `TraitItem` for the associated type.
883    ///
884    /// Note that this is not the `DefId` of the `TraitRef` containing this
885    /// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
886    pub fn item_def_id(&self) -> I::DefId {
887        // Ok to skip binder since trait `DefId` does not care about regions.
888        self.skip_binder().projection_term.def_id
889    }
890}
891
892impl<I: Interner> fmt::Debug for ProjectionPredicate<I> {
893    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
894        f.write_fmt(format_args!("ProjectionPredicate({0:?}, {1:?})",
        self.projection_term, self.term))write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_term, self.term)
895    }
896}
897
898/// Used by the new solver to normalize an alias. This always expects the `term` to
899/// be an unconstrained inference variable which is used as the output.
900#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for NormalizesTo<I> where I: Interner
    {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (NormalizesTo { alias: ref __field_alias, term: ref __field_term
                }, NormalizesTo {
                alias: ref __other_field_alias, term: ref __other_field_term
                }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_alias,
                            __other_field_alias) &&
                    ::core::cmp::PartialEq::eq(__field_term,
                        __other_field_term),
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
901#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            NormalizesTo<I> where I: Interner,
            AliasTerm<I>: ::rustc_type_ir::TypeVisitable<I>,
            I::Term: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    NormalizesTo { alias: ref __binding_0, term: ref __binding_1
                        } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for NormalizesTo<I>
            where I: Interner, AliasTerm<I>: ::rustc_type_ir::TypeFoldable<I>,
            I::Term: ::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 {
                        NormalizesTo { alias: __binding_0, term: __binding_1 } => {
                            NormalizesTo {
                                alias: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                term: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    NormalizesTo { alias: __binding_0, term: __binding_1 } => {
                        NormalizesTo {
                            alias: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            term: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            NormalizesTo<I> where I: Interner, J: Interner,
            AliasTerm<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            AliasTerm<J>>,
            I::Term: ::rustc_type_ir::lift::Lift<J, Lifted = J::Term> {
            type Lifted = NormalizesTo<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        NormalizesTo { alias: __binding_0, term: __binding_1 } => {
                            NormalizesTo {
                                alias: __binding_0.lift_to_interner(interner)?,
                                term: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
902#[cfg_attr(
903    feature = "nightly",
904    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for NormalizesTo<I> where
            AliasTerm<I>: ::rustc_serialize::Decodable<__D>,
            I::Term: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                NormalizesTo {
                    alias: ::rustc_serialize::Decodable::decode(__decoder),
                    term: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for NormalizesTo<I> where
            AliasTerm<I>: ::rustc_serialize::Encodable<__E>,
            I::Term: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    NormalizesTo { alias: ref __binding_0, term: ref __binding_1
                        } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            NormalizesTo<I> where
            AliasTerm<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
            I::Term: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    NormalizesTo { alias: ref __binding_0, term: ref __binding_1
                        } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
905)]
906pub struct NormalizesTo<I: Interner> {
907    pub alias: AliasTerm<I>,
908    pub term: I::Term,
909}
910
911impl<I: Interner> Eq for NormalizesTo<I> {}
912
913impl<I: Interner> NormalizesTo<I> {
914    pub fn self_ty(self) -> I::Ty {
915        self.alias.self_ty()
916    }
917
918    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> NormalizesTo<I> {
919        Self { alias: self.alias.with_replaced_self_ty(interner, self_ty), ..self }
920    }
921
922    pub fn trait_def_id(self, interner: I) -> I::TraitId {
923        self.alias.trait_def_id(interner)
924    }
925
926    pub fn def_id(self) -> I::DefId {
927        self.alias.def_id
928    }
929}
930
931impl<I: Interner> fmt::Debug for NormalizesTo<I> {
932    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
933        f.write_fmt(format_args!("NormalizesTo({0:?}, {1:?})", self.alias, self.term))write!(f, "NormalizesTo({:?}, {:?})", self.alias, self.term)
934    }
935}
936
937#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for HostEffectPredicate<I> where
    I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            HostEffectPredicate {
                trait_ref: ref __field_trait_ref,
                constness: ref __field_constness } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f,
                        "HostEffectPredicate");
                ::core::fmt::DebugStruct::field(&mut __builder, "trait_ref",
                    __field_trait_ref);
                ::core::fmt::DebugStruct::field(&mut __builder, "constness",
                    __field_constness);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
938#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            HostEffectPredicate<I> where I: Interner,
            ty::TraitRef<I>: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    HostEffectPredicate {
                        trait_ref: ref __binding_0, constness: ref __binding_1 } =>
                        {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            HostEffectPredicate<I> where I: Interner,
            ty::TraitRef<I>: ::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 {
                        HostEffectPredicate {
                            trait_ref: __binding_0, constness: __binding_1 } => {
                            HostEffectPredicate {
                                trait_ref: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                constness: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    HostEffectPredicate {
                        trait_ref: __binding_0, constness: __binding_1 } => {
                        HostEffectPredicate {
                            trait_ref: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            constness: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            HostEffectPredicate<I> where I: Interner, J: Interner,
            ty::TraitRef<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
            ty::TraitRef<J>>,
            BoundConstness: ::rustc_type_ir::lift::Lift<J, Lifted =
            BoundConstness> {
            type Lifted = HostEffectPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        HostEffectPredicate {
                            trait_ref: __binding_0, constness: __binding_1 } => {
                            HostEffectPredicate {
                                trait_ref: __binding_0.lift_to_interner(interner)?,
                                constness: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
939#[cfg_attr(
940    feature = "nightly",
941    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for HostEffectPredicate<I> where
            ty::TraitRef<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    HostEffectPredicate {
                        trait_ref: ref __binding_0, constness: ref __binding_1 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for HostEffectPredicate<I> where
            ty::TraitRef<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                HostEffectPredicate {
                    trait_ref: ::rustc_serialize::Decodable::decode(__decoder),
                    constness: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            HostEffectPredicate<I> where
            ty::TraitRef<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    HostEffectPredicate {
                        trait_ref: ref __binding_0, constness: ref __binding_1 } =>
                        {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
942)]
943pub struct HostEffectPredicate<I: Interner> {
944    pub trait_ref: ty::TraitRef<I>,
945    pub constness: BoundConstness,
946}
947
948impl<I: Interner> Eq for HostEffectPredicate<I> {}
949
950impl<I: Interner> HostEffectPredicate<I> {
951    pub fn self_ty(self) -> I::Ty {
952        self.trait_ref.self_ty()
953    }
954
955    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
956        Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), ..self }
957    }
958
959    pub fn def_id(self) -> I::TraitId {
960        self.trait_ref.def_id
961    }
962}
963
964impl<I: Interner> ty::Binder<I, HostEffectPredicate<I>> {
965    pub fn def_id(self) -> I::TraitId {
966        // Ok to skip binder since trait `DefId` does not care about regions.
967        self.skip_binder().def_id()
968    }
969
970    pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
971        self.map_bound(|trait_ref| trait_ref.self_ty())
972    }
973
974    #[inline]
975    pub fn constness(self) -> BoundConstness {
976        self.skip_binder().constness
977    }
978}
979
980/// Encodes that `a` must be a subtype of `b`. The `a_is_expected` flag indicates
981/// whether the `a` type is the type that we should label as "expected" when
982/// presenting user diagnostics.
983#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for SubtypePredicate<I> where I: Interner
    {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            SubtypePredicate {
                a_is_expected: ref __field_a_is_expected,
                a: ref __field_a,
                b: ref __field_b } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f,
                        "SubtypePredicate");
                ::core::fmt::DebugStruct::field(&mut __builder,
                    "a_is_expected", __field_a_is_expected);
                ::core::fmt::DebugStruct::field(&mut __builder, "a",
                    __field_a);
                ::core::fmt::DebugStruct::field(&mut __builder, "b",
                    __field_b);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
984#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            SubtypePredicate<I> where I: Interner,
            I::Ty: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    SubtypePredicate {
                        a_is_expected: ref __binding_0,
                        a: ref __binding_1,
                        b: ref __binding_2 } => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            SubtypePredicate<I> where I: Interner,
            I::Ty: ::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 {
                        SubtypePredicate {
                            a_is_expected: __binding_0, a: __binding_1, b: __binding_2 }
                            => {
                            SubtypePredicate {
                                a_is_expected: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                a: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                b: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    SubtypePredicate {
                        a_is_expected: __binding_0, a: __binding_1, b: __binding_2 }
                        => {
                        SubtypePredicate {
                            a_is_expected: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            a: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            b: ::rustc_type_ir::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            SubtypePredicate<I> where I: Interner, J: Interner,
            bool: ::rustc_type_ir::lift::Lift<J, Lifted = bool>,
            I::Ty: ::rustc_type_ir::lift::Lift<J, Lifted = J::Ty>,
            I::Ty: ::rustc_type_ir::lift::Lift<J, Lifted = J::Ty> {
            type Lifted = SubtypePredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        SubtypePredicate {
                            a_is_expected: __binding_0, a: __binding_1, b: __binding_2 }
                            => {
                            SubtypePredicate {
                                a_is_expected: __binding_0.lift_to_interner(interner)?,
                                a: __binding_1.lift_to_interner(interner)?,
                                b: __binding_2.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
985#[cfg_attr(
986    feature = "nightly",
987    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for SubtypePredicate<I> where
            I::Ty: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                SubtypePredicate {
                    a_is_expected: ::rustc_serialize::Decodable::decode(__decoder),
                    a: ::rustc_serialize::Decodable::decode(__decoder),
                    b: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for SubtypePredicate<I> where
            I::Ty: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    SubtypePredicate {
                        a_is_expected: ref __binding_0,
                        a: ref __binding_1,
                        b: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            SubtypePredicate<I> where
            I::Ty: ::rustc_data_structures::stable_hasher::HashStable<__CTX> {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    SubtypePredicate {
                        a_is_expected: ref __binding_0,
                        a: ref __binding_1,
                        b: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
988)]
989pub struct SubtypePredicate<I: Interner> {
990    pub a_is_expected: bool,
991    pub a: I::Ty,
992    pub b: I::Ty,
993}
994
995impl<I: Interner> Eq for SubtypePredicate<I> {}
996
997/// Encodes that we have to coerce *from* the `a` type to the `b` type.
998#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for CoercePredicate<I> where I: Interner
    {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            CoercePredicate { a: ref __field_a, b: ref __field_b } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f,
                        "CoercePredicate");
                ::core::fmt::DebugStruct::field(&mut __builder, "a",
                    __field_a);
                ::core::fmt::DebugStruct::field(&mut __builder, "b",
                    __field_b);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
999#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            CoercePredicate<I> where I: Interner,
            I::Ty: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    CoercePredicate { a: ref __binding_0, b: ref __binding_1 }
                        => {
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_type_ir::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, GenericTypeVisitable, const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeFoldable<I> for
            CoercePredicate<I> where I: Interner,
            I::Ty: ::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 {
                        CoercePredicate { a: __binding_0, b: __binding_1 } => {
                            CoercePredicate {
                                a: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                b: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    CoercePredicate { a: __binding_0, b: __binding_1 } => {
                        CoercePredicate {
                            a: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            b: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            CoercePredicate<I> where I: Interner, J: Interner,
            I::Ty: ::rustc_type_ir::lift::Lift<J, Lifted = J::Ty>,
            I::Ty: ::rustc_type_ir::lift::Lift<J, Lifted = J::Ty> {
            type Lifted = CoercePredicate<J>;
            fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
                Some(match self {
                        CoercePredicate { a: __binding_0, b: __binding_1 } => {
                            CoercePredicate {
                                a: __binding_0.lift_to_interner(interner)?,
                                b: __binding_1.lift_to_interner(interner)?,
                            }
                        }
                    })
            }
        }
    };Lift_Generic)]
1000#[cfg_attr(
1001    feature = "nightly",
1002    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for CoercePredicate<I> where
            I::Ty: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                CoercePredicate {
                    a: ::rustc_serialize::Decodable::decode(__decoder),
                    b: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for CoercePredicate<I> where
            I::Ty: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    CoercePredicate { a: ref __binding_0, b: ref __binding_1 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            CoercePredicate<I> where
            I::Ty: ::rustc_data_structures::stable_hasher::HashStable<__CTX> {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    CoercePredicate { a: ref __binding_0, b: ref __binding_1 }
                        => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_NoContext)
1003)]
1004pub struct CoercePredicate<I: Interner> {
1005    pub a: I::Ty,
1006    pub b: I::Ty,
1007}
1008
1009impl<I: Interner> Eq for CoercePredicate<I> {}
1010
1011#[derive(#[automatically_derived]
impl ::core::clone::Clone for BoundConstness {
    #[inline]
    fn clone(&self) -> BoundConstness { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for BoundConstness { }Copy, #[automatically_derived]
impl ::core::hash::Hash for BoundConstness {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::cmp::PartialEq for BoundConstness {
    #[inline]
    fn eq(&self, other: &BoundConstness) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for BoundConstness {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for BoundConstness {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                BoundConstness::Const => "Const",
                BoundConstness::Maybe => "Maybe",
            })
    }
}Debug)]
1012#[cfg_attr(
1013    feature = "nightly",
1014    derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundConstness {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        BoundConstness::Const => { 0usize }
                        BoundConstness::Maybe => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    BoundConstness::Const => {}
                    BoundConstness::Maybe => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundConstness {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { BoundConstness::Const }
                    1usize => { BoundConstness::Maybe }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `BoundConstness`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for BoundConstness {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    BoundConstness::Const => {}
                    BoundConstness::Maybe => {}
                }
            }
        }
    };HashStable_NoContext)
1015)]
1016pub enum BoundConstness {
1017    /// `Type: const Trait`
1018    ///
1019    /// A bound is required to be unconditionally const, even in a runtime function.
1020    Const,
1021    /// `Type: [const] Trait`
1022    ///
1023    /// Requires resolving to const only when we are in a const context.
1024    Maybe,
1025}
1026
1027impl BoundConstness {
1028    pub fn satisfies(self, goal: BoundConstness) -> bool {
1029        match (self, goal) {
1030            (BoundConstness::Const, BoundConstness::Const | BoundConstness::Maybe) => true,
1031            (BoundConstness::Maybe, BoundConstness::Maybe) => true,
1032            (BoundConstness::Maybe, BoundConstness::Const) => false,
1033        }
1034    }
1035
1036    pub fn as_str(self) -> &'static str {
1037        match self {
1038            Self::Const => "const",
1039            Self::Maybe => "[const]",
1040        }
1041    }
1042}
1043
1044impl fmt::Display for BoundConstness {
1045    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1046        match self {
1047            Self::Const => f.write_str("const"),
1048            Self::Maybe => f.write_str("[const]"),
1049        }
1050    }
1051}