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::{Decodable_NoContext, Encodable_NoContext, StableHash, StableHash_NoContext};
7use rustc_type_ir_macros::{
8    GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
9};
10
11use crate::inherent::*;
12use crate::upcast::{Upcast, UpcastFrom};
13use crate::visit::TypeVisitableExt as _;
14use crate::{self as ty, Alias, Interner};
15
16/// `A: 'region`
17#[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)]
18#[derive_where(Copy; I: Interner, A: Copy)]
19#[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>,
            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, const _: () =
    {
        impl<I: Interner, A, J> ::rustc_type_ir::lift::Lift<J> for
            OutlivesPredicate<I, A> where J: Interner,
            I: ::rustc_type_ir::LiftInto<J>, A: ::rustc_type_ir::lift::Lift<J>
            {
            type Lifted =
                OutlivesPredicate<J,
                <A as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    OutlivesPredicate(__binding_0, __binding_1) => {
                        OutlivesPredicate(__binding_0.lift_to_interner(interner),
                            __binding_1.lift_to_interner(interner))
                    }
                }
            }
        }
    };Lift_Generic)]
20#[cfg_attr(
21    feature = "nightly",
22    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> ::rustc_data_structures::stable_hash::StableHash
            for OutlivesPredicate<I, A> where
            A: ::rustc_data_structures::stable_hash::StableHash,
            I::Region: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    OutlivesPredicate(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
23)]
24pub struct OutlivesPredicate<I: Interner, A>(pub A, pub I::Region);
25
26impl<I: Interner, A: Eq> Eq for OutlivesPredicate<I, A> {}
27
28/// `'a == 'b`.
29/// For the rationale behind having this instead of a pair of bidirectional
30/// `'a: 'b` and `'b: 'a`, see
31/// [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).
32#[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)]
33#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = RegionEqPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    RegionEqPredicate(__binding_0, __binding_1) => {
                        RegionEqPredicate(__binding_0.lift_to_interner(interner),
                            __binding_1.lift_to_interner(interner))
                    }
                }
            }
        }
    };Lift_Generic)]
34#[cfg_attr(
35    feature = "nightly",
36    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> ::rustc_data_structures::stable_hash::StableHash for
            RegionEqPredicate<I> where
            I::Region: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    RegionEqPredicate(ref __binding_0, ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
37)]
38pub struct RegionEqPredicate<I: Interner>(pub I::Region, pub I::Region);
39
40impl<I: Interner> RegionEqPredicate<I> {
41    /// Decompose `'a == 'b` into `['a: 'b, 'b: 'a]`
42    pub fn into_bidirectional_outlives(self) -> [OutlivesPredicate<I, I::GenericArg>; 2] {
43        [OutlivesPredicate(self.0.into(), self.1), OutlivesPredicate(self.1.into(), self.0)]
44    }
45}
46
47#[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)]
48#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = RegionConstraint<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
49#[cfg_attr(
50    feature = "nightly",
51    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> ::rustc_data_structures::stable_hash::StableHash for
            RegionConstraint<I> where
            OutlivesPredicate<I,
            I::GenericArg>: ::rustc_data_structures::stable_hash::StableHash,
            RegionEqPredicate<I>: ::rustc_data_structures::stable_hash::StableHash
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    RegionConstraint::Outlives(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    RegionConstraint::Eq(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
52)]
53pub enum RegionConstraint<I: Interner> {
54    Outlives(OutlivesPredicate<I, I::GenericArg>),
55    Eq(RegionEqPredicate<I>),
56}
57
58impl<I: Interner> From<OutlivesPredicate<I, I::GenericArg>> for RegionConstraint<I> {
59    fn from(value: OutlivesPredicate<I, I::GenericArg>) -> Self {
60        RegionConstraint::Outlives(value)
61    }
62}
63
64impl<I: Interner> From<RegionEqPredicate<I>> for RegionConstraint<I> {
65    fn from(value: RegionEqPredicate<I>) -> Self {
66        RegionConstraint::Eq(value)
67    }
68}
69
70impl<I: Interner> RegionConstraint<I> {
71    /// Whether the given constraint is either `'a: 'a` or `'a == 'a`.
72    pub fn is_trivial(self) -> bool {
73        match self {
74            RegionConstraint::Outlives(outlives) => {
75                outlives.0.as_region().is_some_and(|re| re == outlives.1)
76            }
77            RegionConstraint::Eq(eq) => eq.0 == eq.1,
78        }
79    }
80
81    /// If `self` is an eq constraint, iterate through its decomposed bidirectional outlives
82    /// bounds and if not, just iterate once for the outlives bound itself.
83    pub fn iter_outlives(self) -> impl Iterator<Item = OutlivesPredicate<I, I::GenericArg>> {
84        match self {
85            RegionConstraint::Outlives(outlives) => iter::once(outlives).chain(None),
86            RegionConstraint::Eq(eq) => {
87                let [outlives1, outlives2] = eq.into_bidirectional_outlives();
88                iter::once(outlives1).chain(Some(outlives2))
89            }
90        }
91    }
92}
93
94/// A complete reference to a trait.
95///
96/// These take numerous guises in syntax,
97/// but perhaps the most recognizable form is in a where-clause:
98/// ```ignore (illustrative)
99/// T: Foo<U>
100/// ```
101/// This would be represented by a trait-reference where the `DefId` is the
102/// `DefId` for the trait `Foo` and the args define `T` as parameter 0,
103/// and `U` as parameter 1.
104///
105/// Trait references also appear in object types like `Foo<U>`, but in
106/// that case the `Self` parameter is absent from the generic parameters.
107#[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)]
108#[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 J: Interner, I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = TraitRef<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
109#[cfg_attr(
110    feature = "nightly",
111    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> ::rustc_data_structures::stable_hash::StableHash for
            TraitRef<I> where
            I::TraitId: ::rustc_data_structures::stable_hash::StableHash,
            I::GenericArgs: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    TraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_trait_ref_new_instead: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
