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::{self as ty, DebruijnIndex, Interner, UniverseIndex, Unnormalized};
19
20#[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(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
38#[cfg(feature = "nightly")]
39macro_rules! impl_binder_encode_decode {
40 ($($t:ty),+ $(,)?) => {
41 $(
42 impl<I: Interner, E: rustc_serialize::Encoder> rustc_serialize::Encodable<E> for ty::Binder<I, $t>
43 where
44 $t: rustc_serialize::Encodable<E>,
45 I::BoundVarKinds: rustc_serialize::Encodable<E>,
46 {
47 fn encode(&self, e: &mut E) {
48 self.bound_vars().encode(e);
49 self.as_ref().skip_binder().encode(e);
50 }
51 }
52 impl<I: Interner, D: rustc_serialize::Decoder> rustc_serialize::Decodable<D> for ty::Binder<I, $t>
53 where
54 $t: TypeVisitable<I> + rustc_serialize::Decodable<D>,
55 I::BoundVarKinds: rustc_serialize::Decodable<D>,
56 {
57 fn decode(decoder: &mut D) -> Self {
58 let bound_vars = rustc_serialize::Decodable::decode(decoder);
59 ty::Binder::bind_with_vars(rustc_serialize::Decodable::decode(decoder), bound_vars)
60 }
61 }
62 )*
63 }
64}
65
66#[cfg(feature = "nightly")]
67impl<I: Interner, E: rustc_serialize::Encoder> rustc_serialize::Encodable<E>
for ty::Binder<I, ty::HostEffectPredicate<I>> where
ty::HostEffectPredicate<I>: rustc_serialize::Encodable<E>,
I::BoundVarKinds: rustc_serialize::Encodable<E> {
fn encode(&self, e: &mut E) {
self.bound_vars().encode(e);
self.as_ref().skip_binder().encode(e);
}
}
impl<I: Interner, D: rustc_serialize::Decoder> rustc_serialize::Decodable<D>
for ty::Binder<I, ty::HostEffectPredicate<I>> where
ty::HostEffectPredicate<I>: TypeVisitable<I> +
rustc_serialize::Decodable<D>,
I::BoundVarKinds: rustc_serialize::Decodable<D> {
fn decode(decoder: &mut D) -> Self {
let bound_vars = rustc_serialize::Decodable::decode(decoder);
ty::Binder::bind_with_vars(rustc_serialize::Decodable::decode(decoder),
bound_vars)
}
}impl_binder_encode_decode! {
68 ty::FnSig<I>,
69 ty::FnSigTys<I>,
70 ty::TraitPredicate<I>,
71 ty::ExistentialPredicate<I>,
72 ty::TraitRef<I>,
73 ty::ExistentialTraitRef<I>,
74 ty::HostEffectPredicate<I>,
75}
76
77#[cfg(feature = "nightly")]
78impl<T: GenericArgs<I>, I: Interner<GenericArgs = T>, E: rustc_serialize::Encoder>
79 rustc_serialize::Encodable<E> for ty::Binder<I, T>
80where
81 T: rustc_serialize::Encodable<E>,
82 I::BoundVarKinds: rustc_serialize::Encodable<E>,
83{
84 fn encode(&self, e: &mut E) {
85 self.bound_vars().encode(e);
86 self.as_ref().skip_binder().encode(e);
87 }
88}
89
90#[cfg(feature = "nightly")]
91impl<T: GenericArgs<I>, I: Interner<GenericArgs = T>, D: rustc_serialize::Decoder>
92 rustc_serialize::Decodable<D> for ty::Binder<I, T>
93where
94 T: TypeVisitable<I> + rustc_serialize::Decodable<D>,
95 I::BoundVarKinds: rustc_serialize::Decodable<D>,
96{
97 fn decode(decoder: &mut D) -> Self {
98 let bound_vars = rustc_serialize::Decodable::decode(decoder);
99 ty::Binder::bind_with_vars(rustc_serialize::Decodable::decode(decoder), bound_vars)
100 }
101}
102
103impl<I: Interner, T> Binder<I, T>
104where
105 T: TypeVisitable<I>,
106{
107 #[track_caller]
112 pub fn dummy(value: T) -> Binder<I, T> {
113 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!(
114 !value.has_escaping_bound_vars(),
115 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
116 );
117 Binder { value, bound_vars: Default::default() }
118 }
119
120 pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
121 if truecfg!(debug_assertions) {
122 let mut validator = ValidateBoundVars::new(bound_vars);
123 let _ = value.visit_with(&mut validator);
124 }
125 Binder { value, bound_vars }
126 }
127}
128
129impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
130 fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
131 folder.try_fold_binder(self)
132 }
133
134 fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
135 folder.fold_binder(self)
136 }
137}
138
139impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
140 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
141 visitor.visit_binder(self)
142 }
143}
144
145impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
146 fn try_super_fold_with<F: FallibleTypeFolder<I>>(
147 self,
148 folder: &mut F,
149 ) -> Result<Self, F::Error> {
150 self.try_map_bound(|t| t.try_fold_with(folder))
151 }
152
153 fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
154 self.map_bound(|t| t.fold_with(folder))
155 }
156}
157
158impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
159 fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
160 self.as_ref().skip_binder().visit_with(visitor)
161 }
162}
163
164impl<I: Interner, T> Binder<I, T> {
165 pub fn skip_binder(self) -> T {
179 self.value
180 }
181
182 pub fn bound_vars(&self) -> I::BoundVarKinds {
183 self.bound_vars
184 }
185
186 pub fn as_ref(&self) -> Binder<I, &T> {
187 Binder { value: &self.value, bound_vars: self.bound_vars }
188 }
189
190 pub fn as_deref(&self) -> Binder<I, &T::Target>
191 where
192 T: Deref,
193 {
194 Binder { value: &self.value, bound_vars: self.bound_vars }
195 }
196
197 pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
198 where
199 F: FnOnce(&T) -> U,
200 {
201 self.as_ref().map_bound(f)
202 }
203
204 pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
205 where
206 F: FnOnce(T) -> U,
207 {
208 let Binder { value, bound_vars } = self;
209 let value = f(value);
210 if truecfg!(debug_assertions) {
211 let mut validator = ValidateBoundVars::new(bound_vars);
212 let _ = value.visit_with(&mut validator);
213 }
214 Binder { value, bound_vars }
215 }
216
217 pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
218 where
219 F: FnOnce(T) -> Result<U, E>,
220 {
221 let Binder { value, bound_vars } = self;
222 let value = f(value)?;
223 if truecfg!(debug_assertions) {
224 let mut validator = ValidateBoundVars::new(bound_vars);
225 let _ = value.visit_with(&mut validator);
226 }
227 Ok(Binder { value, bound_vars })
228 }
229
230 pub fn rebind<U>(&self, value: U) -> Binder<I, U>
240 where
241 U: TypeVisitable<I>,
242 {
243 Binder::bind_with_vars(value, self.bound_vars)
244 }
245
246 pub fn no_bound_vars(self) -> Option<T>
257 where
258 T: TypeVisitable<I>,
259 {
260 if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
262 }
263}
264
265impl<I: Interner, T> Binder<I, Option<T>> {
266 pub fn transpose(self) -> Option<Binder<I, T>> {
267 let Binder { value, bound_vars } = self;
268 value.map(|value| Binder { value, bound_vars })
269 }
270}
271
272impl<I: Interner, T: IntoIterator> Binder<I, T> {
273 pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
274 let Binder { value, bound_vars } = self;
275 value.into_iter().map(move |value| Binder { value, bound_vars })
276 }
277}
278
279pub struct ValidateBoundVars<I: Interner> {
280 bound_vars: I::BoundVarKinds,
281 binder_index: ty::DebruijnIndex,
282 visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
286}
287
288impl<I: Interner> ValidateBoundVars<I> {
289 pub fn new(bound_vars: I::BoundVarKinds) -> Self {
290 ValidateBoundVars {
291 bound_vars,
292 binder_index: ty::INNERMOST,
293 visited: SsoHashSet::default(),
294 }
295 }
296}
297
298impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
299 type Result = ControlFlow<()>;
300
301 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
302 self.binder_index.shift_in(1);
303 let result = t.super_visit_with(self);
304 self.binder_index.shift_out(1);
305 result
306 }
307
308 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
309 if t.outer_exclusive_binder() < self.binder_index
310 || !self.visited.insert((self.binder_index, t))
311 {
312 return ControlFlow::Break(());
313 }
314 match t.kind() {
315 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
316 if debruijn == self.binder_index =>
317 {
318 let idx = bound_ty.var().as_usize();
319 if self.bound_vars.len() <= idx {
320 {
::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);
321 }
322 bound_ty.assert_eq(self.bound_vars.get(idx).unwrap());
323 }
324 _ => {}
325 };
326
327 t.super_visit_with(self)
328 }
329
330 fn visit_const(&mut self, c: I::Const) -> Self::Result {
331 if c.outer_exclusive_binder() < self.binder_index {
332 return ControlFlow::Break(());
333 }
334 match c.kind() {
335 ty::ConstKind::Bound(debruijn, bound_const)
336 if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
337 {
338 let idx = bound_const.var().as_usize();
339 if self.bound_vars.len() <= idx {
340 {
::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);
341 }
342 bound_const.assert_eq(self.bound_vars.get(idx).unwrap());
343 }
344 _ => {}
345 };
346
347 c.super_visit_with(self)
348 }
349
350 fn visit_region(&mut self, r: I::Region) -> Self::Result {
351 match r.kind() {
352 ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
353 let idx = br.var().as_usize();
354 if self.bound_vars.len() <= idx {
355 {
::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);
356 }
357 br.assert_eq(self.bound_vars.get(idx).unwrap());
358 }
359
360 _ => (),
361 };
362
363 ControlFlow::Continue(())
364 }
365}
366
367#[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)]
373#[derive(GenericTypeVisitable)]
374#[cfg_attr(
375 feature = "nightly",
376 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) {
match *self {
EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
} => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, 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)
377)]
378pub struct EarlyBinder<I: Interner, T> {
379 value: T,
380 #[derive_where(skip(Debug))]
381 _tcx: PhantomData<fn() -> I>,
382}
383
384impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
385
386#[cfg(feature = "nightly")]
388macro_rules! generate { ($( $tt:tt )*) => { $( $tt )* } }
389
390#[cfg(feature = "nightly")]
391generate!(
392 impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
394 impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
396);
397
398impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
399 pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {
400 let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization();
402 EarlyBinder { value, _tcx: PhantomData }
403 }
404}
405
406impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> {
407 pub fn bind_iter(value: T) -> EarlyBinder<I, T> {
408 #[cfg(debug_assertions)]
409 {
410 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()));
411 }
412
413 EarlyBinder { value, _tcx: PhantomData }
414 }
415}
416
417impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> {
418 pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> {
419 if true {
if !!value.has_rigid_aliases() {
::core::panicking::panic("assertion failed: !value.has_rigid_aliases()")
};
};debug_assert!(!value.has_rigid_aliases());
420 EarlyBinder { value, _tcx: PhantomData }
421 }
422}
423
424impl<I: Interner, T> EarlyBinder<I, T> {
425 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
426 EarlyBinder { value: &self.value, _tcx: PhantomData }
427 }
428
429 pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
430 where
431 F: FnOnce(&T) -> U,
432 {
433 self.as_ref().map_bound(f)
434 }
435
436 pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
437 where
438 F: FnOnce(T) -> U,
439 {
440 let value = f(self.value);
441 EarlyBinder { value, _tcx: PhantomData }
442 }
443
444 pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
445 where
446 F: FnOnce(T) -> Result<U, E>,
447 {
448 let value = f(self.value)?;
449 Ok(EarlyBinder { value, _tcx: PhantomData })
450 }
451
452 pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
453 EarlyBinder { value, _tcx: PhantomData }
454 }
455
456 pub fn skip_binder(self) -> T {
473 self.value
474 }
475}
476
477impl<I: Interner> EarlyBinder<I, ty::TraitRef<I>> {
478 pub fn def_id(&self) -> I::TraitId {
479 self.value.def_id
480 }
481}
482
483impl<I: Interner, T> EarlyBinder<I, Option<T>> {
484 pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
485 self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
486 }
487}
488
489impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
490where
491 Iter::Item: TypeFoldable<I>,
492{
493 pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
494 where
495 A: SliceLike<Item = I::GenericArg>,
496 {
497 IterInstantiated { it: self.value.into_iter(), cx, args }
498 }
499
500 pub fn iter_identity(self) -> impl Iterator<Item = Unnormalized<I, Iter::Item>> {
503 self.value.into_iter().map(Unnormalized::new)
504 }
505}
506
507pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
508 it: Iter::IntoIter,
509 cx: I,
510 args: A,
511}
512
513impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
514where
515 Iter::Item: TypeFoldable<I>,
516 A: SliceLike<Item = I::GenericArg>,
517{
518 type Item = Unnormalized<I, Iter::Item>;
519
520 fn next(&mut self) -> Option<Self::Item> {
521 Some(
522 EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
523 .instantiate(self.cx, self.args),
524 )
525 }
526
527 fn size_hint(&self) -> (usize, Option<usize>) {
528 self.it.size_hint()
529 }
530}
531
532impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
533where
534 Iter::IntoIter: DoubleEndedIterator,
535 Iter::Item: TypeFoldable<I>,
536 A: SliceLike<Item = I::GenericArg>,
537{
538 fn next_back(&mut self) -> Option<Self::Item> {
539 Some(
540 EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
541 .instantiate(self.cx, self.args),
542 )
543 }
544}
545
546impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
547where
548 Iter::IntoIter: ExactSizeIterator,
549 Iter::Item: TypeFoldable<I>,
550 A: SliceLike<Item = I::GenericArg>,
551{
552}
553
554impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
555where
556 Iter::Item: Deref,
557 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
558{
559 pub fn iter_instantiated_copied(
560 self,
561 cx: I,
562 args: &'s [I::GenericArg],
563 ) -> IterInstantiatedCopied<'s, I, Iter> {
564 IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
565 }
566
567 pub fn iter_identity_copied(self) -> IterIdentityCopied<I, Iter> {
570 IterIdentityCopied { it: self.value.into_iter(), _tcx: PhantomData }
571 }
572}
573
574pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
575 it: Iter::IntoIter,
576 cx: I,
577 args: &'a [I::GenericArg],
578}
579
580impl<'a, I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone
581 for IterInstantiatedCopied<'a, I, Iter>
582{
583 fn clone(&self) -> IterInstantiatedCopied<'a, I, Iter> {
584 IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args }
585 }
586}
587
588impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
589where
590 Iter::Item: Deref,
591 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
592{
593 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
594
595 fn next(&mut self) -> Option<Self::Item> {
596 self.it.next().map(|value| {
597 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
598 })
599 }
600
601 fn size_hint(&self) -> (usize, Option<usize>) {
602 self.it.size_hint()
603 }
604}
605
606impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, I, Iter>
607where
608 Iter::IntoIter: DoubleEndedIterator,
609 Iter::Item: Deref,
610 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
611{
612 fn next_back(&mut self) -> Option<Self::Item> {
613 self.it.next_back().map(|value| {
614 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
615 })
616 }
617}
618
619impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, I, Iter>
620where
621 Iter::IntoIter: ExactSizeIterator,
622 Iter::Item: Deref,
623 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
624{
625}
626
627pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
628 it: Iter::IntoIter,
629 _tcx: PhantomData<fn() -> I>,
630}
631
632impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> {
633 fn clone(&self) -> IterIdentityCopied<I, Iter> {
634 IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx }
635 }
636}
637
638impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
639where
640 Iter::Item: Deref,
641 <Iter::Item as Deref>::Target: Copy,
642{
643 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
644
645 fn next(&mut self) -> Option<Self::Item> {
646 self.it.next().map(|i| Unnormalized::new(*i))
647 }
648
649 fn size_hint(&self) -> (usize, Option<usize>) {
650 self.it.size_hint()
651 }
652}
653
654impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<I, Iter>
655where
656 Iter::IntoIter: DoubleEndedIterator,
657 Iter::Item: Deref,
658 <Iter::Item as Deref>::Target: Copy,
659{
660 fn next_back(&mut self) -> Option<Self::Item> {
661 self.it.next_back().map(|i| Unnormalized::new(*i))
662 }
663}
664
665impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<I, Iter>
666where
667 Iter::IntoIter: ExactSizeIterator,
668 Iter::Item: Deref,
669 <Iter::Item as Deref>::Target: Copy,
670{
671}
672pub struct EarlyBinderIter<I, T> {
673 t: T,
674 _tcx: PhantomData<I>,
675}
676
677impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
678 pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
679 EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
680 }
681}
682
683impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
684 type Item = EarlyBinder<I, T::Item>;
685
686 fn next(&mut self) -> Option<Self::Item> {
687 self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
688 }
689
690 fn size_hint(&self) -> (usize, Option<usize>) {
691 self.t.size_hint()
692 }
693}
694
695impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
696 pub fn instantiate<A>(self, cx: I, args: A) -> Unnormalized<I, T>
697 where
698 A: SliceLike<Item = I::GenericArg>,
699 {
700 if args.is_empty() {
704 if !!self.value.has_param() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
self.value));
}
};assert!(
705 !self.value.has_param(),
706 "{:?} has parameters, but no args were provided in instantiate",
707 self.value,
708 );
709 return Unnormalized::new(self.value);
710 }
711 let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
712 Unnormalized::new(self.value.fold_with(&mut folder))
713 }
714
715 pub fn instantiate_identity(self) -> Unnormalized<I, T> {
724 Unnormalized::new(self.value)
733 }
734
735 pub fn no_bound_vars(self) -> Option<T> {
737 if !self.value.has_param() { Some(self.value) } else { None }
738 }
739}
740
741struct ArgFolder<'a, I: Interner> {
745 cx: I,
746 args: &'a [I::GenericArg],
747
748 binders_passed: u32,
750}
751
752impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
753 #[inline]
754 fn cx(&self) -> I {
755 self.cx
756 }
757
758 fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
759 self.binders_passed += 1;
760 let t = t.super_fold_with(self);
761 self.binders_passed -= 1;
762 t
763 }
764
765 fn fold_region(&mut self, r: I::Region) -> I::Region {
766 match r.kind() {
772 ty::ReEarlyParam(data) => {
773 let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
774 match rk {
775 Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
776 Some(other) => self.region_param_expected(data, r, other),
777 None => self.region_param_out_of_range(data, r),
778 }
779 }
780 ty::ReBound(..)
781 | ty::ReLateParam(_)
782 | ty::ReStatic
783 | ty::RePlaceholder(_)
784 | ty::ReErased
785 | ty::ReError(_) => r,
786 ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
787 }
788 }
789
790 fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
791 if !t.has_param() {
792 return t;
793 }
794
795 match t.kind() {
796 ty::Param(p) => self.ty_for_param(p, t),
797 _ => t.super_fold_with(self),
798 }
799 }
800
801 fn fold_const(&mut self, c: I::Const) -> I::Const {
802 if let ty::ConstKind::Param(p) = c.kind() {
803 self.const_for_param(p, c)
804 } else {
805 c.super_fold_with(self)
806 }
807 }
808
809 fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
810 if p.has_param() { p.super_fold_with(self) } else { p }
811 }
812
813 fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
814 if c.has_param() { c.super_fold_with(self) } else { c }
815 }
816}
817
818impl<'a, I: Interner> ArgFolder<'a, I> {
819 fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
820 let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
822 let ty = match opt_ty {
823 Some(ty::GenericArgKind::Type(ty)) => ty,
824 Some(kind) => self.type_param_expected(p, source_ty, kind),
825 None => self.type_param_out_of_range(p, source_ty),
826 };
827
828 self.shift_vars_through_binders(ty)
829 }
830
831 #[cold]
832 #[inline(never)]
833 fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
834 {
::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!(
835 "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
836 p,
837 ty,
838 p.index(),
839 kind,
840 self.args,
841 )
842 }
843
844 #[cold]
845 #[inline(never)]
846 fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
847 {
::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!(
848 "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
849 p,
850 ty,
851 p.index(),
852 self.args,
853 )
854 }
855
856 fn const_for_param(&self, p: I::ParamConst, source_ct: I::Const) -> I::Const {
857 let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
859 let ct = match opt_ct {
860 Some(ty::GenericArgKind::Const(ct)) => ct,
861 Some(kind) => self.const_param_expected(p, source_ct, kind),
862 None => self.const_param_out_of_range(p, source_ct),
863 };
864
865 self.shift_vars_through_binders(ct)
866 }
867
868 #[cold]
869 #[inline(never)]
870 fn const_param_expected(
871 &self,
872 p: I::ParamConst,
873 ct: I::Const,
874 kind: ty::GenericArgKind<I>,
875 ) -> ! {
876 {
::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!(
877 "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
878 p,
879 ct,
880 p.index(),
881 kind,
882 self.args,
883 )
884 }
885
886 #[cold]
887 #[inline(never)]
888 fn const_param_out_of_range(&self, p: I::ParamConst, ct: I::Const) -> ! {
889 {
::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!(
890 "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
891 p,
892 ct,
893 p.index(),
894 self.args,
895 )
896 }
897
898 #[cold]
899 #[inline(never)]
900 fn region_param_expected(
901 &self,
902 ebr: I::EarlyParamRegion,
903 r: I::Region,
904 kind: ty::GenericArgKind<I>,
905 ) -> ! {
906 {
::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!(
907 "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
908 ebr,
909 r,
910 ebr.index(),
911 kind,
912 self.args,
913 )
914 }
915
916 #[cold]
917 #[inline(never)]
918 fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
919 {
::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!(
920 "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
921 ebr,
922 r,
923 ebr.index(),
924 self.args,
925 )
926 }
927
928 x;#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
971 fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
972 if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
973 val
974 } else {
975 ty::shift_vars(self.cx, val, self.binders_passed)
976 }
977 }
978
979 fn shift_region_through_binders(&self, region: I::Region) -> I::Region {
980 if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
981 region
982 } else {
983 ty::shift_region(self.cx, region, self.binders_passed)
984 }
985 }
986}
987
988#[derive(#[automatically_derived]
impl ::core::clone::Clone for BoundVarIndexKind {
#[inline]
fn clone(&self) -> BoundVarIndexKind {
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 {
BoundVarIndexKind::Bound(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Bound",
&__self_0),
BoundVarIndexKind::Canonical =>
::core::fmt::Formatter::write_str(f, "Canonical"),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for BoundVarIndexKind {
#[inline]
fn eq(&self, other: &BoundVarIndexKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(BoundVarIndexKind::Bound(__self_0),
BoundVarIndexKind::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) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
BoundVarIndexKind::Bound(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
1008#[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))]
1009#[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, 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)]
1010pub enum BoundVarIndexKind {
1011 Bound(DebruijnIndex),
1012 Canonical,
1013}
1014
1015#[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)]
1019#[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, 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)]
1020#[cfg_attr(
1021 feature = "nightly",
1022 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) {
match *self {
Placeholder {
universe: ref __binding_0,
bound: ref __binding_1,
_tcx: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, 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)
1023)]
1024pub struct Placeholder<I: Interner, T> {
1025 #[lift(identity)]
1026 pub universe: UniverseIndex,
1027 pub bound: T,
1028 #[type_foldable(identity)]
1029 #[type_visitable(ignore)]
1030 _tcx: PhantomData<fn() -> I>,
1031}
1032
1033impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
1034 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1035 if self.universe == ty::UniverseIndex::ROOT {
1036 f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
1037 } else {
1038 f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
1039 }
1040 }
1041}
1042
1043#[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)]
1044#[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, GenericTypeVisitable)]
1045#[cfg_attr(
1046 feature = "nightly",
1047 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)
1048)]
1049pub enum BoundRegionKind<I: Interner> {
1050 Anon,
1052
1053 NamedForPrinting(I::Symbol),
1057
1058 Named(I::DefId),
1060
1061 ClosureEnv,
1064}
1065
1066impl<I: Interner> fmt::Debug for ty::BoundRegionKind<I> {
1067 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1068 match *self {
1069 ty::BoundRegionKind::Anon => f.write_fmt(format_args!("BrAnon"))write!(f, "BrAnon"),
1070 ty::BoundRegionKind::NamedForPrinting(name) => {
1071 f.write_fmt(format_args!("BrNamedForPrinting({0:?})", name))write!(f, "BrNamedForPrinting({:?})", name)
1072 }
1073 ty::BoundRegionKind::Named(did) => {
1074 f.write_fmt(format_args!("BrNamed({0:?})", did))write!(f, "BrNamed({did:?})")
1075 }
1076 ty::BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("BrEnv"))write!(f, "BrEnv"),
1077 }
1078 }
1079}
1080
1081impl<I: Interner> BoundRegionKind<I> {
1082 pub fn is_named(&self, tcx: I) -> bool {
1083 self.get_name(tcx).is_some()
1084 }
1085
1086 pub fn get_name(&self, tcx: I) -> Option<I::Symbol> {
1087 match *self {
1088 ty::BoundRegionKind::Named(def_id) => {
1089 let name = tcx.item_name(def_id);
1090 if name.is_kw_underscore_lifetime() { None } else { Some(name) }
1091 }
1092 ty::BoundRegionKind::NamedForPrinting(name) => Some(name),
1093 _ => None,
1094 }
1095 }
1096
1097 pub fn get_id(&self) -> Option<I::DefId> {
1098 match *self {
1099 ty::BoundRegionKind::Named(id) => Some(id),
1100 _ => None,
1101 }
1102 }
1103}
1104
1105#[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)]
1106#[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, GenericTypeVisitable)]
1107#[cfg_attr(
1108 feature = "nightly",
1109 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)
1110)]
1111pub enum BoundTyKind<I: Interner> {
1112 Anon,
1113 Param(I::DefId),
1114}
1115
1116#[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)]
1117#[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, GenericTypeVisitable)]
1118#[cfg_attr(
1119 feature = "nightly",
1120 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)
1121)]
1122pub enum BoundVariableKind<I: Interner> {
1123 Ty(BoundTyKind<I>),
1124 Region(BoundRegionKind<I>),
1125 Const,
1126}
1127
1128impl<I: Interner> BoundVariableKind<I> {
1129 pub fn expect_region(self) -> BoundRegionKind<I> {
1130 match self {
1131 BoundVariableKind::Region(lt) => lt,
1132 _ => {
::core::panicking::panic_fmt(format_args!("expected a region, but found another kind"));
}panic!("expected a region, but found another kind"),
1133 }
1134 }
1135
1136 pub fn expect_ty(self) -> BoundTyKind<I> {
1137 match self {
1138 BoundVariableKind::Ty(ty) => ty,
1139 _ => {
::core::panicking::panic_fmt(format_args!("expected a type, but found another kind"));
}panic!("expected a type, but found another kind"),
1140 }
1141 }
1142
1143 pub fn expect_const(self) {
1144 match self {
1145 BoundVariableKind::Const => (),
1146 _ => {
::core::panicking::panic_fmt(format_args!("expected a const, but found another kind"));
}panic!("expected a const, but found another kind"),
1147 }
1148 }
1149}
1150
1151#[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)]
1152#[derive(GenericTypeVisitable)]
1153#[cfg_attr(
1154 feature = "nightly",
1155 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) {
match *self {
BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
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)
1156)]
1157pub struct BoundRegion<I: Interner> {
1158 pub var: ty::BoundVar,
1159 pub kind: BoundRegionKind<I>,
1160}
1161
1162impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1163 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1164 match self.kind {
1165 BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1166 BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1167 BoundRegionKind::Named(def) => {
1168 f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1169 }
1170 BoundRegionKind::NamedForPrinting(symbol) => {
1171 f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1172 }
1173 }
1174 }
1175}
1176
1177impl<I: Interner> BoundRegion<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_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())
1184 }
1185}
1186
1187pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1188
1189impl<I: Interner> PlaceholderRegion<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: BoundRegion<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 = BoundRegion { var, kind: BoundRegionKind::Anon };
1208 Self { universe: ui, bound, _tcx: PhantomData }
1209 }
1210}
1211
1212#[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)]
1213#[derive(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)]
1214#[cfg_attr(
1215 feature = "nightly",
1216 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) {
match *self {
BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for 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)
1217)]
1218pub struct BoundTy<I: Interner> {
1219 #[lift(identity)]
1220 pub var: ty::BoundVar,
1221 pub kind: BoundTyKind<I>,
1222}
1223
1224impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1225 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1226 match self.kind {
1227 ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1228 ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1229 }
1230 }
1231}
1232
1233impl<I: Interner> BoundTy<I> {
1234 pub fn var(self) -> ty::BoundVar {
1235 self.var
1236 }
1237
1238 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1239 {
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())
1240 }
1241}
1242
1243pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1244
1245impl<I: Interner> PlaceholderType<I> {
1246 pub fn universe(self) -> UniverseIndex {
1247 self.universe
1248 }
1249
1250 pub fn var(self) -> ty::BoundVar {
1251 self.bound.var
1252 }
1253
1254 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1255 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1256 }
1257
1258 pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1259 Self { universe: ui, bound, _tcx: PhantomData }
1260 }
1261
1262 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1263 let bound = BoundTy { var, kind: BoundTyKind::Anon };
1264 Self { universe: ui, bound, _tcx: PhantomData }
1265 }
1266}
1267
1268#[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)]
1269#[derive(GenericTypeVisitable)]
1270#[cfg_attr(
1271 feature = "nightly",
1272 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) {
match *self {
BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for 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)
1273)]
1274pub struct BoundConst<I: Interner> {
1275 pub var: ty::BoundVar,
1276 #[derive_where(skip(Debug))]
1277 pub _tcx: PhantomData<fn() -> I>,
1278}
1279
1280impl<I: Interner> BoundConst<I> {
1281 pub fn var(self) -> ty::BoundVar {
1282 self.var
1283 }
1284
1285 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1286 var.expect_const()
1287 }
1288
1289 pub fn new(var: ty::BoundVar) -> Self {
1290 Self { var, _tcx: PhantomData }
1291 }
1292}
1293
1294pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1295
1296impl<I: Interner> PlaceholderConst<I> {
1297 pub fn universe(self) -> UniverseIndex {
1298 self.universe
1299 }
1300
1301 pub fn var(self) -> ty::BoundVar {
1302 self.bound.var
1303 }
1304
1305 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1306 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1307 }
1308
1309 pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1310 Self { universe: ui, bound, _tcx: PhantomData }
1311 }
1312
1313 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1314 let bound = BoundConst::new(var);
1315 Self { universe: ui, bound, _tcx: PhantomData }
1316 }
1317
1318 pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1319 let mut candidates = env.caller_bounds().iter().filter_map(|clause| {
1320 match clause.kind().skip_binder() {
1322 ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1323 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());
1324
1325 match placeholder_ct.kind() {
1326 ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1327 Some(ty)
1328 }
1329 _ => None,
1330 }
1331 }
1332 _ => None,
1333 }
1334 });
1335
1336 let ty = candidates.next().unwrap_or_else(|| {
1343 {
::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1344 });
1345 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!(
1346 candidates.next().is_none(),
1347 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1348 );
1349 ty
1350 }
1351}