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, CallerBoundsIterator, Const, DebruijnIndex, Interner, PredicateProxy, Region,
20 UniverseIndex, Unnormalized,
21};
22
23#[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)]
30#[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)]
31#[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))]
32pub struct Binder<I: Interner, T> {
33 value: T,
34 bound_vars: I::BoundVarKinds,
35}
36
37impl<I: Interner, T: Eq> Eq for Binder<I, T> {}
38
39impl<I: Interner, T> Binder<I, T>
40where
41 T: TypeVisitable<I>,
42{
43 #[track_caller]
48 pub fn dummy(value: T) -> Binder<I, T> {
49 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!(
50 !value.has_escaping_bound_vars(),
51 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
52 );
53 Binder { value, bound_vars: Default::default() }
54 }
55
56 pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
57 if truecfg!(debug_assertions) {
58 let mut validator = ValidateBoundVars::new(bound_vars);
59 let _ = value.visit_with(&mut validator);
60 }
61 Binder { value, bound_vars }
62 }
63}
64
65impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
66 fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
67 folder.try_fold_binder(self)
68 }
69
70 fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
71 folder.fold_binder(self)
72 }
73}
74
75impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
76 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
77 visitor.visit_binder(self)
78 }
79}
80
81impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
82 fn try_super_fold_with<F: FallibleTypeFolder<I>>(
83 self,
84 folder: &mut F,
85 ) -> Result<Self, F::Error> {
86 self.try_map_bound(|t| t.try_fold_with(folder))
87 }
88
89 fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
90 self.map_bound(|t| t.fold_with(folder))
91 }
92}
93
94impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
95 fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
96 self.as_ref().skip_binder().visit_with(visitor)
97 }
98}
99
100impl<I: Interner, T> Binder<I, T> {
101 pub fn skip_binder(self) -> T {
115 self.value
116 }
117
118 pub fn bound_vars(&self) -> I::BoundVarKinds {
119 self.bound_vars
120 }
121
122 pub fn as_ref(&self) -> Binder<I, &T> {
123 Binder { value: &self.value, bound_vars: self.bound_vars }
124 }
125
126 pub fn as_deref(&self) -> Binder<I, &T::Target>
127 where
128 T: Deref,
129 {
130 Binder { value: &self.value, bound_vars: self.bound_vars }
131 }
132
133 pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
134 where
135 F: FnOnce(&T) -> U,
136 {
137 self.as_ref().map_bound(f)
138 }
139
140 #[inline]
141 pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
142 where
143 F: FnOnce(T) -> U,
144 {
145 let Binder { value, bound_vars } = self;
146 let value = f(value);
147 if truecfg!(debug_assertions) {
148 let mut validator = ValidateBoundVars::new(bound_vars);
149 let _ = value.visit_with(&mut validator);
150 }
151 Binder { value, bound_vars }
152 }
153
154 #[inline]
158 pub fn map_bound_no_validate_bound_vars<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
159 where
160 F: FnOnce(T) -> U,
161 {
162 let Binder { value, bound_vars } = self;
163 let value = f(value);
164 Binder { value, bound_vars }
165 }
166
167 pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
168 where
169 F: FnOnce(T) -> Result<U, E>,
170 {
171 let Binder { value, bound_vars } = self;
172 let value = f(value)?;
173 if truecfg!(debug_assertions) {
174 let mut validator = ValidateBoundVars::new(bound_vars);
175 let _ = value.visit_with(&mut validator);
176 }
177 Ok(Binder { value, bound_vars })
178 }
179
180 pub fn rebind<U>(&self, value: U) -> Binder<I, U>
190 where
191 U: TypeVisitable<I>,
192 {
193 Binder::bind_with_vars(value, self.bound_vars)
194 }
195
196 pub fn no_bound_vars(self) -> Option<T>
207 where
208 T: TypeVisitable<I>,
209 {
210 if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
212 }
213}
214
215impl<I: Interner, T> Binder<I, Option<T>> {
216 pub fn transpose(self) -> Option<Binder<I, T>> {
217 let Binder { value, bound_vars } = self;
218 value.map(|value| Binder { value, bound_vars })
219 }
220}
221
222impl<I: Interner, T: IntoIterator> Binder<I, T> {
223 pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
224 let Binder { value, bound_vars } = self;
225 value.into_iter().map(move |value| Binder { value, bound_vars })
226 }
227}
228
229pub struct ValidateBoundVars<I: Interner> {
230 bound_vars: I::BoundVarKinds,
231 binder_index: ty::DebruijnIndex,
232 visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
236}
237
238impl<I: Interner> ValidateBoundVars<I> {
239 pub fn new(bound_vars: I::BoundVarKinds) -> Self {
240 ValidateBoundVars {
241 bound_vars,
242 binder_index: ty::INNERMOST,
243 visited: SsoHashSet::default(),
244 }
245 }
246}
247
248impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
249 type Result = ControlFlow<()>;
250
251 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
252 self.binder_index.shift_in(1);
253 let result = t.super_visit_with(self);
254 self.binder_index.shift_out(1);
255 result
256 }
257
258 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
259 if t.outer_exclusive_binder() <= self.binder_index
260 || !self.visited.insert((self.binder_index, t))
261 {
262 return ControlFlow::Continue(());
263 }
264 match t.kind() {
265 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
266 if debruijn == self.binder_index =>
267 {
268 let idx = bound_ty.var().as_usize();
269 let Some(bound_var) = self.bound_vars.get(idx) else {
270 {
::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);
271 };
272 bound_ty.assert_eq(bound_var);
273 }
274 _ => {}
275 };
276
277 t.super_visit_with(self)
278 }
279
280 fn visit_const(&mut self, c: Const<I>) -> Self::Result {
281 if c.outer_exclusive_binder() <= self.binder_index {
282 return ControlFlow::Continue(());
283 }
284 match c.kind() {
285 ty::ConstKind::Bound(debruijn, bound_const)
286 if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
287 {
288 let idx = bound_const.var().as_usize();
289 let Some(bound_var) = self.bound_vars.get(idx) else {
290 {
::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);
291 };
292 bound_const.assert_eq(bound_var);
293 }
294 _ => {}
295 };
296
297 c.super_visit_with(self)
298 }
299
300 fn visit_region(&mut self, r: Region<I>) -> Self::Result {
301 match r.kind() {
302 ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
303 let idx = br.var().as_usize();
304 let Some(bound_var) = self.bound_vars.get(idx) else {
305 {
::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);
306 };
307 br.assert_eq(bound_var);
308 }
309
310 _ => (),
311 };
312
313 ControlFlow::Continue(())
314 }
315}
316
317#[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)]
323#[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)]
324#[cfg_attr(
325 feature = "nightly",
326 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)
327)]
328pub struct EarlyBinder<I: Interner, T> {
329 value: T,
330 #[derive_where(skip(Debug))]
331 _tcx: PhantomData<fn() -> I>,
332}
333
334impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
335
336#[cfg(feature = "nightly")]
338macro_rules! generate { ($( $tt:tt )*) => { $( $tt )* } }
339
340#[cfg(feature = "nightly")]
341generate!(
342 impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
344 impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
346);
347
348impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
349 pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {
350 let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization();
352 EarlyBinder { value, _tcx: PhantomData }
353 }
354}
355
356impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> {
357 pub fn bind_iter(value: T) -> EarlyBinder<I, T> {
358 #[cfg(debug_assertions)]
359 {
360 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()));
361 }
362
363 EarlyBinder { value, _tcx: PhantomData }
364 }
365}
366
367impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> {
368 pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> {
369 if true {
if !!value.has_rigid_aliases() {
::core::panicking::panic("assertion failed: !value.has_rigid_aliases()")
};
};debug_assert!(!value.has_rigid_aliases());
370 EarlyBinder { value, _tcx: PhantomData }
371 }
372}
373
374impl<I: Interner, T> EarlyBinder<I, T> {
375 pub fn bind_unchecked(value: T) -> EarlyBinder<I, T> {
378 EarlyBinder { value, _tcx: PhantomData }
379 }
380}
381
382impl<I: Interner, T> EarlyBinder<I, T> {
383 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
384 EarlyBinder { value: &self.value, _tcx: PhantomData }
385 }
386
387 pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
388 where
389 F: FnOnce(&T) -> U,
390 {
391 self.as_ref().map_bound(f)
392 }
393
394 pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
395 where
396 F: FnOnce(T) -> U,
397 {
398 let value = f(self.value);
399 EarlyBinder { value, _tcx: PhantomData }
400 }
401
402 pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
403 where
404 F: FnOnce(T) -> Result<U, E>,
405 {
406 let value = f(self.value)?;
407 Ok(EarlyBinder { value, _tcx: PhantomData })
408 }
409
410 pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
411 EarlyBinder { value, _tcx: PhantomData }
412 }
413
414 pub fn skip_binder(self) -> T {
431 self.value
432 }
433}
434
435impl<I: Interner> EarlyBinder<I, ty::TraitRef<I>> {
436 pub fn def_id(&self) -> I::TraitId {
437 self.value.def_id
438 }
439}
440
441impl<I: Interner, T> EarlyBinder<I, Option<T>> {
442 pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
443 self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
444 }
445}
446
447impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
448where
449 Iter::Item: TypeFoldable<I>,
450{
451 pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
452 where
453 A: SliceLike<Item = I::GenericArg>,
454 {
455 IterInstantiated { it: self.value.into_iter(), cx, args }
456 }
457
458 pub fn iter_identity(self) -> impl Iterator<Item = Unnormalized<I, Iter::Item>> {
461 self.value.into_iter().map(Unnormalized::new)
462 }
463}
464
465pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
466 it: Iter::IntoIter,
467 cx: I,
468 args: A,
469}
470
471impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
472where
473 Iter::Item: TypeFoldable<I>,
474 A: SliceLike<Item = I::GenericArg>,
475{
476 type Item = Unnormalized<I, Iter::Item>;
477
478 fn next(&mut self) -> Option<Self::Item> {
479 Some(
480 EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
481 .instantiate(self.cx, self.args),
482 )
483 }
484
485 fn size_hint(&self) -> (usize, Option<usize>) {
486 self.it.size_hint()
487 }
488}
489
490impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
491where
492 Iter::IntoIter: DoubleEndedIterator,
493 Iter::Item: TypeFoldable<I>,
494 A: SliceLike<Item = I::GenericArg>,
495{
496 fn next_back(&mut self) -> Option<Self::Item> {
497 Some(
498 EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
499 .instantiate(self.cx, self.args),
500 )
501 }
502}
503
504impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
505where
506 Iter::IntoIter: ExactSizeIterator,
507 Iter::Item: TypeFoldable<I>,
508 A: SliceLike<Item = I::GenericArg>,
509{
510}
511
512impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
513where
514 Iter::Item: Deref,
515 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
516{
517 pub fn iter_instantiated_copied(
518 self,
519 cx: I,
520 args: I::GenericArgs,
521 ) -> IterInstantiatedCopied<I, Iter> {
522 IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
523 }
524
525 pub fn iter_identity_copied(self) -> IterIdentityCopied<I, Iter> {
528 IterIdentityCopied { it: self.value.into_iter(), _tcx: PhantomData }
529 }
530}
531
532pub struct IterInstantiatedCopied<I: Interner, Iter: IntoIterator> {
533 it: Iter::IntoIter,
534 cx: I,
535 args: I::GenericArgs,
536}
537
538impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterInstantiatedCopied<I, Iter> {
539 fn clone(&self) -> IterInstantiatedCopied<I, Iter> {
540 IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args }
541 }
542}
543
544impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<I, Iter>
545where
546 Iter::Item: Deref,
547 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
548{
549 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
550
551 fn next(&mut self) -> Option<Self::Item> {
552 self.it.next().map(|value| {
553 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
554 })
555 }
556
557 fn size_hint(&self) -> (usize, Option<usize>) {
558 self.it.size_hint()
559 }
560}
561
562impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<I, Iter>
563where
564 Iter::IntoIter: DoubleEndedIterator,
565 Iter::Item: Deref,
566 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
567{
568 fn next_back(&mut self) -> Option<Self::Item> {
569 self.it.next_back().map(|value| {
570 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
571 })
572 }
573}
574
575impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<I, Iter>
576where
577 Iter::IntoIter: ExactSizeIterator,
578 Iter::Item: Deref,
579 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
580{
581}
582
583pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
584 it: Iter::IntoIter,
585 _tcx: PhantomData<fn() -> I>,
586}
587
588impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> {
589 fn clone(&self) -> IterIdentityCopied<I, Iter> {
590 IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx }
591 }
592}
593
594impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
595where
596 Iter::Item: Deref,
597 <Iter::Item as Deref>::Target: Copy,
598{
599 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
600
601 fn next(&mut self) -> Option<Self::Item> {
602 self.it.next().map(|i| Unnormalized::new(*i))
603 }
604
605 fn size_hint(&self) -> (usize, Option<usize>) {
606 self.it.size_hint()
607 }
608}
609
610impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<I, Iter>
611where
612 Iter::IntoIter: DoubleEndedIterator,
613 Iter::Item: Deref,
614 <Iter::Item as Deref>::Target: Copy,
615{
616 fn next_back(&mut self) -> Option<Self::Item> {
617 self.it.next_back().map(|i| Unnormalized::new(*i))
618 }
619}
620
621impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<I, Iter>
622where
623 Iter::IntoIter: ExactSizeIterator,
624 Iter::Item: Deref,
625 <Iter::Item as Deref>::Target: Copy,
626{
627}
628pub struct EarlyBinderIter<I, T> {
629 t: T,
630 _tcx: PhantomData<I>,
631}
632
633impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
634 pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
635 EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
636 }
637}
638
639impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
640 type Item = EarlyBinder<I, T::Item>;
641
642 fn next(&mut self) -> Option<Self::Item> {
643 self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
644 }
645
646 fn size_hint(&self) -> (usize, Option<usize>) {
647 self.t.size_hint()
648 }
649}
650
651impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
652 pub fn instantiate<A>(self, cx: I, args: A) -> Unnormalized<I, T>
653 where
654 A: SliceLike<Item = I::GenericArg>,
655 {
656 if args.is_empty() {
660 if !!self.value.has_param() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
self.value));
}
};assert!(
661 !self.value.has_param(),
662 "{:?} has parameters, but no args were provided in instantiate",
663 self.value,
664 );
665 return Unnormalized::new(self.value);
666 }
667 let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
668 Unnormalized::new(self.value.fold_with(&mut folder))
669 }
670
671 pub fn instantiate_identity(self) -> Unnormalized<I, T> {
680 Unnormalized::new(self.value)
689 }
690
691 pub fn no_bound_vars(self) -> Option<T> {
693 if !self.value.has_param() { Some(self.value) } else { None }
694 }
695}
696
697struct ArgFolder<'a, I: Interner> {
701 cx: I,
702 args: &'a [I::GenericArg],
703
704 binders_passed: u32,
706}
707
708impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
709 #[inline]
710 fn cx(&self) -> I {
711 self.cx
712 }
713
714 fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
715 self.binders_passed += 1;
716 let t = t.super_fold_with(self);
717 self.binders_passed -= 1;
718 t
719 }
720
721 fn fold_region(&mut self, r: Region<I>) -> Region<I> {
722 match r.kind() {
728 ty::ReEarlyParam(data) => {
729 let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
730 match rk {
731 Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
732 Some(other) => self.region_param_expected(data, r, other),
733 None => self.region_param_out_of_range(data, r),
734 }
735 }
736 ty::ReBound(..)
737 | ty::ReLateParam(_)
738 | ty::ReStatic
739 | ty::RePlaceholder(_)
740 | ty::ReErased
741 | ty::ReError(_) => r,
742 ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
743 }
744 }
745
746 fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
747 if !t.has_param() {
748 return t;
749 }
750
751 match t.kind() {
752 ty::Param(p) => self.ty_for_param(p, t),
753 _ => t.super_fold_with(self),
754 }
755 }
756
757 fn fold_const(&mut self, c: Const<I>) -> Const<I> {
758 if let ty::ConstKind::Param(p) = c.kind() {
759 self.const_for_param(p, c)
760 } else {
761 c.super_fold_with(self)
762 }
763 }
764
765 fn fold_predicate<P: PredicateProxy<I>>(&mut self, p: P) -> P {
766 if p.has_param() { p.super_fold_with(self) } else { p }
767 }
768
769 fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
770 if c.has_param() { c.super_fold_with(self) } else { c }
771 }
772}
773
774impl<'a, I: Interner> ArgFolder<'a, I> {
775 fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
776 let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
778 let ty = match opt_ty {
779 Some(ty::GenericArgKind::Type(ty)) => ty,
780 Some(kind) => self.type_param_expected(p, source_ty, kind),
781 None => self.type_param_out_of_range(p, source_ty),
782 };
783
784 self.shift_vars_through_binders(ty)
785 }
786
787 #[cold]
788 #[inline(never)]
789 fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
790 {
::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!(
791 "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
792 p,
793 ty,
794 p.index(),
795 kind,
796 self.args,
797 )
798 }
799
800 #[cold]
801 #[inline(never)]
802 fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
803 {
::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!(
804 "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
805 p,
806 ty,
807 p.index(),
808 self.args,
809 )
810 }
811
812 fn const_for_param(&self, p: I::ParamConst, source_ct: Const<I>) -> Const<I> {
813 let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
815 let ct = match opt_ct {
816 Some(ty::GenericArgKind::Const(ct)) => ct,
817 Some(kind) => self.const_param_expected(p, source_ct, kind),
818 None => self.const_param_out_of_range(p, source_ct),
819 };
820
821 self.shift_vars_through_binders(ct)
822 }
823
824 #[cold]
825 #[inline(never)]
826 fn const_param_expected(
827 &self,
828 p: I::ParamConst,
829 ct: Const<I>,
830 kind: ty::GenericArgKind<I>,
831 ) -> ! {
832 {
::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!(
833 "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
834 p,
835 ct,
836 p.index(),
837 kind,
838 self.args,
839 )
840 }
841
842 #[cold]
843 #[inline(never)]
844 fn const_param_out_of_range(&self, p: I::ParamConst, ct: Const<I>) -> ! {
845 {
::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!(
846 "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
847 p,
848 ct,
849 p.index(),
850 self.args,
851 )
852 }
853
854 #[cold]
855 #[inline(never)]
856 fn region_param_expected(
857 &self,
858 ebr: I::EarlyParamRegion,
859 r: Region<I>,
860 kind: ty::GenericArgKind<I>,
861 ) -> ! {
862 {
::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!(
863 "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
864 ebr,
865 r,
866 ebr.index(),
867 kind,
868 self.args,
869 )
870 }
871
872 #[cold]
873 #[inline(never)]
874 fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: Region<I>) -> ! {
875 {
::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!(
876 "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
877 ebr,
878 r,
879 ebr.index(),
880 self.args,
881 )
882 }
883
884 {}
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/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_type_ir/src/binder.rs"),
::tracing_core::__macro_support::Option::Some(926u32),
::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/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_type_ir/src/binder.rs:926",
"rustc_type_ir::binder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_type_ir/src/binder.rs"),
::tracing_core::__macro_support::Option::Some(926u32),
::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)]
927 fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
928 if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
929 val
930 } else {
931 ty::shift_vars(self.cx, val, self.binders_passed)
932 }
933 }
934
935 fn shift_region_through_binders(&self, region: Region<I>) -> Region<I> {
936 if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
937 region
938 } else {
939 ty::shift_region(self.cx, region, self.binders_passed)
940 }
941 }
942}
943
944#[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_struct_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)]
964#[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) {
match *self {
BoundVarIndexKind::Bound(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
BoundVarIndexKind::Canonical =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
BoundVarIndexKind::Bound(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
BoundVarIndexKind::Canonical => {}
}
}
}
};StableHash))]
965#[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)]
966pub enum BoundVarIndexKind {
967 Bound(DebruijnIndex),
968 Canonical,
969}
970
971#[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)]
975#[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)]
976#[cfg_attr(
977 feature = "nightly",
978 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)
979)]
980pub struct Placeholder<I: Interner, T> {
981 #[lift(identity)]
982 pub universe: UniverseIndex,
983 pub bound: T,
984 #[type_foldable(identity)]
985 #[type_visitable(ignore)]
986 _tcx: PhantomData<fn() -> I>,
987}
988
989impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
990 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
991 if self.universe == ty::UniverseIndex::ROOT {
992 f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
993 } else {
994 f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
995 }
996 }
997}
998
999#[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)]
1000#[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)]
1001#[cfg_attr(
1002 feature = "nightly",
1003 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) {
match *self {
BoundRegionKind::Anon => 0u8.stable_hash(__hcx, __hasher),
BoundRegionKind::NamedForPrinting(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
BoundRegionKind::Named(ref __binding_0) =>
2u8.stable_hash(__hcx, __hasher),
BoundRegionKind::ClosureEnv =>
3u8.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)
1004)]
1005pub enum BoundRegionKind<I: Interner> {
1006 Anon,
1008
1009 NamedForPrinting(I::Symbol),
1013
1014 Named(I::DefId),
1016
1017 ClosureEnv,
1020}
1021
1022impl<I: Interner> fmt::Debug for ty::BoundRegionKind<I> {
1023 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1024 match *self {
1025 ty::BoundRegionKind::Anon => f.write_fmt(format_args!("BrAnon"))write!(f, "BrAnon"),
1026 ty::BoundRegionKind::NamedForPrinting(name) => {
1027 f.write_fmt(format_args!("BrNamedForPrinting({0:?})", name))write!(f, "BrNamedForPrinting({:?})", name)
1028 }
1029 ty::BoundRegionKind::Named(did) => {
1030 f.write_fmt(format_args!("BrNamed({0:?})", did))write!(f, "BrNamed({did:?})")
1031 }
1032 ty::BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("BrEnv"))write!(f, "BrEnv"),
1033 }
1034 }
1035}
1036
1037impl<I: Interner> BoundRegionKind<I> {
1038 pub fn is_named(&self, tcx: I) -> bool {
1039 self.get_name(tcx).is_some()
1040 }
1041
1042 pub fn get_name(&self, tcx: I) -> Option<I::Symbol> {
1043 match *self {
1044 ty::BoundRegionKind::Named(def_id) => {
1045 let name = tcx.item_name(def_id);
1046 if name == I::Symbol::KW_UNDERSCORE_LIFETIME { None } else { Some(name) }
1047 }
1048 ty::BoundRegionKind::NamedForPrinting(name) => Some(name),
1049 _ => None,
1050 }
1051 }
1052
1053 pub fn get_id(&self) -> Option<I::DefId> {
1054 match *self {
1055 ty::BoundRegionKind::Named(id) => Some(id),
1056 _ => None,
1057 }
1058 }
1059}
1060
1061#[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)]
1062#[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)]
1063#[cfg_attr(
1064 feature = "nightly",
1065 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) {
match *self {
BoundTyKind::Anon => 0u8.stable_hash(__hcx, __hasher),
BoundTyKind::Param(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
BoundTyKind::Anon => {}
BoundTyKind::Param(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
1066)]
1067pub enum BoundTyKind<I: Interner> {
1068 Anon,
1069 Param(I::DefId),
1070}
1071
1072#[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)]
1073#[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)]
1074#[cfg_attr(
1075 feature = "nightly",
1076 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) {
match *self {
BoundVariableKind::Ty(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
BoundVariableKind::Region(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
BoundVariableKind::Const =>
2u8.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)
1077)]
1078pub enum BoundVariableKind<I: Interner> {
1079 Ty(BoundTyKind<I>),
1080 Region(BoundRegionKind<I>),
1081 Const,
1082}
1083
1084impl<I: Interner> BoundVariableKind<I> {
1085 pub fn expect_region(self) -> BoundRegionKind<I> {
1086 match self {
1087 BoundVariableKind::Region(lt) => lt,
1088 _ => {
::core::panicking::panic_fmt(format_args!("expected a region, but found another kind"));
}panic!("expected a region, but found another kind"),
1089 }
1090 }
1091
1092 pub fn expect_ty(self) -> BoundTyKind<I> {
1093 match self {
1094 BoundVariableKind::Ty(ty) => ty,
1095 _ => {
::core::panicking::panic_fmt(format_args!("expected a type, but found another kind"));
}panic!("expected a type, but found another kind"),
1096 }
1097 }
1098
1099 pub fn expect_const(self) {
1100 match self {
1101 BoundVariableKind::Const => (),
1102 _ => {
::core::panicking::panic_fmt(format_args!("expected a const, but found another kind"));
}panic!("expected a const, but found another kind"),
1103 }
1104 }
1105}
1106
1107#[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)]
1108#[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)]
1109#[cfg_attr(
1110 feature = "nightly",
1111 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)
1112)]
1113pub struct BoundRegion<I: Interner> {
1114 #[lift(identity)]
1115 pub var: ty::BoundVar,
1116 pub kind: BoundRegionKind<I>,
1117}
1118
1119impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1121 match self.kind {
1122 BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1123 BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1124 BoundRegionKind::Named(def) => {
1125 f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1126 }
1127 BoundRegionKind::NamedForPrinting(symbol) => {
1128 f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1129 }
1130 }
1131 }
1132}
1133
1134impl<I: Interner> BoundRegion<I> {
1135 pub fn var(self) -> ty::BoundVar {
1136 self.var
1137 }
1138
1139 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1140 {
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())
1141 }
1142}
1143
1144pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1145
1146impl<I: Interner> PlaceholderRegion<I> {
1147 pub fn universe(self) -> UniverseIndex {
1148 self.universe
1149 }
1150
1151 pub fn var(self) -> ty::BoundVar {
1152 self.bound.var()
1153 }
1154
1155 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1156 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1157 }
1158
1159 pub fn new(ui: UniverseIndex, bound: BoundRegion<I>) -> Self {
1160 Self { universe: ui, bound, _tcx: PhantomData }
1161 }
1162
1163 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1164 let bound = BoundRegion { var, kind: BoundRegionKind::Anon };
1165 Self { universe: ui, bound, _tcx: PhantomData }
1166 }
1167}
1168
1169#[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)]
1170#[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)]
1171#[cfg_attr(
1172 feature = "nightly",
1173 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)
1174)]
1175pub struct BoundTy<I: Interner> {
1176 #[lift(identity)]
1177 pub var: ty::BoundVar,
1178 pub kind: BoundTyKind<I>,
1179}
1180
1181impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1182 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1183 match self.kind {
1184 ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1185 ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1186 }
1187 }
1188}
1189
1190impl<I: Interner> BoundTy<I> {
1191 pub fn var(self) -> ty::BoundVar {
1192 self.var
1193 }
1194
1195 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1196 {
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())
1197 }
1198}
1199
1200pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1201
1202impl<I: Interner> PlaceholderType<I> {
1203 pub fn universe(self) -> UniverseIndex {
1204 self.universe
1205 }
1206
1207 pub fn var(self) -> ty::BoundVar {
1208 self.bound.var
1209 }
1210
1211 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1212 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1213 }
1214
1215 pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1216 Self { universe: ui, bound, _tcx: PhantomData }
1217 }
1218
1219 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1220 let bound = BoundTy { var, kind: BoundTyKind::Anon };
1221 Self { universe: ui, bound, _tcx: PhantomData }
1222 }
1223}
1224
1225#[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)]
1226#[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)]
1227#[cfg_attr(
1228 feature = "nightly",
1229 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)
1230)]
1231pub struct BoundConst<I: Interner> {
1232 pub var: ty::BoundVar,
1233 #[derive_where(skip(Debug))]
1234 pub _tcx: PhantomData<fn() -> I>,
1235}
1236
1237impl<I: Interner> BoundConst<I> {
1238 pub fn var(self) -> ty::BoundVar {
1239 self.var
1240 }
1241
1242 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1243 var.expect_const()
1244 }
1245
1246 pub fn new(var: ty::BoundVar) -> Self {
1247 Self { var, _tcx: PhantomData }
1248 }
1249}
1250
1251pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1252
1253impl<I: Interner> PlaceholderConst<I> {
1254 pub fn universe(self) -> UniverseIndex {
1255 self.universe
1256 }
1257
1258 pub fn var(self) -> ty::BoundVar {
1259 self.bound.var
1260 }
1261
1262 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1263 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1264 }
1265
1266 pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1267 Self { universe: ui, bound, _tcx: PhantomData }
1268 }
1269
1270 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1271 let bound = BoundConst::new(var);
1272 Self { universe: ui, bound, _tcx: PhantomData }
1273 }
1274
1275 pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1276 let mut candidates = env.caller_bounds().non_trait_clauses().iter().filter_map(|clause| {
1277 match clause.kind().skip_binder() {
1279 ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1280 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());
1281
1282 match placeholder_ct.kind() {
1283 ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1284 Some(ty)
1285 }
1286 _ => None,
1287 }
1288 }
1289 _ => None,
1290 }
1291 });
1292
1293 let ty = candidates.next().unwrap_or_else(|| {
1300 {
::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1301 });
1302 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!(
1303 candidates.next().is_none(),
1304 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1305 );
1306 ty
1307 }
1308}