112)]
113pub struct TraitRef<I: Interner> {
114    pub def_id: I::TraitId,
115    pub args: I::GenericArgs,
116    /// This field exists to prevent the creation of `TraitRef` without
117    /// calling [`TraitRef::new_from_args`].
118    _use_trait_ref_new_instead: (),
119}
120
121impl<I: Interner> Eq for TraitRef<I> {}
122
123impl<I: Interner> TraitRef<I> {
124    pub fn new_from_args(interner: I, trait_def_id: I::TraitId, args: I::GenericArgs) -> Self {
125        interner.debug_assert_args_compatible(trait_def_id.into(), args);
126        Self { def_id: trait_def_id, args, _use_trait_ref_new_instead: () }
127    }
128
129    pub fn new(
130        interner: I,
131        trait_def_id: I::TraitId,
132        args: impl IntoIterator<Item: Into<I::GenericArg>>,
133    ) -> Self {
134        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
135        Self::new_from_args(interner, trait_def_id, args)
136    }
137
138    pub fn from_assoc(interner: I, trait_id: I::TraitId, args: I::GenericArgs) -> TraitRef<I> {
139        let generics = interner.generics_of(trait_id.into());
140        TraitRef::new(interner, trait_id, args.iter().take(generics.count()))
141    }
142
143    /// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
144    /// are the parameters defined on trait.
145    pub fn identity(interner: I, def_id: I::TraitId) -> TraitRef<I> {
146        TraitRef::new_from_args(
147            interner,
148            def_id,
149            I::GenericArgs::identity_for_item(interner, def_id.into()),
150        )
151    }
152
153    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
154        TraitRef::new(
155            interner,
156            self.def_id,
157            [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
158        )
159    }
160
161    #[inline]
162    pub fn self_ty(&self) -> I::Ty {
163        self.args.type_at(0)
164    }
165}
166
167impl<I: Interner> ty::Binder<I, TraitRef<I>> {
168    pub fn self_ty(&self) -> ty::Binder<I, I::Ty> {
169        self.map_bound_ref(|tr| tr.self_ty())
170    }
171
172    pub fn def_id(&self) -> I::TraitId {
173        self.skip_binder().def_id
174    }
175
176    pub fn to_host_effect_clause(self, cx: I, constness: BoundConstness) -> I::Clause {
177        self.map_bound(|trait_ref| {
178            ty::ClauseKind::HostEffect(HostEffectPredicate { trait_ref, constness })
179        })
180        .upcast(cx)
181    }
182}
183
184#[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)]
185#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = TraitPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    TraitPredicate {
                        trait_ref: __binding_0, polarity: __binding_1 } => {
                        TraitPredicate {
                            trait_ref: __binding_0.lift_to_interner(interner),
                            polarity: __binding_1,
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
186#[cfg_attr(
187    feature = "nightly",
188    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> ::rustc_data_structures::stable_hash::StableHash for
            TraitPredicate<I> where
            TraitRef<I>: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    TraitPredicate {
                        trait_ref: ref __binding_0, polarity: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
189)]
190pub struct TraitPredicate<I: Interner> {
191    pub trait_ref: TraitRef<I>,
192
193    /// If polarity is Positive: we are proving that the trait is implemented.
194    ///
195    /// If polarity is Negative: we are proving that a negative impl of this trait
196    /// exists. (Note that coherence also checks whether negative impls of supertraits
197    /// exist via a series of predicates.)
198    #[lift(identity)]
199    pub polarity: PredicatePolarity,
200}
201
202impl<I: Interner> Eq for TraitPredicate<I> {}
203
204impl<I: Interner> TraitPredicate<I> {
205    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
206        Self {
207            trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty),
208            polarity: self.polarity,
209        }
210    }
211
212    pub fn def_id(self) -> I::TraitId {
213        self.trait_ref.def_id
214    }
215
216    pub fn self_ty(self) -> I::Ty {
217        self.trait_ref.self_ty()
218    }
219}
220
221impl<I: Interner> ty::Binder<I, TraitPredicate<I>> {
222    pub fn def_id(self) -> I::TraitId {
223        // Ok to skip binder since trait `DefId` does not care about regions.
224        self.skip_binder().def_id()
225    }
226
227    pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
228        self.map_bound(|trait_ref| trait_ref.self_ty())
229    }
230
231    #[inline]
232    pub fn polarity(self) -> PredicatePolarity {
233        self.skip_binder().polarity
234    }
235}
236
237impl<I: Interner> UpcastFrom<I, TraitRef<I>> for TraitPredicate<I> {
238    fn upcast_from(from: TraitRef<I>, _tcx: I) -> Self {
239        TraitPredicate { trait_ref: from, polarity: PredicatePolarity::Positive }
240    }
241}
242
243impl<I: Interner> UpcastFrom<I, ty::Binder<I, TraitRef<I>>> for ty::Binder<I, TraitPredicate<I>> {
244    fn upcast_from(from: ty::Binder<I, TraitRef<I>>, _tcx: I) -> Self {
245        from.map_bound(|trait_ref| TraitPredicate {
246            trait_ref,
247            polarity: PredicatePolarity::Positive,
248        })
249    }
250}
251
252impl<I: Interner> fmt::Debug for TraitPredicate<I> {
253    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
254        f.write_fmt(format_args!("TraitPredicate({0:?}, polarity:{1:?})",
        self.trait_ref, self.polarity))write!(f, "TraitPredicate({:?}, polarity:{:?})", self.trait_ref, self.polarity)
255    }
256}
257
258#[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> {
        ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
    }
}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)]
259#[cfg_attr(feature = "nightly", 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 ::rustc_data_structures::stable_hash::StableHash for ImplPolarity
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    ImplPolarity::Positive => {}
                    ImplPolarity::Negative => {}
                    ImplPolarity::Reservation => {}
                }
            }
        }
    };StableHash))]
