Skip to main content

rustc_type_ir/
binder.rs

1use std::fmt;
2use std::hash::Hash;
3use std::marker::PhantomData;
4use std::ops::{ControlFlow, Deref};
5
6use derive_where::derive_where;
7#[cfg(feature = "nightly")]
8use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash, StableHash_NoContext};
9use rustc_type_ir_macros::{
10    GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
11};
12use tracing::instrument;
13
14use crate::data_structures::SsoHashSet;
15use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
16use crate::inherent::*;
17use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
18use crate::{
19    self as ty, Const, DebruijnIndex, Interner, PredicateProxy, Region, UniverseIndex, Unnormalized,
20};
21
22/// `Binder` is a binder for higher-ranked lifetimes or types. It is part of the
23/// compiler's representation for things like `for<'a> Fn(&'a isize)`
24/// (which would be represented by the type `PolyTraitRef == Binder<I, TraitRef>`).
25///
26/// See <https://rustc-dev-guide.rust-lang.org/ty_module/instantiating_binders.html>
27/// for more details.
28#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for Binder<I, T> where I: Interner,
    T: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Binder {
                value: ref __field_value, bound_vars: ref __field_bound_vars }
                =>
                Binder {
                    value: ::core::clone::Clone::clone(__field_value),
                    bound_vars: ::core::clone::Clone::clone(__field_bound_vars),
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for Binder<I, T> where I: Interner,
    T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for Binder<I, T> where I: Interner,
    T: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            Binder {
                value: ref __field_value, bound_vars: ref __field_bound_vars }
                => {
                ::core::hash::Hash::hash(__field_value, __state);
                ::core::hash::Hash::hash(__field_bound_vars, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for Binder<I, T> where
    I: Interner, T: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (Binder {
                value: ref __field_value, bound_vars: ref __field_bound_vars
                }, Binder {
                value: ref __other_field_value,
                bound_vars: ref __other_field_bound_vars }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_value,
                            __other_field_value) &&
                    ::core::cmp::PartialEq::eq(__field_bound_vars,
                        __other_field_bound_vars),
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::fmt::Debug for Binder<I, T> where I: Interner,
    T: ::core::fmt::Debug {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            Binder {
                value: ref __field_value, bound_vars: ref __field_bound_vars }
                => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "Binder");
                ::core::fmt::DebugStruct::field(&mut __builder, "value",
                    __field_value);
                ::core::fmt::DebugStruct::field(&mut __builder, "bound_vars",
                    __field_bound_vars);
                ::core::fmt::DebugStruct::finish(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner, T)]
29#[derive(const _: () =
    {
        unsafe impl<I: Interner, T, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for Binder<I, T> where
            T: ::rustc_type_ir::GenericTypeVisitable<__V>,
            I::BoundVarKinds: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    Binder { value: ref __binding_0, bound_vars: ref __binding_1
                        } => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, T, J> ::rustc_type_ir::lift::Lift<J> for
            Binder<I, T> where J: Interner, I: ::rustc_type_ir::LiftInto<J>,
            T: ::rustc_type_ir::lift::Lift<J> {
            type Lifted =
                Binder<J, <T as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    Binder { value: __binding_0, bound_vars: __binding_1 } => {
                        Binder {
                            value: __binding_0.lift_to_interner(interner),
                            bound_vars: __binding_1.lift_to_interner(interner),
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
30#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
            for Binder<I, T> where
            T: ::rustc_data_structures::stable_hash::StableHash,
            I::BoundVarKinds: ::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 {
                    Binder { value: ref __binding_0, bound_vars: ref __binding_1
                        } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext))]
31pub struct Binder<I: Interner, T> {
32    value: T,
33    bound_vars: I::BoundVarKinds,
34}
35
36impl<I: Interner, T: Eq> Eq for Binder<I, T> {}
37
38impl<I: Interner, T> Binder<I, T>
39where
40    T: TypeVisitable<I>,
41{
42    /// Wraps `value` in a binder, asserting that `value` does not
43    /// contain any bound vars that would be bound by the
44    /// binder. This is commonly used to 'inject' a value T into a
45    /// different binding level.
46    #[track_caller]
47    pub fn dummy(value: T) -> Binder<I, T> {
48        if !!value.has_escaping_bound_vars() {
    {
        ::core::panicking::panic_fmt(format_args!("`{0:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder.",
                value));
    }
};assert!(
49            !value.has_escaping_bound_vars(),
50            "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
51        );
52        Binder { value, bound_vars: Default::default() }
53    }
54
55    pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
56        if truecfg!(debug_assertions) {
57            let mut validator = ValidateBoundVars::new(bound_vars);
58            let _ = value.visit_with(&mut validator);
59        }
60        Binder { value, bound_vars }
61    }
62}
63
64impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
65    fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
66        folder.try_fold_binder(self)
67    }
68
69    fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
70        folder.fold_binder(self)
71    }
72}
73
74impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
75    fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
76        visitor.visit_binder(self)
77    }
78}
79
80impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
81    fn try_super_fold_with<F: FallibleTypeFolder<I>>(
82        self,
83        folder: &mut F,
84    ) -> Result<Self, F::Error> {
85        self.try_map_bound(|t| t.try_fold_with(folder))
86    }
87
88    fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
89        self.map_bound(|t| t.fold_with(folder))
90    }
91}
92
93impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
94    fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
95        self.as_ref().skip_binder().visit_with(visitor)
96    }
97}
98
99impl<I: Interner, T> Binder<I, T> {
100    /// Returns the value contained inside of this `for<'a>`. Accessing generic args
101    /// in the returned value is generally incorrect.
102    ///
103    /// Please read <https://rustc-dev-guide.rust-lang.org/ty_module/instantiating_binders.html>
104    /// before using this function. It is usually better to discharge the binder using
105    /// `no_bound_vars` or `instantiate_bound_regions` or something like that.
106    ///
107    /// `skip_binder` is only valid when you are either extracting data that does not reference
108    /// any generic arguments, e.g. a `DefId`, or when you're making sure you only pass the
109    /// value to things which can handle escaping bound vars.
110    ///
111    /// See existing uses of `.skip_binder()` in `rustc_trait_selection::traits::select`
112    /// or `rustc_next_trait_solver` for examples.
113    pub fn skip_binder(self) -> T {
114        self.value
115    }
116
117    pub fn bound_vars(&self) -> I::BoundVarKinds {
118        self.bound_vars
119    }
120
121    pub fn as_ref(&self) -> Binder<I, &T> {
122        Binder { value: &self.value, bound_vars: self.bound_vars }
123    }
124
125    pub fn as_deref(&self) -> Binder<I, &T::Target>
126    where
127        T: Deref,
128    {
129        Binder { value: &self.value, bound_vars: self.bound_vars }
130    }
131
132    pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
133    where
134        F: FnOnce(&T) -> U,
135    {
136        self.as_ref().map_bound(f)
137    }
138
139    pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
140    where
141        F: FnOnce(T) -> U,
142    {
143        let Binder { value, bound_vars } = self;
144        let value = f(value);
145        if truecfg!(debug_assertions) {
146            let mut validator = ValidateBoundVars::new(bound_vars);
147            let _ = value.visit_with(&mut validator);
148        }
149        Binder { value, bound_vars }
150    }
151
152    pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
153    where
154        F: FnOnce(T) -> Result<U, E>,
155    {
156        let Binder { value, bound_vars } = self;
157        let value = f(value)?;
158        if truecfg!(debug_assertions) {
159            let mut validator = ValidateBoundVars::new(bound_vars);
160            let _ = value.visit_with(&mut validator);
161        }
162        Ok(Binder { value, bound_vars })
163    }
164
165    /// Wraps a `value` in a binder, using the same bound variables as the
166    /// current `Binder`. This should not be used if the new value *changes*
167    /// the bound variables. Note: the (old or new) value itself does not
168    /// necessarily need to *name* all the bound variables.
169    ///
170    /// This currently doesn't do anything different than `bind`, because we
171    /// don't actually track bound vars. However, semantically, it is different
172    /// because bound vars aren't allowed to change here, whereas they are
173    /// in `bind`. This may be (debug) asserted in the future.
174    pub fn rebind<U>(&self, value: U) -> Binder<I, U>
175    where
176        U: TypeVisitable<I>,
177    {
178        Binder::bind_with_vars(value, self.bound_vars)
179    }
180
181    /// Unwraps and returns the value within, but only if it contains
182    /// no bound vars at all. (In other words, if this binder --
183    /// and indeed any enclosing binder -- doesn't bind anything at
184    /// all.) Otherwise, returns `None`.
185    ///
186    /// (One could imagine having a method that just unwraps a single
187    /// binder, but permits late-bound vars bound by enclosing
188    /// binders, but that would require adjusting the debruijn
189    /// indices, and given the shallow binding structure we often use,
190    /// would not be that useful.)
191    pub fn no_bound_vars(self) -> Option<T>
192    where
193        T: TypeVisitable<I>,
194    {
195        // `self.value` is equivalent to `self.skip_binder()`
196        if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
197    }
198}
199
200impl<I: Interner, T> Binder<I, Option<T>> {
201    pub fn transpose(self) -> Option<Binder<I, T>> {
202        let Binder { value, bound_vars } = self;
203        value.map(|value| Binder { value, bound_vars })
204    }
205}
206
207impl<I: Interner, T: IntoIterator> Binder<I, T> {
208    pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
209        let Binder { value, bound_vars } = self;
210        value.into_iter().map(move |value| Binder { value, bound_vars })
211    }
212}
213
214pub struct ValidateBoundVars<I: Interner> {
215    bound_vars: I::BoundVarKinds,
216    binder_index: ty::DebruijnIndex,
217    // We only cache types because any complex const will have to step through
218    // a type at some point anyways. We may encounter the same variable at
219    // different levels of binding, so this can't just be `Ty`.
220    visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
221}
222
223impl<I: Interner> ValidateBoundVars<I> {
224    pub fn new(bound_vars: I::BoundVarKinds) -> Self {
225        ValidateBoundVars {
226            bound_vars,
227            binder_index: ty::INNERMOST,
228            visited: SsoHashSet::default(),
229        }
230    }
231}
232
233impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
234    type Result = ControlFlow<()>;
235
236    fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
237        self.binder_index.shift_in(1);
238        let result = t.super_visit_with(self);
239        self.binder_index.shift_out(1);
240        result
241    }
242
243    fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
244        if t.outer_exclusive_binder() < self.binder_index
245            || !self.visited.insert((self.binder_index, t))
246        {
247            return ControlFlow::Break(());
248        }
249        match t.kind() {
250            ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
251                if debruijn == self.binder_index =>
252            {
253                let idx = bound_ty.var().as_usize();
254                if self.bound_vars.len() <= idx {
255                    {
    ::core::panicking::panic_fmt(format_args!("Not enough bound vars: {0:?} not found in {1:?}",
            t, self.bound_vars));
};panic!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
256                }
257                bound_ty.assert_eq(self.bound_vars.get(idx).unwrap());
258            }
259            _ => {}
260        };
261
262        t.super_visit_with(self)
263    }
264
265    fn visit_const(&mut self, c: Const<I>) -> Self::Result {
266        if c.outer_exclusive_binder() < self.binder_index {
267            return ControlFlow::Break(());
268        }
269        match c.kind() {
270            ty::ConstKind::Bound(debruijn, bound_const)
271                if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
272            {
273                let idx = bound_const.var().as_usize();
274                if self.bound_vars.len() <= idx {
275                    {
    ::core::panicking::panic_fmt(format_args!("Not enough bound vars: {0:?} not found in {1:?}",
            c, self.bound_vars));
};panic!("Not enough bound vars: {:?} not found in {:?}", c, self.bound_vars);
276                }
277                bound_const.assert_eq(self.bound_vars.get(idx).unwrap());
278            }
279            _ => {}
280        };
281
282        c.super_visit_with(self)
283    }
284
285    fn visit_region(&mut self, r: Region<I>) -> Self::Result {
286        match r.kind() {
287            ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
288                let idx = br.var().as_usize();
289                if self.bound_vars.len() <= idx {
290                    {
    ::core::panicking::panic_fmt(format_args!("Not enough bound vars: {0:?} not found in {1:?}",
            r, self.bound_vars));
};panic!("Not enough bound vars: {:?} not found in {:?}", r, self.bound_vars);
291                }
292                br.assert_eq(self.bound_vars.get(idx).unwrap());
293            }
294
295            _ => (),
296        };
297
298        ControlFlow::Continue(())
299    }
300}
301
302/// Similar to [`Binder`] except that it tracks early bound generics, i.e. `struct Foo<T>(T)`
303/// needs `T` instantiated immediately. This type primarily exists to avoid forgetting to call
304/// `instantiate`.
305///
306/// See <https://rustc-dev-guide.rust-lang.org/ty_module/early_binder.html> for more details.
307#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for EarlyBinder<I, T> where
    I: Interner, T: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
                =>
                EarlyBinder {
                    value: ::core::clone::Clone::clone(__field_value),
                    _tcx: ::core::clone::Clone::clone(__field__tcx),
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for EarlyBinder<I, T> where
    I: Interner, T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialOrd for EarlyBinder<I, T> where
    I: Interner, T: ::core::cmp::PartialOrd {
    #[inline]
    fn partial_cmp(&self, __other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match (self, __other) {
            (EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
                EarlyBinder {
                value: ref __other_field_value, _tcx: ref __other_field__tcx
                }) =>
                match ::core::cmp::PartialOrd::partial_cmp(__field_value,
                        __other_field_value) {
                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                        =>
                        match ::core::cmp::PartialOrd::partial_cmp(__field__tcx,
                                __other_field__tcx) {
                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                =>
                                ::core::option::Option::Some(::core::cmp::Ordering::Equal),
                            __cmp => __cmp,
                        },
                    __cmp => __cmp,
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Ord for EarlyBinder<I, T> where I: Interner,
    T: ::core::cmp::Ord {
    #[inline]
    fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
        match (self, __other) {
            (EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
                EarlyBinder {
                value: ref __other_field_value, _tcx: ref __other_field__tcx
                }) =>
                match ::core::cmp::Ord::cmp(__field_value,
                        __other_field_value) {
                    ::core::cmp::Ordering::Equal =>
                        match ::core::cmp::Ord::cmp(__field__tcx,
                                __other_field__tcx) {
                            ::core::cmp::Ordering::Equal =>
                                ::core::cmp::Ordering::Equal,
                            __cmp => __cmp,
                        },
                    __cmp => __cmp,
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for EarlyBinder<I, T> where
    I: Interner, T: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
                EarlyBinder {
                value: ref __other_field_value, _tcx: ref __other_field__tcx
                }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_value,
                            __other_field_value) &&
                    ::core::cmp::PartialEq::eq(__field__tcx,
                        __other_field__tcx),
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for EarlyBinder<I, T> where
    I: Interner, T: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
                => {
                ::core::hash::Hash::hash(__field_value, __state);
                ::core::hash::Hash::hash(__field__tcx, __state);
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::fmt::Debug for EarlyBinder<I, T> where
    I: Interner, T: ::core::fmt::Debug {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
                => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "EarlyBinder");
                ::core::fmt::DebugStruct::field(&mut __builder, "value",
                    __field_value);
                ::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
            }
        }
    }
}#[derive_where(Clone, Copy, PartialOrd, Ord, PartialEq, Hash, Debug; I: Interner, T)]
308#[derive(const _: () =
    {
        unsafe impl<I: Interner, T, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for EarlyBinder<I, T>
            where T: ::rustc_type_ir::GenericTypeVisitable<__V>,
            PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
            {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
                        } => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable)]
309#[cfg_attr(
310    feature = "nightly",
311    derive(const _: () =
    {
        impl<I: Interner, T, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for EarlyBinder<I, T> where
            T: ::rustc_serialize::Encodable<__E>,
            PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let EarlyBinder {
                        value: ref __binding_0, _tcx: ref __binding_1 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, T, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for EarlyBinder<I, T> where
            T: ::rustc_serialize::Decodable<__D>,
            PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                EarlyBinder {
                    value: ::rustc_serialize::Decodable::decode(__decoder),
                    _tcx: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
            for EarlyBinder<I, T> where
            T: ::rustc_data_structures::stable_hash::StableHash,
            PhantomData<fn()
                -> 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 {
                    EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
                        } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
312)]
313pub struct EarlyBinder<I: Interner, T> {
314    value: T,
315    #[derive_where(skip(Debug))]
316    _tcx: PhantomData<fn() -> I>,
317}
318
319impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
320
321// FIXME(154045): Recommended as per https://github.com/rust-lang/rust/issues/154045, this is so sad :((
322#[cfg(feature = "nightly")]
323macro_rules! generate { ($( $tt:tt )*) => { $( $tt )* } }
324
325#[cfg(feature = "nightly")]
326generate!(
327    /// For early binders, you should first call `instantiate` before using any visitors.
328    impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
329    /// For early binders, you should first call `instantiate` before using any visitors.
330    impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
331);
332
333impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
334    pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {
335        // Instantiation will require normalization.
336        let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization();
337        EarlyBinder { value, _tcx: PhantomData }
338    }
339}
340
341impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> {
342    pub fn bind_iter(value: T) -> EarlyBinder<I, T> {
343        #[cfg(debug_assertions)]
344        {
345            value.clone().into_iter().for_each(|v| if !!v.has_rigid_aliases() {
    ::core::panicking::panic("assertion failed: !v.has_rigid_aliases()")
}assert!(!v.has_rigid_aliases()));
346        }
347
348        EarlyBinder { value, _tcx: PhantomData }
349    }
350}
351
352impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> {
353    pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> {
354        if true {
    if !!value.has_rigid_aliases() {
        ::core::panicking::panic("assertion failed: !value.has_rigid_aliases()")
    };
};debug_assert!(!value.has_rigid_aliases());
355        EarlyBinder { value, _tcx: PhantomData }
356    }
357}
358
359impl<I: Interner, T> EarlyBinder<I, T> {
360    /// Use `bind/bind_iter/bind_no_rigid_aliases` instead.
361    /// Don't use this unless you know what you're doing.
362    pub fn bind_unchecked(value: T) -> EarlyBinder<I, T> {
363        EarlyBinder { value, _tcx: PhantomData }
364    }
365}
366
367impl<I: Interner, T> EarlyBinder<I, T> {
368    pub fn as_ref(&self) -> EarlyBinder<I, &T> {
369        EarlyBinder { value: &self.value, _tcx: PhantomData }
370    }
371
372    pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
373    where
374        F: FnOnce(&T) -> U,
375    {
376        self.as_ref().map_bound(f)
377    }
378
379    pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
380    where
381        F: FnOnce(T) -> U,
382    {
383        let value = f(self.value);
384        EarlyBinder { value, _tcx: PhantomData }
385    }
386
387    pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
388    where
389        F: FnOnce(T) -> Result<U, E>,
390    {
391        let value = f(self.value)?;
392        Ok(EarlyBinder { value, _tcx: PhantomData })
393    }
394
395    pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
396        EarlyBinder { value, _tcx: PhantomData }
397    }
398
399    /// Skips the binder and returns the "bound" value. Accessing generic args
400    /// in the returned value is generally incorrect.
401    ///
402    /// Please read <https://rustc-dev-guide.rust-lang.org/ty_module/early_binder.html>
403    /// before using this function.
404    ///
405    /// Only use this to extract data that does not depend on generic parameters, e.g.
406    /// to get the `DefId` of the inner value or the number of arguments ofan `FnSig`,
407    /// or while making sure to only pass the value to functions which are explicitly
408    /// set up to handle these uninstantiated generic parameters.
409    ///
410    /// To skip the binder on `x: &EarlyBinder<I, T>` to obtain `&T`, leverage
411    /// [`EarlyBinder::as_ref`](EarlyBinder::as_ref): `x.as_ref().skip_binder()`.
412    ///
413    /// See also [`Binder::skip_binder`](Binder::skip_binder), which is
414    /// the analogous operation on [`Binder`].
415    pub fn skip_binder(self) -> T {
416        self.value
417    }
418}
419
420impl<I: Interner> EarlyBinder<I, ty::TraitRef<I>> {
421    pub fn def_id(&self) -> I::TraitId {
422        self.value.def_id
423    }
424}
425
426impl<I: Interner, T> EarlyBinder<I, Option<T>> {
427    pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
428        self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
429    }
430}
431
432impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
433where
434    Iter::Item: TypeFoldable<I>,
435{
436    pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
437    where
438        A: SliceLike<Item = I::GenericArg>,
439    {
440        IterInstantiated { it: self.value.into_iter(), cx, args }
441    }
442
443    /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
444    /// but on an iterator of `TypeFoldable` values.
445    pub fn iter_identity(self) -> impl Iterator<Item = Unnormalized<I, Iter::Item>> {
446        self.value.into_iter().map(Unnormalized::new)
447    }
448}
449
450pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
451    it: Iter::IntoIter,
452    cx: I,
453    args: A,
454}
455
456impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
457where
458    Iter::Item: TypeFoldable<I>,
459    A: SliceLike<Item = I::GenericArg>,
460{
461    type Item = Unnormalized<I, Iter::Item>;
462
463    fn next(&mut self) -> Option<Self::Item> {
464        Some(
465            EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
466                .instantiate(self.cx, self.args),
467        )
468    }
469
470    fn size_hint(&self) -> (usize, Option<usize>) {
471        self.it.size_hint()
472    }
473}
474
475impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
476where
477    Iter::IntoIter: DoubleEndedIterator,
478    Iter::Item: TypeFoldable<I>,
479    A: SliceLike<Item = I::GenericArg>,
480{
481    fn next_back(&mut self) -> Option<Self::Item> {
482        Some(
483            EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
484                .instantiate(self.cx, self.args),
485        )
486    }
487}
488
489impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
490where
491    Iter::IntoIter: ExactSizeIterator,
492    Iter::Item: TypeFoldable<I>,
493    A: SliceLike<Item = I::GenericArg>,
494{
495}
496
497impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
498where
499    Iter::Item: Deref,
500    <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
501{
502    pub fn iter_instantiated_copied(
503        self,
504        cx: I,
505        args: &'s [I::GenericArg],
506    ) -> IterInstantiatedCopied<'s, I, Iter> {
507        IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
508    }
509
510    /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
511    /// but on an iterator of values that deref to a `TypeFoldable`.
512    pub fn iter_identity_copied(self) -> IterIdentityCopied<I, Iter> {
513        IterIdentityCopied { it: self.value.into_iter(), _tcx: PhantomData }
514    }
515}
516
517pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
518    it: Iter::IntoIter,
519    cx: I,
520    args: &'a [I::GenericArg],
521}
522
523impl<'a, I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone
524    for IterInstantiatedCopied<'a, I, Iter>
525{
526    fn clone(&self) -> IterInstantiatedCopied<'a, I, Iter> {
527        IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args }
528    }
529}
530
531impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
532where
533    Iter::Item: Deref,
534    <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
535{
536    type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
537
538    fn next(&mut self) -> Option<Self::Item> {
539        self.it.next().map(|value| {
540            EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
541        })
542    }
543
544    fn size_hint(&self) -> (usize, Option<usize>) {
545        self.it.size_hint()
546    }
547}
548
549impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, I, Iter>
550where
551    Iter::IntoIter: DoubleEndedIterator,
552    Iter::Item: Deref,
553    <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
554{
555    fn next_back(&mut self) -> Option<Self::Item> {
556        self.it.next_back().map(|value| {
557            EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
558        })
559    }
560}
561
562impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, I, Iter>
563where
564    Iter::IntoIter: ExactSizeIterator,
565    Iter::Item: Deref,
566    <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
567{
568}
569
570pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
571    it: Iter::IntoIter,
572    _tcx: PhantomData<fn() -> I>,
573}
574
575impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> {
576    fn clone(&self) -> IterIdentityCopied<I, Iter> {
577        IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx }
578    }
579}
580
581impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
582where
583    Iter::Item: Deref,
584    <Iter::Item as Deref>::Target: Copy,
585{
586    type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
587
588    fn next(&mut self) -> Option<Self::Item> {
589        self.it.next().map(|i| Unnormalized::new(*i))
590    }
591
592    fn size_hint(&self) -> (usize, Option<usize>) {
593        self.it.size_hint()
594    }
595}
596
597impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<I, Iter>
598where
599    Iter::IntoIter: DoubleEndedIterator,
600    Iter::Item: Deref,
601    <Iter::Item as Deref>::Target: Copy,
602{
603    fn next_back(&mut self) -> Option<Self::Item> {
604        self.it.next_back().map(|i| Unnormalized::new(*i))
605    }
606}
607
608impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<I, Iter>
609where
610    Iter::IntoIter: ExactSizeIterator,
611    Iter::Item: Deref,
612    <Iter::Item as Deref>::Target: Copy,
613{
614}
615pub struct EarlyBinderIter<I, T> {
616    t: T,
617    _tcx: PhantomData<I>,
618}
619
620impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
621    pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
622        EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
623    }
624}
625
626impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
627    type Item = EarlyBinder<I, T::Item>;
628
629    fn next(&mut self) -> Option<Self::Item> {
630        self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
631    }
632
633    fn size_hint(&self) -> (usize, Option<usize>) {
634        self.t.size_hint()
635    }
636}
637
638impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
639    pub fn instantiate<A>(self, cx: I, args: A) -> Unnormalized<I, T>
640    where
641        A: SliceLike<Item = I::GenericArg>,
642    {
643        // Nothing to fold, so let's avoid visiting things and possibly re-hashing/equating
644        // them when interning. Perf testing found this to be a modest improvement.
645        // See: <https://github.com/rust-lang/rust/pull/142317>
646        if args.is_empty() {
647            if !!self.value.has_param() {
    {
        ::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
                self.value));
    }
};assert!(
648                !self.value.has_param(),
649                "{:?} has parameters, but no args were provided in instantiate",
650                self.value,
651            );
652            return Unnormalized::new(self.value);
653        }
654        let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
655        Unnormalized::new(self.value.fold_with(&mut folder))
656    }
657
658    /// Makes the identity replacement `T0 => T0, ..., TN => TN`.
659    /// Conceptually, this converts universally bound variables into placeholders
660    /// when inside of a given item.
661    ///
662    /// For example, consider `for<T> fn foo<T>(){ .. }`:
663    /// - Outside of `foo`, `T` is bound (represented by the presence of `EarlyBinder`).
664    /// - Inside of the body of `foo`, we treat `T` as a placeholder by calling
665    /// `instantiate_identity` to discharge the `EarlyBinder`.
666    pub fn instantiate_identity(self) -> Unnormalized<I, T> {
667        // FIXME(#155345): In case the bound value was already normalized, this
668        // is unnecessary. We may want to track explicitly whether `EarlyBinder`
669        // contains something that has been normalized already.
670        // Also do that for other types who have `instantiate_identity` method,
671        // e.g., `GenericClauses` and `ConstConditions`.
672        //
673        // This is annoying, as e.g. `type_of` for opaque types is normalized,
674        // while `type_of` for free type aliases is not.
675        Unnormalized::new(self.value)
676    }
677
678    /// Returns the inner value, but only if it contains no bound vars.
679    pub fn no_bound_vars(self) -> Option<T> {
680        if !self.value.has_param() { Some(self.value) } else { None }
681    }
682}
683
684///////////////////////////////////////////////////////////////////////////
685// The actual instantiation engine itself is a type folder.
686
687struct ArgFolder<'a, I: Interner> {
688    cx: I,
689    args: &'a [I::GenericArg],
690
691    /// Number of region binders we have passed through while doing the instantiation
692    binders_passed: u32,
693}
694
695impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
696    #[inline]
697    fn cx(&self) -> I {
698        self.cx
699    }
700
701    fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
702        self.binders_passed += 1;
703        let t = t.super_fold_with(self);
704        self.binders_passed -= 1;
705        t
706    }
707
708    fn fold_region(&mut self, r: Region<I>) -> Region<I> {
709        // Note: This routine only handles regions that are bound on
710        // type declarations and other outer declarations, not those
711        // bound in *fn types*. Region instantiation of the bound
712        // regions that appear in a function signature is done using
713        // the specialized routine `ty::replace_late_regions()`.
714        match r.kind() {
715            ty::ReEarlyParam(data) => {
716                let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
717                match rk {
718                    Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
719                    Some(other) => self.region_param_expected(data, r, other),
720                    None => self.region_param_out_of_range(data, r),
721                }
722            }
723            ty::ReBound(..)
724            | ty::ReLateParam(_)
725            | ty::ReStatic
726            | ty::RePlaceholder(_)
727            | ty::ReErased
728            | ty::ReError(_) => r,
729            ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
730        }
731    }
732
733    fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
734        if !t.has_param() {
735            return t;
736        }
737
738        match t.kind() {
739            ty::Param(p) => self.ty_for_param(p, t),
740            _ => t.super_fold_with(self),
741        }
742    }
743
744    fn fold_const(&mut self, c: Const<I>) -> Const<I> {
745        if let ty::ConstKind::Param(p) = c.kind() {
746            self.const_for_param(p, c)
747        } else {
748            c.super_fold_with(self)
749        }
750    }
751
752    fn fold_predicate<P: PredicateProxy<I>>(&mut self, p: P) -> P {
753        if p.has_param() { p.super_fold_with(self) } else { p }
754    }
755
756    fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
757        if c.has_param() { c.super_fold_with(self) } else { c }
758    }
759}
760
761impl<'a, I: Interner> ArgFolder<'a, I> {
762    fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
763        // Look up the type in the args. It really should be in there.
764        let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
765        let ty = match opt_ty {
766            Some(ty::GenericArgKind::Type(ty)) => ty,
767            Some(kind) => self.type_param_expected(p, source_ty, kind),
768            None => self.type_param_out_of_range(p, source_ty),
769        };
770
771        self.shift_vars_through_binders(ty)
772    }
773
774    #[cold]
775    #[inline(never)]
776    fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
777        {
    ::core::panicking::panic_fmt(format_args!("expected type for `{0:?}` ({1:?}/{2}) but found {3:?} when instantiating, args={4:?}",
            p, ty, p.index(), kind, self.args));
}panic!(
778            "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
779            p,
780            ty,
781            p.index(),
782            kind,
783            self.args,
784        )
785    }
786
787    #[cold]
788    #[inline(never)]
789    fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
790        {
    ::core::panicking::panic_fmt(format_args!("type parameter `{0:?}` ({1:?}/{2}) out of range when instantiating, args={3:?}",
            p, ty, p.index(), self.args));
}panic!(
791            "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
792            p,
793            ty,
794            p.index(),
795            self.args,
796        )
797    }
798
799    fn const_for_param(&self, p: I::ParamConst, source_ct: Const<I>) -> Const<I> {
800        // Look up the const in the args. It really should be in there.
801        let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
802        let ct = match opt_ct {
803            Some(ty::GenericArgKind::Const(ct)) => ct,
804            Some(kind) => self.const_param_expected(p, source_ct, kind),
805            None => self.const_param_out_of_range(p, source_ct),
806        };
807
808        self.shift_vars_through_binders(ct)
809    }
810
811    #[cold]
812    #[inline(never)]
813    fn const_param_expected(
814        &self,
815        p: I::ParamConst,
816        ct: Const<I>,
817        kind: ty::GenericArgKind<I>,
818    ) -> ! {
819        {
    ::core::panicking::panic_fmt(format_args!("expected const for `{0:?}` ({1:?}/{2}) but found {3:?} when instantiating args={4:?}",
            p, ct, p.index(), kind, self.args));
}panic!(
820            "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
821            p,
822            ct,
823            p.index(),
824            kind,
825            self.args,
826        )
827    }
828
829    #[cold]
830    #[inline(never)]
831    fn const_param_out_of_range(&self, p: I::ParamConst, ct: Const<I>) -> ! {
832        {
    ::core::panicking::panic_fmt(format_args!("const parameter `{0:?}` ({1:?}/{2}) out of range when instantiating args={3:?}",
            p, ct, p.index(), self.args));
}panic!(
833            "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
834            p,
835            ct,
836            p.index(),
837            self.args,
838        )
839    }
840
841    #[cold]
842    #[inline(never)]
843    fn region_param_expected(
844        &self,
845        ebr: I::EarlyParamRegion,
846        r: Region<I>,
847        kind: ty::GenericArgKind<I>,
848    ) -> ! {
849        {
    ::core::panicking::panic_fmt(format_args!("expected region for `{0:?}` ({1:?}/{2}) but found {3:?} when instantiating args={4:?}",
            ebr, r, ebr.index(), kind, self.args));
}panic!(
850            "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
851            ebr,
852            r,
853            ebr.index(),
854            kind,
855            self.args,
856        )
857    }
858
859    #[cold]
860    #[inline(never)]
861    fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: Region<I>) -> ! {
862        {
    ::core::panicking::panic_fmt(format_args!("region parameter `{0:?}` ({1:?}/{2}) out of range when instantiating args={3:?}",
            ebr, r, ebr.index(), self.args));
}panic!(
863            "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
864            ebr,
865            r,
866            ebr.index(),
867            self.args,
868        )
869    }
870
871    /// It is sometimes necessary to adjust the De Bruijn indices during instantiation. This occurs
872    /// when we are instantiating a type with escaping bound vars into a context where we have
873    /// passed through binders. That's quite a mouthful. Let's see an example:
874    ///
875    /// ```
876    /// type Func<A> = fn(A);
877    /// type MetaFunc = for<'a> fn(Func<&'a i32>);
878    /// ```
879    ///
880    /// The type `MetaFunc`, when fully expanded, will be
881    /// ```ignore (illustrative)
882    /// for<'a> fn(fn(&'a i32))
883    /// //      ^~ ^~ ^~~
884    /// //      |  |  |
885    /// //      |  |  DebruijnIndex of 2
886    /// //      Binders
887    /// ```
888    /// Here the `'a` lifetime is bound in the outer function, but appears as an argument of the
889    /// inner one. Therefore, that appearance will have a DebruijnIndex of 2, because we must skip
890    /// over the inner binder (remember that we count De Bruijn indices from 1). However, in the
891    /// definition of `MetaFunc`, the binder is not visible, so the type `&'a i32` will have a
892    /// De Bruijn index of 1. It's only during the instantiation that we can see we must increase the
893    /// depth by 1 to account for the binder that we passed through.
894    ///
895    /// As a second example, consider this twist:
896    ///
897    /// ```
898    /// type FuncTuple<A> = (A,fn(A));
899    /// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>);
900    /// ```
901    ///
902    /// Here the final type will be:
903    /// ```ignore (illustrative)
904    /// for<'a> fn((&'a i32, fn(&'a i32)))
905    /// //          ^~~         ^~~
906    /// //          |           |
907    /// //   DebruijnIndex of 1 |
908    /// //               DebruijnIndex of 2
909    /// ```
910    /// As indicated in the diagram, here the same type `&'a i32` is instantiated once, but in the
911    /// first case we do not increase the De Bruijn index and in the second case we do. The reason
912    /// is that only in the second case have we passed through a fn binder.
913    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::TRACE <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("shift_vars_through_binders",
                                "rustc_type_ir::binder", ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/75a75c3e0a67d3fa3d03982775f5bb0356e7b510/compiler/rustc_type_ir/src/binder.rs"),
                                ::tracing_core::__macro_support::Option::Some(913u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_type_ir::binder"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("val")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("val");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("binders_passed")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("binders_passed");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&val)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&self.binders_passed
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: T = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if self.binders_passed == 0 ||
                                !val.has_escaping_bound_vars() {
                            val
                        } else { ty::shift_vars(self.cx, val, self.binders_passed) }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/75a75c3e0a67d3fa3d03982775f5bb0356e7b510/compiler/rustc_type_ir/src/binder.rs:913",
                        "rustc_type_ir::binder", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/75a75c3e0a67d3fa3d03982775f5bb0356e7b510/compiler/rustc_type_ir/src/binder.rs"),
                        ::tracing_core::__macro_support::Option::Some(913u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_type_ir::binder"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
914    fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
915        if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
916            val
917        } else {
918            ty::shift_vars(self.cx, val, self.binders_passed)
919        }
920    }
921
922    fn shift_region_through_binders(&self, region: Region<I>) -> Region<I> {
923        if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
924            region
925        } else {
926            ty::shift_region(self.cx, region, self.binders_passed)
927        }
928    }
929}
930
931/// Okay, we do something fun for `Bound` types/regions/consts:
932/// Specifically, we distinguish between *canonically* bound things and
933/// `for<>` bound things. And, really, it comes down to caching during
934/// canonicalization and instantiation.
935///
936/// To understand why we do this, imagine we have a type `(T, for<> fn(T))`.
937/// If we just tracked canonically bound types with a `DebruijnIndex` (as we
938/// used to), then the canonicalized type would be something like
939/// `for<0> (^0.0, for<> fn(^1.0))` and so we can't cache `T -> ^0.0`,
940/// we have to also factor in binder level. (Of course, we don't cache that
941/// exactly, but rather the entire enclosing type, but the point stands.)
942///
943/// Of course, this is okay because we don't ever nest canonicalization, so
944/// `BoundVarIndexKind::Canonical` is unambiguous. We, alternatively, could
945/// have some sentinel `DebruijinIndex`, but that just seems too scary.
946///
947/// This doesn't seem to have a huge perf swing either way, but in the next
948/// solver, canonicalization is hot and there are some pathological cases where
949/// this is needed (`post-mono-higher-ranked-hang`).
950#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for BoundVarIndexKind { }
#[automatically_derived]
impl ::core::clone::Clone for BoundVarIndexKind {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<DebruijnIndex>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for BoundVarIndexKind { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for BoundVarIndexKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Bound(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Bound",
                    &__self_0),
            Self::Canonical =>
                ::core::fmt::Formatter::write_str(f, "Canonical"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for BoundVarIndexKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for BoundVarIndexKind {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::Bound(__self_0), Self::Bound(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for BoundVarIndexKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DebruijnIndex>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for BoundVarIndexKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
            state);
        match self {
            Self::Bound(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash)]
951#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundVarIndexKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        BoundVarIndexKind::Bound(ref __binding_0) => { 0usize }
                        BoundVarIndexKind::Canonical => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    BoundVarIndexKind::Bound(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    BoundVarIndexKind::Canonical => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundVarIndexKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        BoundVarIndexKind::Bound(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => { BoundVarIndexKind::Canonical }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `BoundVarIndexKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            BoundVarIndexKind {
            #[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 {
                    BoundVarIndexKind::Bound(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    BoundVarIndexKind::Canonical => {}
                }
            }
        }
    };StableHash))]
952#[derive(const _: () =
    {
        impl<I> ::rustc_type_ir::TypeVisitable<I> for BoundVarIndexKind where
            I: Interner {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    BoundVarIndexKind::Bound(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);
                                }
                            }
                        }
                    }
                    BoundVarIndexKind::Canonical => {}
                }
                <__V::Result as ::rustc_type_ir::VisitorResult>::output()
            }
        }
    };TypeVisitable_Generic, const _: () =
    {
        unsafe impl<__V> ::rustc_type_ir::GenericTypeVisitable<__V> for
            BoundVarIndexKind where
            DebruijnIndex: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundVarIndexKind::Bound(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    BoundVarIndexKind::Canonical => {}
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I> ::rustc_type_ir::TypeFoldable<I> for BoundVarIndexKind where
            I: Interner {
            fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        BoundVarIndexKind::Bound(__binding_0) => {
                            BoundVarIndexKind::Bound(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?)
                        }
                        BoundVarIndexKind::Canonical => {
                            BoundVarIndexKind::Canonical
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    BoundVarIndexKind::Bound(__binding_0) => {
                        BoundVarIndexKind::Bound(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder))
                    }
                    BoundVarIndexKind::Canonical => {
                        BoundVarIndexKind::Canonical
                    }
                }
            }
        }
    };TypeFoldable_Generic)]
953pub enum BoundVarIndexKind {
954    Bound(DebruijnIndex),
955    Canonical,
956}
957
958/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
959/// identified by both a universe, as well as a name residing within that universe. Distinct bound
960/// regions/types/consts within the same universe simply have an unknown relationship to one
961#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for Placeholder<I, T> where
    I: Interner, T: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Placeholder {
                universe: ref __field_universe,
                bound: ref __field_bound,
                _tcx: ref __field__tcx } =>
                Placeholder {
                    universe: ::core::clone::Clone::clone(__field_universe),
                    bound: ::core::clone::Clone::clone(__field_bound),
                    _tcx: ::core::clone::Clone::clone(__field__tcx),
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for Placeholder<I, T> where
    I: Interner, T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialOrd for Placeholder<I, T> where
    I: Interner, T: ::core::cmp::PartialOrd {
    #[inline]
    fn partial_cmp(&self, __other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match (self, __other) {
            (Placeholder {
                universe: ref __field_universe,
                bound: ref __field_bound,
                _tcx: ref __field__tcx }, Placeholder {
                universe: ref __other_field_universe,
                bound: ref __other_field_bound,
                _tcx: ref __other_field__tcx }) =>
                match ::core::cmp::PartialOrd::partial_cmp(__field_universe,
                        __other_field_universe) {
                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                        =>
                        match ::core::cmp::PartialOrd::partial_cmp(__field_bound,
                                __other_field_bound) {
                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                =>
                                match ::core::cmp::PartialOrd::partial_cmp(__field__tcx,
                                        __other_field__tcx) {
                                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                        =>
                                        ::core::option::Option::Some(::core::cmp::Ordering::Equal),
                                    __cmp => __cmp,
                                },
                            __cmp => __cmp,
                        },
                    __cmp => __cmp,
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Ord for Placeholder<I, T> where I: Interner,
    T: ::core::cmp::Ord {
    #[inline]
    fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
        match (self, __other) {
            (Placeholder {
                universe: ref __field_universe,
                bound: ref __field_bound,
                _tcx: ref __field__tcx }, Placeholder {
                universe: ref __other_field_universe,
                bound: ref __other_field_bound,
                _tcx: ref __other_field__tcx }) =>
                match ::core::cmp::Ord::cmp(__field_universe,
                        __other_field_universe) {
                    ::core::cmp::Ordering::Equal =>
                        match ::core::cmp::Ord::cmp(__field_bound,
                                __other_field_bound) {
                            ::core::cmp::Ordering::Equal =>
                                match ::core::cmp::Ord::cmp(__field__tcx,
                                        __other_field__tcx) {
                                    ::core::cmp::Ordering::Equal =>
                                        ::core::cmp::Ordering::Equal,
                                    __cmp => __cmp,
                                },
                            __cmp => __cmp,
                        },
                    __cmp => __cmp,
                },
        }
    }
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for Placeholder<I, T> where
    I: Interner, T: ::core::cmp::PartialEq {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (Placeholder {
                universe: ref __field_universe,
                bound: ref __field_bound,
                _tcx: ref __field__tcx }, Placeholder {
                universe: ref __other_field_universe,
                bound: ref __other_field_bound,
                _tcx: ref __other_field__tcx }) =>
                true &&
                            ::core::cmp::PartialEq::eq(__field_universe,
                                __other_field_universe) &&
                        ::core::cmp::PartialEq::eq(__field_bound,
                            __other_field_bound) &&
                    ::core::cmp::PartialEq::eq(__field__tcx,
                        __other_field__tcx),
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner, T> DeriveWhereAssertEq for Placeholder<I, T> where
            I: Interner, T: ::core::cmp::Eq {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<UniverseIndex>;
                let _: __AssertEq<T>;
                let _: __AssertEq<PhantomData<fn() -> I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Eq for Placeholder<I, T> where I: Interner,
    T: ::core::cmp::Eq {
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for Placeholder<I, T> where
    I: Interner, T: ::core::hash::Hash {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            Placeholder {
                universe: ref __field_universe,
                bound: ref __field_bound,
                _tcx: ref __field__tcx } => {
                ::core::hash::Hash::hash(__field_universe, __state);
                ::core::hash::Hash::hash(__field_bound, __state);
                ::core::hash::Hash::hash(__field__tcx, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash; I: Interner, T)]
962#[derive(const _: () =
    {
        impl<I: Interner, T> ::rustc_type_ir::TypeVisitable<I> for
            Placeholder<I, T> where I: Interner,
            T: ::rustc_type_ir::TypeVisitable<I> {
            fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    Placeholder {
                        universe: ref __binding_0, bound: 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, const _: () =
    {
        impl<I: Interner, T> ::rustc_type_ir::TypeFoldable<I> for
            Placeholder<I, T> where I: Interner,
            T: ::rustc_type_ir::TypeFoldable<I>,
            T: ::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 {
                        Placeholder {
                            universe: __binding_0, bound: __binding_1, _tcx: __binding_2
                            } => {
                            Placeholder {
                                universe: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                bound: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                _tcx: __binding_2,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    Placeholder {
                        universe: __binding_0, bound: __binding_1, _tcx: __binding_2
                        } => {
                        Placeholder {
                            universe: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            bound: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            _tcx: __binding_2,
                        }
                    }
                }
            }
        }
    };TypeFoldable_Generic, const _: () =
    {
        unsafe impl<I: Interner, T, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for Placeholder<I, T>
            where UniverseIndex: ::rustc_type_ir::GenericTypeVisitable<__V>,
            T: ::rustc_type_ir::GenericTypeVisitable<__V>,
            PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
            {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    Placeholder {
                        universe: ref __binding_0,
                        bound: ref __binding_1,
                        _tcx: ref __binding_2 } => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_2,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, T, J> ::rustc_type_ir::lift::Lift<J> for
            Placeholder<I, T> where J: Interner,
            I: ::rustc_type_ir::LiftInto<J>, T: ::rustc_type_ir::lift::Lift<J>
            {
            type Lifted =
                Placeholder<J, <T as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    Placeholder {
                        universe: __binding_0, bound: __binding_1, _tcx: __binding_2
                        } => {
                        Placeholder {
                            universe: __binding_0,
                            bound: __binding_1.lift_to_interner(interner),
                            _tcx: PhantomData,
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
963#[cfg_attr(
964    feature = "nightly",
965    derive(const _: () =
    {
        impl<I: Interner, T, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for Placeholder<I, T> where
            T: ::rustc_serialize::Encodable<__E>,
            PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let Placeholder {
                        universe: ref __binding_0,
                        bound: ref __binding_1,
                        _tcx: ref __binding_2 } = *self;
                ::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, T, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for Placeholder<I, T> where
            T: ::rustc_serialize::Decodable<__D>,
            PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                Placeholder {
                    universe: ::rustc_serialize::Decodable::decode(__decoder),
                    bound: ::rustc_serialize::Decodable::decode(__decoder),
                    _tcx: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
            for Placeholder<I, T> where
            T: ::rustc_data_structures::stable_hash::StableHash,
            PhantomData<fn()
                -> 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 {
                    Placeholder {
                        universe: ref __binding_0,
                        bound: ref __binding_1,
                        _tcx: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
966)]
967pub struct Placeholder<I: Interner, T> {
968    #[lift(identity)]
969    pub universe: UniverseIndex,
970    pub bound: T,
971    #[type_foldable(identity)]
972    #[type_visitable(ignore)]
973    _tcx: PhantomData<fn() -> I>,
974}
975
976impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
977    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
978        if self.universe == ty::UniverseIndex::ROOT {
979            f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
980        } else {
981            f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
982        }
983    }
984}
985
986#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundRegionKind<I> where
    I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundRegionKind<I> where
    I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundRegionKind<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (BoundRegionKind::NamedForPrinting(ref __field_0),
                    BoundRegionKind::NamedForPrinting(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (BoundRegionKind::Named(ref __field_0),
                    BoundRegionKind::Named(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                _ => true,
            }
        } else { false }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundRegionKind<I> where
            I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<I::Symbol>;
                let _: __AssertEq<I::DefId>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundRegionKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundRegionKind<I> where I: Interner
    {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundRegionKind::Anon => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
            }
            BoundRegionKind::NamedForPrinting(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
            BoundRegionKind::Named(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
            BoundRegionKind::ClosureEnv => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
987#[derive(const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            BoundRegionKind<I> where J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = BoundRegionKind<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    BoundRegionKind::Anon => { BoundRegionKind::Anon }
                    BoundRegionKind::NamedForPrinting(__binding_0) => {
                        BoundRegionKind::NamedForPrinting(__binding_0.lift_to_interner(interner))
                    }
                    BoundRegionKind::Named(__binding_0) => {
                        BoundRegionKind::Named(__binding_0.lift_to_interner(interner))
                    }
                    BoundRegionKind::ClosureEnv => {
                        BoundRegionKind::ClosureEnv
                    }
                }
            }
        }
    };Lift_Generic, const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for BoundRegionKind<I>
            where I::Symbol: ::rustc_type_ir::GenericTypeVisitable<__V>,
            I::DefId: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundRegionKind::Anon => {}
                    BoundRegionKind::NamedForPrinting(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    BoundRegionKind::Named(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    BoundRegionKind::ClosureEnv => {}
                }
            }
        }
    };GenericTypeVisitable)]
988#[cfg_attr(
989    feature = "nightly",
990    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundRegionKind<I> where
            I::Symbol: ::rustc_serialize::Encodable<__E>,
            I::DefId: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        BoundRegionKind::Anon => { 0usize }
                        BoundRegionKind::NamedForPrinting(ref __binding_0) => {
                            1usize
                        }
                        BoundRegionKind::Named(ref __binding_0) => { 2usize }
                        BoundRegionKind::ClosureEnv => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    BoundRegionKind::Anon => {}
                    BoundRegionKind::NamedForPrinting(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    BoundRegionKind::Named(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    BoundRegionKind::ClosureEnv => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundRegionKind<I> where
            I::Symbol: ::rustc_serialize::Decodable<__D>,
            I::DefId: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { BoundRegionKind::Anon }
                    1usize => {
                        BoundRegionKind::NamedForPrinting(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        BoundRegionKind::Named(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => { BoundRegionKind::ClosureEnv }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `BoundRegionKind`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            BoundRegionKind<I> where
            I::Symbol: ::rustc_data_structures::stable_hash::StableHash,
            I::DefId: ::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 {
                    BoundRegionKind::Anon => {}
                    BoundRegionKind::NamedForPrinting(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    BoundRegionKind::Named(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    BoundRegionKind::ClosureEnv => {}
                }
            }
        }
    };StableHash_NoContext)
991)]
992pub enum BoundRegionKind<I: Interner> {
993    /// An anonymous region parameter for a given fn (&T)
994    Anon,
995
996    /// An anonymous region parameter with a `Symbol` name.
997    ///
998    /// Used to give late-bound regions names for things like pretty printing.
999    NamedForPrinting(I::Symbol),
1000
1001    /// Late-bound regions that appear in the AST.
1002    Named(I::DefId),
1003
1004    /// Anonymous region for the implicit env pointer parameter
1005    /// to a closure
1006    ClosureEnv,
1007}
1008
1009impl<I: Interner> fmt::Debug for ty::BoundRegionKind<I> {
1010    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1011        match *self {
1012            ty::BoundRegionKind::Anon => f.write_fmt(format_args!("BrAnon"))write!(f, "BrAnon"),
1013            ty::BoundRegionKind::NamedForPrinting(name) => {
1014                f.write_fmt(format_args!("BrNamedForPrinting({0:?})", name))write!(f, "BrNamedForPrinting({:?})", name)
1015            }
1016            ty::BoundRegionKind::Named(did) => {
1017                f.write_fmt(format_args!("BrNamed({0:?})", did))write!(f, "BrNamed({did:?})")
1018            }
1019            ty::BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("BrEnv"))write!(f, "BrEnv"),
1020        }
1021    }
1022}
1023
1024impl<I: Interner> BoundRegionKind<I> {
1025    pub fn is_named(&self, tcx: I) -> bool {
1026        self.get_name(tcx).is_some()
1027    }
1028
1029    pub fn get_name(&self, tcx: I) -> Option<I::Symbol> {
1030        match *self {
1031            ty::BoundRegionKind::Named(def_id) => {
1032                let name = tcx.item_name(def_id);
1033                if name == I::Symbol::KW_UNDERSCORE_LIFETIME { None } else { Some(name) }
1034            }
1035            ty::BoundRegionKind::NamedForPrinting(name) => Some(name),
1036            _ => None,
1037        }
1038    }
1039
1040    pub fn get_id(&self) -> Option<I::DefId> {
1041        match *self {
1042            ty::BoundRegionKind::Named(id) => Some(id),
1043            _ => None,
1044        }
1045    }
1046}
1047
1048#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundTyKind<I> where I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundTyKind<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundTyKind<I> where I: Interner
    {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (BoundTyKind::Param(ref __field_0),
                    BoundTyKind::Param(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                _ => true,
            }
        } else { false }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundTyKind<I> where
            I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<I::DefId>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundTyKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundTyKind<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            BoundTyKind::Anon =>
                ::core::fmt::Formatter::write_str(__f, "Anon"),
            BoundTyKind::Param(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Param");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
        }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundTyKind<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundTyKind::Anon => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
            }
            BoundTyKind::Param(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)]
1049#[derive(const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundTyKind<I>
            where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = BoundTyKind<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    BoundTyKind::Anon => { BoundTyKind::Anon }
                    BoundTyKind::Param(__binding_0) => {
                        BoundTyKind::Param(__binding_0.lift_to_interner(interner))
                    }
                }
            }
        }
    };Lift_Generic, const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for BoundTyKind<I>
            where I::DefId: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundTyKind::Anon => {}
                    BoundTyKind::Param(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable)]
1050#[cfg_attr(
1051    feature = "nightly",
1052    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundTyKind<I> where
            I::DefId: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        BoundTyKind::Anon => { 0usize }
                        BoundTyKind::Param(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    BoundTyKind::Anon => {}
                    BoundTyKind::Param(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundTyKind<I> where
            I::DefId: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { BoundTyKind::Anon }
                    1usize => {
                        BoundTyKind::Param(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `BoundTyKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            BoundTyKind<I> where
            I::DefId: ::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 {
                    BoundTyKind::Anon => {}
                    BoundTyKind::Param(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
1053)]
1054pub enum BoundTyKind<I: Interner> {
1055    Anon,
1056    Param(I::DefId),
1057}
1058
1059#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundVariableKind<I> where
    I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundVariableKind<I> where
    I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundVariableKind<I> where
    I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        if ::core::mem::discriminant(self) ==
                ::core::mem::discriminant(__other) {
            match (self, __other) {
                (BoundVariableKind::Ty(ref __field_0),
                    BoundVariableKind::Ty(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                (BoundVariableKind::Region(ref __field_0),
                    BoundVariableKind::Region(ref __other_field_0)) =>
                    true &&
                        ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
                _ => true,
            }
        } else { false }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundVariableKind<I> where
            I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<BoundTyKind<I>>;
                let _: __AssertEq<BoundRegionKind<I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundVariableKind<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundVariableKind<I> where
    I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            BoundVariableKind::Ty(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Ty");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            BoundVariableKind::Region(ref __field_0) => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_tuple(__f, "Region");
                ::core::fmt::DebugTuple::field(&mut __builder, __field_0);
                ::core::fmt::DebugTuple::finish(&mut __builder)
            }
            BoundVariableKind::Const =>
                ::core::fmt::Formatter::write_str(__f, "Const"),
        }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundVariableKind<I> where
    I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundVariableKind::Ty(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
            BoundVariableKind::Region(ref __field_0) => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
                ::core::hash::Hash::hash(__field_0, __state);
            }
            BoundVariableKind::Const => {
                ::core::hash::Hash::hash(&::core::mem::discriminant(self),
                    __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)]
1060#[derive(const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
            BoundVariableKind<I> where J: Interner,
            I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = BoundVariableKind<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    BoundVariableKind::Ty(__binding_0) => {
                        BoundVariableKind::Ty(__binding_0.lift_to_interner(interner))
                    }
                    BoundVariableKind::Region(__binding_0) => {
                        BoundVariableKind::Region(__binding_0.lift_to_interner(interner))
                    }
                    BoundVariableKind::Const => { BoundVariableKind::Const }
                }
            }
        }
    };Lift_Generic, const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for
            BoundVariableKind<I> where
            BoundTyKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V>,
            BoundRegionKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundVariableKind::Ty(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    BoundVariableKind::Region(ref __binding_0) => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                    }
                    BoundVariableKind::Const => {}
                }
            }
        }
    };GenericTypeVisitable)]