260pub enum ImplPolarity {
261    /// `impl Trait for Type`
262    Positive,
263    /// `impl !Trait for Type`
264    Negative,
265    /// `#[rustc_reservation_impl] impl Trait for Type`
266    ///
267    /// This is a "stability hack", not a real Rust feature.
268    /// See #64631 for details.
269    Reservation,
270}
271
272impl fmt::Display for ImplPolarity {
273    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
274        match self {
275            Self::Positive => f.write_str("positive"),
276            Self::Negative => f.write_str("negative"),
277            Self::Reservation => f.write_str("reservation"),
278        }
279    }
280}
281
282impl ImplPolarity {
283    /// The polarity marker in front of the impl trait ref if applicable.
284    pub fn as_str(self) -> &'static str {
285        match self {
286            Self::Positive => "",
287            Self::Negative => "!",
288            Self::Reservation => "",
289        }
290    }
291}
292
293/// Polarity for a trait predicate.
294///
295/// May either be negative or positive.
296/// Distinguished from [`ImplPolarity`] since we never compute goals with
297/// "reservation" level.
298#[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> {
        ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
    }
}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)]
299#[cfg_attr(feature = "nightly", 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 ::rustc_data_structures::stable_hash::StableHash for
            PredicatePolarity {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    PredicatePolarity::Positive => {}
                    PredicatePolarity::Negative => {}
                }
            }
        }
    };StableHash))]
300pub enum PredicatePolarity {
301    /// `Type: Trait`
302    Positive,
303    /// `Type: !Trait`
304    Negative,
305}
306
307impl PredicatePolarity {
308    /// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
309    pub fn flip(&self) -> PredicatePolarity {
310        match self {
311            PredicatePolarity::Positive => PredicatePolarity::Negative,
312            PredicatePolarity::Negative => PredicatePolarity::Positive,
313        }
314    }
315}
316
317impl fmt::Display for PredicatePolarity {
318    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
319        match self {
320            Self::Positive => f.write_str("positive"),
321            Self::Negative => f.write_str("negative"),
322        }
323    }
324}
325
326#[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)]
327#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = ExistentialPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
328#[cfg_attr(
329    feature = "nightly",
330    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> ::rustc_data_structures::stable_hash::StableHash for
            ExistentialPredicate<I> where
            ExistentialTraitRef<I>: ::rustc_data_structures::stable_hash::StableHash,
            ExistentialProjection<I>: ::rustc_data_structures::stable_hash::StableHash,
            I::TraitId: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    ExistentialPredicate::Trait(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    ExistentialPredicate::Projection(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    ExistentialPredicate::AutoTrait(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
331)]
332pub enum ExistentialPredicate<I: Interner> {
333    /// E.g., `Iterator`.
334    Trait(ExistentialTraitRef<I>),
335    /// E.g., `Iterator::Item = T`.
336    Projection(ExistentialProjection<I>),
337    /// E.g., `Send`.
338    AutoTrait(I::TraitId),
339}
340
341impl<I: Interner> Eq for ExistentialPredicate<I> {}
342
343impl<I: Interner> ty::Binder<I, ExistentialPredicate<I>> {
344    pub fn def_id(&self) -> I::DefId {
345        match self.skip_binder() {
346            ExistentialPredicate::Trait(tr) => tr.def_id.into(),
347            ExistentialPredicate::Projection(p) => p.def_id.into(),
348            ExistentialPredicate::AutoTrait(did) => did.into(),
349        }
350    }
351    /// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`),
352    /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self`
353    /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq<u32>`, in our example).
354    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> I::Clause {
355        match self.skip_binder() {
356            ExistentialPredicate::Trait(tr) => self.rebind(tr).with_self_ty(cx, self_ty).upcast(cx),
357            ExistentialPredicate::Projection(p) => {
358                self.rebind(p.with_self_ty(cx, self_ty)).upcast(cx)
359            }
360            ExistentialPredicate::AutoTrait(did) => {
361                let generics = cx.generics_of(did.into());
362                let trait_ref = if generics.count() == 1 {
363                    ty::TraitRef::new(cx, did, [self_ty])
364                } else {
365                    // If this is an ill-formed auto trait, then synthesize
366                    // new error args for the missing generics.
367                    let err_args =
368                        GenericArgs::extend_with_error(cx, did.into(), &[self_ty.into()]);
369                    ty::TraitRef::new_from_args(cx, did, err_args)
370                };
371                self.rebind(trait_ref).upcast(cx)
372            }
373        }
374    }
375}
376
377/// An existential reference to a trait where the self type `Self` is erased.
378///
379/// For example, the trait object type `Trait<'a, T, N>` can be understood as:
380/// ```ignore (illustrative)
381/// exists<X> X: Trait<'a, T, N>
382/// ```
383/// The generic arguments don't include the erased self type (so it's only `['a, T, N]`).
384#[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)]
385#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = ExistentialTraitRef<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
386#[cfg_attr(
387    feature = "nightly",
388    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> ::rustc_data_structures::stable_hash::StableHash for
            ExistentialTraitRef<I> where
            I::TraitId: ::rustc_data_structures::stable_hash::StableHash,
            I::GenericArgs: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ExistentialTraitRef {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        _use_existential_trait_ref_new_instead: ref __binding_2 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
389)]
390pub struct ExistentialTraitRef<I: Interner> {
391    pub def_id: I::TraitId,
392    pub args: I::GenericArgs,
393    /// This field exists to prevent the creation of `ExistentialTraitRef` without
394    /// calling [`ExistentialTraitRef::new_from_args`].
395    _use_existential_trait_ref_new_instead: (),
396}
397
398impl<I: Interner> Eq for ExistentialTraitRef<I> {}
399
400impl<I: Interner> ExistentialTraitRef<I> {
401    pub fn new_from_args(interner: I, trait_def_id: I::TraitId, args: I::GenericArgs) -> Self {
402        interner.debug_assert_existential_args_compatible(trait_def_id.into(), args);
403        Self { def_id: trait_def_id, args, _use_existential_trait_ref_new_instead: () }
404    }
405
406    pub fn new(
407        interner: I,
408        trait_def_id: I::TraitId,
409        args: impl IntoIterator<Item: Into<I::GenericArg>>,
410    ) -> Self {
411        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
412        Self::new_from_args(interner, trait_def_id, args)
413    }
414
415    pub fn erase_self_ty(interner: I, trait_ref: TraitRef<I>) -> ExistentialTraitRef<I> {
416        // Assert there is a Self.
417        trait_ref.args.type_at(0);
418
419        ExistentialTraitRef {
420            def_id: trait_ref.def_id,
421            args: interner.mk_args(&trait_ref.args.as_slice()[1..]),
422            _use_existential_trait_ref_new_instead: (),
423        }
424    }
425
426    /// Convert the *existential* trait ref into a normal one by providing a self type.
427    ///
428    /// Existential trait refs don't contain a self type, it's erased.
429    /// Therefore, you must specify *some* self type to perform the conversion.
430    /// A common choice is the trait object type itself or some kind of dummy type.
431    pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> TraitRef<I> {
432        TraitRef::new(interner, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter()))
433    }
434}
435
436impl<I: Interner> ty::Binder<I, ExistentialTraitRef<I>> {
437    pub fn def_id(&self) -> I::TraitId {
438        self.skip_binder().def_id
439    }
440
441    /// Convert the *existential* polymorphic trait ref into a normal one by providing a self type.
442    ///
443    /// See also [`ExistentialTraitRef::with_self_ty`].
444    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder<I, TraitRef<I>> {
445        self.map_bound(|trait_ref| trait_ref.with_self_ty(cx, self_ty))
446    }
447}
448
449/// A `ProjectionPredicate` for an `ExistentialTraitRef`.
450#[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)]
451#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ExistentialProjection<I> where I: Interner,
            I::TraitAssocTermId: ::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::TraitAssocTermId: ::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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = ExistentialProjection<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