1061#[cfg_attr(
1062    feature = "nightly",
1063    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundVariableKind<I> where
            BoundTyKind<I>: ::rustc_serialize::Encodable<__E>,
            BoundRegionKind<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        BoundVariableKind::Ty(ref __binding_0) => { 0usize }
                        BoundVariableKind::Region(ref __binding_0) => { 1usize }
                        BoundVariableKind::Const => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    BoundVariableKind::Ty(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    BoundVariableKind::Region(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    BoundVariableKind::Const => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundVariableKind<I> where
            BoundTyKind<I>: ::rustc_serialize::Decodable<__D>,
            BoundRegionKind<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        BoundVariableKind::Ty(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        BoundVariableKind::Region(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => { BoundVariableKind::Const }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `BoundVariableKind`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            BoundVariableKind<I> where
            BoundTyKind<I>: ::rustc_data_structures::stable_hash::StableHash,
            BoundRegionKind<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 {
                    BoundVariableKind::Ty(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    BoundVariableKind::Region(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    BoundVariableKind::Const => {}
                }
            }
        }
    };StableHash_NoContext)
1064)]
1065pub enum BoundVariableKind<I: Interner> {
1066    Ty(BoundTyKind<I>),
1067    Region(BoundRegionKind<I>),
1068    Const,
1069}
1070
1071impl<I: Interner> BoundVariableKind<I> {
1072    pub fn expect_region(self) -> BoundRegionKind<I> {
1073        match self {
1074            BoundVariableKind::Region(lt) => lt,
1075            _ => {
    ::core::panicking::panic_fmt(format_args!("expected a region, but found another kind"));
}panic!("expected a region, but found another kind"),
1076        }
1077    }
1078
1079    pub fn expect_ty(self) -> BoundTyKind<I> {
1080        match self {
1081            BoundVariableKind::Ty(ty) => ty,
1082            _ => {
    ::core::panicking::panic_fmt(format_args!("expected a type, but found another kind"));
}panic!("expected a type, but found another kind"),
1083        }
1084    }
1085
1086    pub fn expect_const(self) {
1087        match self {
1088            BoundVariableKind::Const => (),
1089            _ => {
    ::core::panicking::panic_fmt(format_args!("expected a const, but found another kind"));
}panic!("expected a const, but found another kind"),
1090        }
1091    }
1092}
1093
1094#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundRegion<I> where I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundRegion<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundRegion<I> where I: Interner
    {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (BoundRegion { var: ref __field_var, kind: ref __field_kind },
                BoundRegion {
                var: ref __other_field_var, kind: ref __other_field_kind }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_var, __other_field_var)
                    &&
                    ::core::cmp::PartialEq::eq(__field_kind,
                        __other_field_kind),
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundRegion<I> where
            I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<ty::BoundVar>;
                let _: __AssertEq<BoundRegionKind<I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundRegion<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundRegion<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundRegion { var: ref __field_var, kind: ref __field_kind } => {
                ::core::hash::Hash::hash(__field_var, __state);
                ::core::hash::Hash::hash(__field_kind, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
1095#[derive(const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for BoundRegion<I>
            where ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
            BoundRegionKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
                        => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundRegion<I>
            where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = BoundRegion<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    BoundRegion { var: __binding_0, kind: __binding_1 } => {
                        BoundRegion {
                            var: __binding_0,
                            kind: __binding_1.lift_to_interner(interner),
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
1096#[cfg_attr(
1097    feature = "nightly",
1098    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundRegion<I> where
            BoundRegionKind<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let BoundRegion { var: ref __binding_0, kind: ref __binding_1
                        } = *self;
                ::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
            BoundRegion<I> where
            BoundRegionKind<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 {
                    BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext, const _: () =
    {
        impl<I: Interner, __D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for BoundRegion<I> where
            BoundRegionKind<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                BoundRegion {
                    var: ::rustc_serialize::Decodable::decode(__decoder),
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext)
1099)]
1100pub struct BoundRegion<I: Interner> {
1101    #[lift(identity)]
1102    pub var: ty::BoundVar,
1103    pub kind: BoundRegionKind<I>,
1104}
1105
1106impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1107    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1108        match self.kind {
1109            BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1110            BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1111            BoundRegionKind::Named(def) => {
1112                f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1113            }
1114            BoundRegionKind::NamedForPrinting(symbol) => {
1115                f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1116            }
1117        }
1118    }
1119}
1120
1121impl<I: Interner> BoundRegion<I> {
1122    pub fn var(self) -> ty::BoundVar {
1123        self.var
1124    }
1125
1126    pub fn assert_eq(self, var: BoundVariableKind<I>) {
1127        {
    match (&self.kind, &var.expect_region()) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
}assert_eq!(self.kind, var.expect_region())
1128    }
1129}
1130
1131pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1132
1133impl<I: Interner> PlaceholderRegion<I> {
1134    pub fn universe(self) -> UniverseIndex {
1135        self.universe
1136    }
1137
1138    pub fn var(self) -> ty::BoundVar {
1139        self.bound.var()
1140    }
1141
1142    pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1143        Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1144    }
1145
1146    pub fn new(ui: UniverseIndex, bound: BoundRegion<I>) -> Self {
1147        Self { universe: ui, bound, _tcx: PhantomData }
1148    }
1149
1150    pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1151        let bound = BoundRegion { var, kind: BoundRegionKind::Anon };
1152        Self { universe: ui, bound, _tcx: PhantomData }
1153    }
1154}
1155
1156#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundTy<I> where I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundTy<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundTy<I> where I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (BoundTy { var: ref __field_var, kind: ref __field_kind },
                BoundTy {
                var: ref __other_field_var, kind: ref __other_field_kind }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_var, __other_field_var)
                    &&
                    ::core::cmp::PartialEq::eq(__field_kind,
                        __other_field_kind),
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundTy<I> where I: Interner
            {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<ty::BoundVar>;
                let _: __AssertEq<BoundTyKind<I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundTy<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundTy<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundTy { var: ref __field_var, kind: ref __field_kind } => {
                ::core::hash::Hash::hash(__field_var, __state);
                ::core::hash::Hash::hash(__field_kind, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
1157#[derive(const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for BoundTy<I> where
            ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
            BoundTyKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable, const _: () =
    {
        impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundTy<I>
            where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
            type Lifted = BoundTy<J>;
            fn lift_to_interner(self, interner: J) -> Self::Lifted {
                match self {
                    BoundTy { var: __binding_0, kind: __binding_1 } => {
                        BoundTy {
                            var: __binding_0,
                            kind: __binding_1.lift_to_interner(interner),
                        }
                    }
                }
            }
        }
    };Lift_Generic)]