452#[cfg_attr(
453    feature = "nightly",
454    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ExistentialProjection<I>
            where I::TraitAssocTermId: ::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::TraitAssocTermId: ::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> ::rustc_data_structures::stable_hash::StableHash for
            ExistentialProjection<I> where
            I::TraitAssocTermId: ::rustc_data_structures::stable_hash::StableHash,
            I::GenericArgs: ::rustc_data_structures::stable_hash::StableHash,
            I::Term: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ExistentialProjection {
                        def_id: ref __binding_0,
                        args: ref __binding_1,
                        term: ref __binding_2,
                        use_existential_projection_new_instead: ref __binding_3 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
455)]
456pub struct ExistentialProjection<I: Interner> {
457    pub def_id: I::TraitAssocTermId,
458    pub args: I::GenericArgs,
459    pub term: I::Term,
460
461    /// This field exists to prevent the creation of `ExistentialProjection`
462    /// without using [`ExistentialProjection::new_from_args`].
463    #[derive_where(skip(Debug))]
464    use_existential_projection_new_instead: (),
465}
466
467impl<I: Interner> Eq for ExistentialProjection<I> {}
468
469impl<I: Interner> ExistentialProjection<I> {
470    pub fn new_from_args(
471        interner: I,
472        def_id: I::TraitAssocTermId,
473        args: I::GenericArgs,
474        term: I::Term,
475    ) -> ExistentialProjection<I> {
476        interner.debug_assert_existential_args_compatible(def_id.into(), args);
477        Self { def_id, args, term, use_existential_projection_new_instead: () }
478    }
479
480    pub fn new(
481        interner: I,
482        def_id: I::TraitAssocTermId,
483        args: impl IntoIterator<Item: Into<I::GenericArg>>,
484        term: I::Term,
485    ) -> ExistentialProjection<I> {
486        let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
487        Self::new_from_args(interner, def_id, args, term)
488    }
489
490    /// Extracts the underlying existential trait reference from this projection.
491    ///
492    /// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`,
493    /// then this function would return an `exists T. T: Iterator` existential trait
494    /// reference.
495    pub fn trait_ref(&self, interner: I) -> ExistentialTraitRef<I> {
496        let def_id = interner.projection_parent(self.def_id);
497        let args_count = interner.generics_of(def_id.into()).count() - 1;
498        let args = interner.mk_args(&self.args.as_slice()[..args_count]);
499        ExistentialTraitRef::new_from_args(interner, def_id, args)
500    }
501
502    pub fn with_self_ty(&self, interner: I, self_ty: I::Ty) -> ProjectionPredicate<I> {
503        // otherwise the escaping regions would be captured by the binders
504        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());
505
506        ProjectionPredicate {
507            projection_term: ty::AliasTerm::new(
508                interner,
509                interner.alias_term_kind_from_def_id(self.def_id.into()),
510                [self_ty.into()].iter().chain(self.args.iter()),
511            ),
512            term: self.term,
513        }
514    }
515
516    pub fn erase_self_ty(interner: I, projection_predicate: ProjectionPredicate<I>) -> Self {
517        // Assert there is a Self.
518        projection_predicate.projection_term.args.type_at(0);
519
520        Self {
521            def_id: projection_predicate.def_id(),
522            args: interner.mk_args(&projection_predicate.projection_term.args.as_slice()[1..]),
523            term: projection_predicate.term,
524            use_existential_projection_new_instead: (),
525        }
526    }
527}
528
529impl<I: Interner> ty::Binder<I, ExistentialProjection<I>> {
530    pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder<I, ProjectionPredicate<I>> {
531        self.map_bound(|p| p.with_self_ty(cx, self_ty))
532    }
533
534    pub fn item_def_id(&self) -> I::TraitAssocTermId {
535        self.skip_binder().def_id
536    }
537}
538
539/// This kind of predicate has no *direct* correspondent in the
540/// syntax, but it roughly corresponds to the syntactic forms:
541///
542/// 1. `T: TraitRef<..., Item = Type>`
543/// 2. `<T as TraitRef<...>>::Item == Type` (NYI)
544///
545/// In particular, form #1 is "desugared" to the combination of a
546/// normal trait predicate (`T: TraitRef<...>`) and one of these
547/// predicates. Form #2 is a broader form in that it also permits
548/// equality between arbitrary types. Processing an instance of
549/// Form #2 eventually yields one of these `ProjectionPredicate`
550/// instances to normalize the LHS.
551#[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)]
552#[derive(const _: () =
    {
        impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for
            ProjectionPredicate<I> where I: Interner,
            ty::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,
            ty::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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = ProjectionPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
553#[cfg_attr(
554    feature = "nightly",
555    derive(const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for ProjectionPredicate<I> where
            ty::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
            ty::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> ::rustc_data_structures::stable_hash::StableHash for
            ProjectionPredicate<I> where
            ty::AliasTerm<I>: ::rustc_data_structures::stable_hash::StableHash,
            I::Term: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ProjectionPredicate {
                        projection_term: ref __binding_0, term: ref __binding_1 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
556)]
557pub struct ProjectionPredicate<I: Interner> {
558    pub projection_term: ty::AliasTerm<I>,
559    pub term: I::Term,
560}
561
562impl<I: Interner> Eq for ProjectionPredicate<I> {}
563
564impl<I: Interner> ProjectionPredicate<I> {
565    pub fn self_ty(self) -> I::Ty {
566        self.projection_term.self_ty()
567    }
568
569    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> ProjectionPredicate<I> {
570        Self {
571            projection_term: self.projection_term.with_replaced_self_ty(interner, self_ty),
572            ..self
573        }
574    }
575
576    pub fn trait_def_id(self, interner: I) -> I::TraitId {
577        self.projection_term.trait_def_id(interner)
578    }
579
580    pub fn def_id(self) -> I::TraitAssocTermId {
581        self.projection_term.expect_projection_def_id()
582    }
583}
584
585impl<I: Interner> ty::Binder<I, ProjectionPredicate<I>> {
586    /// Returns the `DefId` of the trait of the associated item being projected.
587    #[inline]
588    pub fn trait_def_id(&self, cx: I) -> I::TraitId {
589        self.skip_binder().projection_term.trait_def_id(cx)
590    }
591
592    pub fn term(&self) -> ty::Binder<I, I::Term> {
593        self.map_bound(|predicate| predicate.term)
594    }
595
596    /// The `DefId` of the `TraitItem` for the associated type.
597    ///
598    /// Note that this is not the `DefId` of the `TraitRef` containing this
599    /// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
600    pub fn item_def_id(&self) -> I::TraitAssocTermId {
601        // Ok to skip binder since trait `DefId` does not care about regions.
602        self.skip_binder().def_id()
603    }
604}
605
606impl<I: Interner> fmt::Debug for ProjectionPredicate<I> {
607    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
608        f.write_fmt(format_args!("ProjectionPredicate({0:?}, {1:?})",
        self.projection_term, self.term))write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_term, self.term)
609    }
610}
611
612/// Used by the new solver to normalize an alias. This always expects the `term` to
613/// be an unconstrained inference variable which is used as the output.
614#[automatically_derived]
impl<I: Interner, K> ::core::cmp::PartialEq for NormalizesTo<I, K> where
    I: Interner, K: ::core::cmp::PartialEq {
    #[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, Eq, PartialEq; I: Interner, K)]
615#[derive(const _: () =
    {
        impl<I: Interner, K> ::rustc_type_ir::TypeVisitable<I> for
            NormalizesTo<I, K> where I: Interner,
            Alias<I, K>: ::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, K> ::rustc_type_ir::TypeFoldable<I> for
            NormalizesTo<I, K> where I: Interner,
            K: ::rustc_type_ir::TypeFoldable<I>,
            Alias<I, K>: ::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, K, J> ::rustc_type_ir::lift::Lift<J> for
            NormalizesTo<I, K> where J: Interner,
            I: ::rustc_type_ir::LiftInto<J>, K: ::rustc_type_ir::lift::Lift<J>
            {
            type Lifted =
                NormalizesTo<J,
                <K as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
616#[cfg_attr(
617    feature = "nightly",
618    derive(const _: () =
    {
        impl<I: Interner, K, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for NormalizesTo<I, K> where
            Alias<I, K>: ::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, K, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for NormalizesTo<I, K> where
            Alias<I, K>: ::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, K> ::rustc_data_structures::stable_hash::StableHash
            for NormalizesTo<I, K> where
            Alias<I, K>: ::rustc_data_structures::stable_hash::StableHash,
            I::Term: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    NormalizesTo { alias: ref __binding_0, term: ref __binding_1
                        } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
619)]
620pub struct NormalizesTo<I: Interner, K = ty::AliasTermKind<I>> {
621    pub alias: Alias<I, K>,
622    pub term: I::Term,
623}
624
625impl<I: Interner> NormalizesTo<I> {
626    pub fn self_ty(self) -> I::Ty {
627        self.alias.self_ty()
628    }
629
630    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> NormalizesTo<I> {
631        Self { alias: self.alias.with_replaced_self_ty(interner, self_ty), ..self }
632    }
633
634    pub fn trait_def_id(self, interner: I) -> I::TraitId {
635        self.alias.trait_def_id(interner)
636    }
637}
638
639impl<I: Interner, K> fmt::Debug for NormalizesTo<I, K>
640where
641    // `TypeVisitable_Generic` derived on `NormalizesTo` creates a field-level
642    // `Alias<I, K>: TypeVisitable<I>` bound. Since `TypeVisitable<I>: fmt::Debug`,
643    // that proves `Alias<I, K>: fmt::Debug`, but not `K: fmt::Debug`.
644    Alias<I, K>: fmt::Debug,
645{
646    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
647        f.write_fmt(format_args!("NormalizesTo({0:?}, {1:?})", self.alias, self.term))write!(f, "NormalizesTo({:?}, {:?})", self.alias, self.term)
648    }
649}
650
651#[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)]
652#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = HostEffectPredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    HostEffectPredicate {
                        trait_ref: __binding_0, constness: __binding_1 } => {
                        HostEffectPredicate {
                            trait_ref: __binding_0.lift_to_interner(interner),
                            constness: __binding_1,
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
653#[cfg_attr(
654    feature = "nightly",
655    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> ::rustc_data_structures::stable_hash::StableHash for
            HostEffectPredicate<I> where
            ty::TraitRef<I>: ::rustc_data_structures::stable_hash::StableHash
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    HostEffectPredicate {
                        trait_ref: ref __binding_0, constness: ref __binding_1 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
656)]
657pub struct HostEffectPredicate<I: Interner> {
658    pub trait_ref: ty::TraitRef<I>,
659    #[lift(identity)]
660    pub constness: BoundConstness,
661}
662
663impl<I: Interner> Eq for HostEffectPredicate<I> {}
664
665impl<I: Interner> HostEffectPredicate<I> {
666    pub fn self_ty(self) -> I::Ty {
667        self.trait_ref.self_ty()
668    }
669
670    pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
671        Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), ..self }
672    }
673
674    pub fn def_id(self) -> I::TraitId {
675        self.trait_ref.def_id
676    }
677}
678
679impl<I: Interner> ty::Binder<I, HostEffectPredicate<I>> {
680    pub fn def_id(self) -> I::TraitId {
681        // Ok to skip binder since trait `DefId` does not care about regions.
682        self.skip_binder().def_id()
683    }
684
685    pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
686        self.map_bound(|trait_ref| trait_ref.self_ty())
687    }
688
689    #[inline]
690    pub fn constness(self) -> BoundConstness {
691        self.skip_binder().constness
692    }
693}
694
695/// Encodes that `a` must be a subtype of `b`. The `a_is_expected` flag indicates
696/// whether the `a` type is the type that we should label as "expected" when
697/// presenting user diagnostics.
698#[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)]
699#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = SubtypePredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    SubtypePredicate {
                        a_is_expected: __binding_0, a: __binding_1, b: __binding_2 }
                        => {
                        SubtypePredicate {
                            a_is_expected: __binding_0,
                            a: __binding_1.lift_to_interner(interner),
                            b: __binding_2.lift_to_interner(interner),
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
700#[cfg_attr(
701    feature = "nightly",
702    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> ::rustc_data_structures::stable_hash::StableHash for
            SubtypePredicate<I> where
            I::Ty: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    SubtypePredicate {
                        a_is_expected: ref __binding_0,
                        a: ref __binding_1,
                        b: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
703)]
704pub struct SubtypePredicate<I: Interner> {
705    #[lift(identity)]
706    pub a_is_expected: bool,
707    pub a: I::Ty,
708    pub b: I::Ty,
709}
710
711impl<I: Interner> Eq for SubtypePredicate<I> {}
712
713/// Encodes that we have to coerce *from* the `a` type to the `b` type.
714#[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)]
715#[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 J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = CoercePredicate<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                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)]
716#[cfg_attr(
717    feature = "nightly",
718    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> ::rustc_data_structures::stable_hash::StableHash for
            CoercePredicate<I> where
            I::Ty: ::rustc_data_structures::stable_hash::StableHash {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    CoercePredicate { a: ref __binding_0, b: ref __binding_1 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
719)]
720pub struct CoercePredicate<I: Interner> {
721    pub a: I::Ty,
722    pub b: I::Ty,
723}
724
725impl<I: Interner> Eq for CoercePredicate<I> {}
726
727#[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)]
728#[cfg_attr(feature = "nightly", 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 ::rustc_data_structures::stable_hash::StableHash for
            BoundConstness {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    BoundConstness::Const => {}
                    BoundConstness::Maybe => {}
                }
            }
        }
    };StableHash))]
729pub enum BoundConstness {
730    /// `Type: const Trait`
731    ///
732    /// A bound is required to be unconditionally const, even in a runtime function.
733    Const,
734    /// `Type: [const] Trait`
735    ///
736    /// Requires resolving to const only when we are in a const context.
737    Maybe,
738}
739
740impl BoundConstness {
741    pub fn satisfies(self, goal: BoundConstness) -> bool {
742        match (self, goal) {
743            (BoundConstness::Const, BoundConstness::Const | BoundConstness::Maybe) => true,
744            (BoundConstness::Maybe, BoundConstness::Maybe) => true,
745            (BoundConstness::Maybe, BoundConstness::Const) => false,
746        }
747    }
748
749    pub fn as_str(self) -> &'static str {
750        match self {
751            Self::Const => "const",
752            Self::Maybe => "[const]",
753        }
754    }
755}
756
757impl fmt::Display for BoundConstness {
758    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
759        match self {
760            Self::Const => f.write_str("const"),
761            Self::Maybe => f.write_str("[const]"),
762        }
763    }
764}