1158#[cfg_attr(
1159    feature = "nightly",
1160    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundTy<I> where
            BoundTyKind<I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let BoundTy { var: ref __binding_0, kind: ref __binding_1 } =
                    *self;
                ::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 BoundTy<I> where
            BoundTyKind<I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                BoundTy {
                    var: ::rustc_serialize::Decodable::decode(__decoder),
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            BoundTy<I> where
            BoundTyKind<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 {
                    BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
1161)]
1162pub struct BoundTy<I: Interner> {
1163    #[lift(identity)]
1164    pub var: ty::BoundVar,
1165    pub kind: BoundTyKind<I>,
1166}
1167
1168impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1169    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1170        match self.kind {
1171            ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1172            ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1173        }
1174    }
1175}
1176
1177impl<I: Interner> BoundTy<I> {
1178    pub fn var(self) -> ty::BoundVar {
1179        self.var
1180    }
1181
1182    pub fn assert_eq(self, var: BoundVariableKind<I>) {
1183        {
    match (&self.kind, &var.expect_ty()) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
}assert_eq!(self.kind, var.expect_ty())
1184    }
1185}
1186
1187pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1188
1189impl<I: Interner> PlaceholderType<I> {
1190    pub fn universe(self) -> UniverseIndex {
1191        self.universe
1192    }
1193
1194    pub fn var(self) -> ty::BoundVar {
1195        self.bound.var
1196    }
1197
1198    pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1199        Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1200    }
1201
1202    pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1203        Self { universe: ui, bound, _tcx: PhantomData }
1204    }
1205
1206    pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1207        let bound = BoundTy { var, kind: BoundTyKind::Anon };
1208        Self { universe: ui, bound, _tcx: PhantomData }
1209    }
1210}
1211
1212#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundConst<I> where I: Interner {
    #[inline]
    fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundConst<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundConst<I> where I: Interner {
    #[inline]
    fn eq(&self, __other: &Self) -> ::core::primitive::bool {
        match (self, __other) {
            (BoundConst { var: ref __field_var, _tcx: ref __field__tcx },
                BoundConst {
                var: ref __other_field_var, _tcx: ref __other_field__tcx }) =>
                true &&
                        ::core::cmp::PartialEq::eq(__field_var, __other_field_var)
                    &&
                    ::core::cmp::PartialEq::eq(__field__tcx,
                        __other_field__tcx),
        }
    }
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundConst<I> where I: Interner {
    fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
        -> ::core::fmt::Result {
        match self {
            BoundConst { var: ref __field_var, _tcx: ref __field__tcx } => {
                let mut __builder =
                    ::core::fmt::Formatter::debug_struct(__f, "BoundConst");
                ::core::fmt::DebugStruct::field(&mut __builder, "var",
                    __field_var);
                ::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
            }
        }
    }
}
const _: () =
    {
        trait DeriveWhereAssertEq {
            fn assert(&self);
        }
        impl<I: Interner> DeriveWhereAssertEq for BoundConst<I> where
            I: Interner {
            fn assert(&self) {
                struct __AssertEq<__T: ::core::cmp::Eq +
                    ?::core::marker::Sized>(::core::marker::PhantomData<__T>);
                let _: __AssertEq<ty::BoundVar>;
                let _: __AssertEq<PhantomData<fn() -> I>>;
            }
        }
    };
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundConst<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundConst<I> where I: Interner {
    fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
        match self {
            BoundConst { var: ref __field_var, _tcx: ref __field__tcx } => {
                ::core::hash::Hash::hash(__field_var, __state);
                ::core::hash::Hash::hash(__field__tcx, __state);
            }
        }
    }
}#[derive_where(Clone, Copy, PartialEq, Debug, Eq, Hash; I: Interner)]
1213#[derive(const _: () =
    {
        unsafe impl<I: Interner, __V>
            ::rustc_type_ir::GenericTypeVisitable<__V> for BoundConst<I> where
            ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
            PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
            {
            fn generic_visit_with(&self, __visitor: &mut __V) {
                match *self {
                    BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
                        => {
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
                                __visitor);
                        }
                        {
                            ::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
                                __visitor);
                        }
                    }
                }
            }
        }
    };GenericTypeVisitable)]
1214#[cfg_attr(
1215    feature = "nightly",
1216    derive(const _: () =
    {
        impl<I: Interner, __E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for BoundConst<I> where
            PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let BoundConst { var: ref __binding_0, _tcx: ref __binding_1
                        } = *self;
                ::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 BoundConst<I> where
            PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                BoundConst {
                    var: ::rustc_serialize::Decodable::decode(__decoder),
                    _tcx: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
            BoundConst<I> where
            PhantomData<fn()
                -> 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 {
                    BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash_NoContext)
1217)]
1218pub struct BoundConst<I: Interner> {
1219    pub var: ty::BoundVar,
1220    #[derive_where(skip(Debug))]
1221    pub _tcx: PhantomData<fn() -> I>,
1222}
1223
1224impl<I: Interner> BoundConst<I> {
1225    pub fn var(self) -> ty::BoundVar {
1226        self.var
1227    }
1228
1229    pub fn assert_eq(self, var: BoundVariableKind<I>) {
1230        var.expect_const()
1231    }
1232
1233    pub fn new(var: ty::BoundVar) -> Self {
1234        Self { var, _tcx: PhantomData }
1235    }
1236}
1237
1238pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1239
1240impl<I: Interner> PlaceholderConst<I> {
1241    pub fn universe(self) -> UniverseIndex {
1242        self.universe
1243    }
1244
1245    pub fn var(self) -> ty::BoundVar {
1246        self.bound.var
1247    }
1248
1249    pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1250        Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1251    }
1252
1253    pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1254        Self { universe: ui, bound, _tcx: PhantomData }
1255    }
1256
1257    pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1258        let bound = BoundConst::new(var);
1259        Self { universe: ui, bound, _tcx: PhantomData }
1260    }
1261
1262    pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1263        let mut candidates = env.caller_bounds().filter_map(|clause| {
1264            // `ConstArgHasType` are never desugared to be higher ranked.
1265            match clause.kind().skip_binder() {
1266                ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1267                    if !!(placeholder_ct, ty).has_escaping_bound_vars() {
    ::core::panicking::panic("assertion failed: !(placeholder_ct, ty).has_escaping_bound_vars()")
};assert!(!(placeholder_ct, ty).has_escaping_bound_vars());
1268
1269                    match placeholder_ct.kind() {
1270                        ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1271                            Some(ty)
1272                        }
1273                        _ => None,
1274                    }
1275                }
1276                _ => None,
1277            }
1278        });
1279
1280        // N.B. it may be tempting to fix ICEs by making this function return
1281        // `Option<Ty<'tcx>>` instead of `Ty<'tcx>`; however, this is generally
1282        // considered to be a bandaid solution, since it hides more important
1283        // underlying issues with how we construct generics and predicates of
1284        // items. It's advised to fix the underlying issue rather than trying
1285        // to modify this function.
1286        let ty = candidates.next().unwrap_or_else(|| {
1287            {
    ::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
            self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1288        });
1289        if !candidates.next().is_none() {
    {
        ::core::panicking::panic_fmt(format_args!("did not expect duplicate `ConstParamHasTy` for `{0:?}` in param-env: {1:#?}",
                self, env));
    }
};assert!(
1290            candidates.next().is_none(),
1291            "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1292        );
1293        ty
1294    }
1295}