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, HashStable_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::lift::Lift;
18use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
19use crate::{self as ty, DebruijnIndex, Interner, UniverseIndex};
20
21#[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(GenericTypeVisitable)]
31#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<I: Interner, T, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
Binder<I, T> where
T: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::BoundVarKinds: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Binder { value: ref __binding_0, bound_vars: ref __binding_1
} => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_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, U: Interner, T> Lift<U> for Binder<I, T>
42where
43 T: Lift<U>,
44 I::BoundVarKinds: Lift<U, Lifted = U::BoundVarKinds>,
45{
46 type Lifted = Binder<U, T::Lifted>;
47
48 fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
49 Some(Binder {
50 value: self.value.lift_to_interner(cx)?,
51 bound_vars: self.bound_vars.lift_to_interner(cx)?,
52 })
53 }
54}
55
56#[cfg(feature = "nightly")]
57macro_rules! impl_binder_encode_decode {
58 ($($t:ty),+ $(,)?) => {
59 $(
60 impl<I: Interner, E: rustc_serialize::Encoder> rustc_serialize::Encodable<E> for ty::Binder<I, $t>
61 where
62 $t: rustc_serialize::Encodable<E>,
63 I::BoundVarKinds: rustc_serialize::Encodable<E>,
64 {
65 fn encode(&self, e: &mut E) {
66 self.bound_vars().encode(e);
67 self.as_ref().skip_binder().encode(e);
68 }
69 }
70 impl<I: Interner, D: rustc_serialize::Decoder> rustc_serialize::Decodable<D> for ty::Binder<I, $t>
71 where
72 $t: TypeVisitable<I> + rustc_serialize::Decodable<D>,
73 I::BoundVarKinds: rustc_serialize::Decodable<D>,
74 {
75 fn decode(decoder: &mut D) -> Self {
76 let bound_vars = rustc_serialize::Decodable::decode(decoder);
77 ty::Binder::bind_with_vars(rustc_serialize::Decodable::decode(decoder), bound_vars)
78 }
79 }
80 )*
81 }
82}
83
84#[cfg(feature = "nightly")]
85impl<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! {
86 ty::FnSig<I>,
87 ty::FnSigTys<I>,
88 ty::TraitPredicate<I>,
89 ty::ExistentialPredicate<I>,
90 ty::TraitRef<I>,
91 ty::ExistentialTraitRef<I>,
92 ty::HostEffectPredicate<I>,
93}
94
95impl<I: Interner, T> Binder<I, T>
96where
97 T: TypeVisitable<I>,
98{
99 #[track_caller]
104 pub fn dummy(value: T) -> Binder<I, T> {
105 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!(
106 !value.has_escaping_bound_vars(),
107 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
108 );
109 Binder { value, bound_vars: Default::default() }
110 }
111
112 pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
113 if truecfg!(debug_assertions) {
114 let mut validator = ValidateBoundVars::new(bound_vars);
115 let _ = value.visit_with(&mut validator);
116 }
117 Binder { value, bound_vars }
118 }
119}
120
121impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
122 fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
123 folder.try_fold_binder(self)
124 }
125
126 fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
127 folder.fold_binder(self)
128 }
129}
130
131impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
132 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
133 visitor.visit_binder(self)
134 }
135}
136
137impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
138 fn try_super_fold_with<F: FallibleTypeFolder<I>>(
139 self,
140 folder: &mut F,
141 ) -> Result<Self, F::Error> {
142 self.try_map_bound(|t| t.try_fold_with(folder))
143 }
144
145 fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
146 self.map_bound(|t| t.fold_with(folder))
147 }
148}
149
150impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
151 fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
152 self.as_ref().skip_binder().visit_with(visitor)
153 }
154}
155
156impl<I: Interner, T> Binder<I, T> {
157 pub fn skip_binder(self) -> T {
171 self.value
172 }
173
174 pub fn bound_vars(&self) -> I::BoundVarKinds {
175 self.bound_vars
176 }
177
178 pub fn as_ref(&self) -> Binder<I, &T> {
179 Binder { value: &self.value, bound_vars: self.bound_vars }
180 }
181
182 pub fn as_deref(&self) -> Binder<I, &T::Target>
183 where
184 T: Deref,
185 {
186 Binder { value: &self.value, bound_vars: self.bound_vars }
187 }
188
189 pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
190 where
191 F: FnOnce(&T) -> U,
192 {
193 self.as_ref().map_bound(f)
194 }
195
196 pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
197 where
198 F: FnOnce(T) -> U,
199 {
200 let Binder { value, bound_vars } = self;
201 let value = f(value);
202 if truecfg!(debug_assertions) {
203 let mut validator = ValidateBoundVars::new(bound_vars);
204 let _ = value.visit_with(&mut validator);
205 }
206 Binder { value, bound_vars }
207 }
208
209 pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
210 where
211 F: FnOnce(T) -> Result<U, E>,
212 {
213 let Binder { value, bound_vars } = self;
214 let value = f(value)?;
215 if truecfg!(debug_assertions) {
216 let mut validator = ValidateBoundVars::new(bound_vars);
217 let _ = value.visit_with(&mut validator);
218 }
219 Ok(Binder { value, bound_vars })
220 }
221
222 pub fn rebind<U>(&self, value: U) -> Binder<I, U>
232 where
233 U: TypeVisitable<I>,
234 {
235 Binder::bind_with_vars(value, self.bound_vars)
236 }
237
238 pub fn no_bound_vars(self) -> Option<T>
249 where
250 T: TypeVisitable<I>,
251 {
252 if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
254 }
255}
256
257impl<I: Interner, T> Binder<I, Option<T>> {
258 pub fn transpose(self) -> Option<Binder<I, T>> {
259 let Binder { value, bound_vars } = self;
260 value.map(|value| Binder { value, bound_vars })
261 }
262}
263
264impl<I: Interner, T: IntoIterator> Binder<I, T> {
265 pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
266 let Binder { value, bound_vars } = self;
267 value.into_iter().map(move |value| Binder { value, bound_vars })
268 }
269}
270
271pub struct ValidateBoundVars<I: Interner> {
272 bound_vars: I::BoundVarKinds,
273 binder_index: ty::DebruijnIndex,
274 visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
278}
279
280impl<I: Interner> ValidateBoundVars<I> {
281 pub fn new(bound_vars: I::BoundVarKinds) -> Self {
282 ValidateBoundVars {
283 bound_vars,
284 binder_index: ty::INNERMOST,
285 visited: SsoHashSet::default(),
286 }
287 }
288}
289
290impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
291 type Result = ControlFlow<()>;
292
293 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
294 self.binder_index.shift_in(1);
295 let result = t.super_visit_with(self);
296 self.binder_index.shift_out(1);
297 result
298 }
299
300 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
301 if t.outer_exclusive_binder() < self.binder_index
302 || !self.visited.insert((self.binder_index, t))
303 {
304 return ControlFlow::Break(());
305 }
306 match t.kind() {
307 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
308 if debruijn == self.binder_index =>
309 {
310 let idx = bound_ty.var().as_usize();
311 if self.bound_vars.len() <= idx {
312 {
::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);
313 }
314 bound_ty.assert_eq(self.bound_vars.get(idx).unwrap());
315 }
316 _ => {}
317 };
318
319 t.super_visit_with(self)
320 }
321
322 fn visit_const(&mut self, c: I::Const) -> Self::Result {
323 if c.outer_exclusive_binder() < self.binder_index {
324 return ControlFlow::Break(());
325 }
326 match c.kind() {
327 ty::ConstKind::Bound(debruijn, bound_const)
328 if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
329 {
330 let idx = bound_const.var().as_usize();
331 if self.bound_vars.len() <= idx {
332 {
::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);
333 }
334 bound_const.assert_eq(self.bound_vars.get(idx).unwrap());
335 }
336 _ => {}
337 };
338
339 c.super_visit_with(self)
340 }
341
342 fn visit_region(&mut self, r: I::Region) -> Self::Result {
343 match r.kind() {
344 ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
345 let idx = br.var().as_usize();
346 if self.bound_vars.len() <= idx {
347 {
::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);
348 }
349 br.assert_eq(self.bound_vars.get(idx).unwrap());
350 }
351
352 _ => (),
353 };
354
355 ControlFlow::Continue(())
356 }
357}
358
359#[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)]
365#[derive(GenericTypeVisitable)]
366#[cfg_attr(
367 feature = "nightly",
368 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
EarlyBinder<I, T> where
T: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
PhantomData<fn()
->
I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
} => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
369)]
370pub struct EarlyBinder<I: Interner, T> {
371 value: T,
372 #[derive_where(skip(Debug))]
373 _tcx: PhantomData<fn() -> I>,
374}
375
376impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
377
378#[cfg(feature = "nightly")]
380impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
381
382#[cfg(feature = "nightly")]
384impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
385
386impl<I: Interner, T> EarlyBinder<I, T> {
387 pub fn bind(value: T) -> EarlyBinder<I, T> {
388 EarlyBinder { value, _tcx: PhantomData }
389 }
390
391 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
392 EarlyBinder { value: &self.value, _tcx: PhantomData }
393 }
394
395 pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
396 where
397 F: FnOnce(&T) -> U,
398 {
399 self.as_ref().map_bound(f)
400 }
401
402 pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
403 where
404 F: FnOnce(T) -> U,
405 {
406 let value = f(self.value);
407 EarlyBinder { value, _tcx: PhantomData }
408 }
409
410 pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
411 where
412 F: FnOnce(T) -> Result<U, E>,
413 {
414 let value = f(self.value)?;
415 Ok(EarlyBinder { value, _tcx: PhantomData })
416 }
417
418 pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
419 EarlyBinder { value, _tcx: PhantomData }
420 }
421
422 pub fn skip_binder(self) -> T {
439 self.value
440 }
441}
442
443impl<I: Interner, T> EarlyBinder<I, Option<T>> {
444 pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
445 self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
446 }
447}
448
449impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
450where
451 Iter::Item: TypeFoldable<I>,
452{
453 pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
454 where
455 A: SliceLike<Item = I::GenericArg>,
456 {
457 IterInstantiated { it: self.value.into_iter(), cx, args }
458 }
459
460 pub fn iter_identity(self) -> Iter::IntoIter {
463 self.value.into_iter()
464 }
465}
466
467pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
468 it: Iter::IntoIter,
469 cx: I,
470 args: A,
471}
472
473impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
474where
475 Iter::Item: TypeFoldable<I>,
476 A: SliceLike<Item = I::GenericArg>,
477{
478 type Item = Iter::Item;
479
480 fn next(&mut self) -> Option<Self::Item> {
481 Some(
482 EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
483 .instantiate(self.cx, self.args),
484 )
485 }
486
487 fn size_hint(&self) -> (usize, Option<usize>) {
488 self.it.size_hint()
489 }
490}
491
492impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
493where
494 Iter::IntoIter: DoubleEndedIterator,
495 Iter::Item: TypeFoldable<I>,
496 A: SliceLike<Item = I::GenericArg>,
497{
498 fn next_back(&mut self) -> Option<Self::Item> {
499 Some(
500 EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
501 .instantiate(self.cx, self.args),
502 )
503 }
504}
505
506impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
507where
508 Iter::IntoIter: ExactSizeIterator,
509 Iter::Item: TypeFoldable<I>,
510 A: SliceLike<Item = I::GenericArg>,
511{
512}
513
514impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
515where
516 Iter::Item: Deref,
517 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
518{
519 pub fn iter_instantiated_copied(
520 self,
521 cx: I,
522 args: &'s [I::GenericArg],
523 ) -> IterInstantiatedCopied<'s, I, Iter> {
524 IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
525 }
526
527 pub fn iter_identity_copied(self) -> IterIdentityCopied<Iter> {
530 IterIdentityCopied { it: self.value.into_iter() }
531 }
532}
533
534pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
535 it: Iter::IntoIter,
536 cx: I,
537 args: &'a [I::GenericArg],
538}
539
540impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
541where
542 Iter::Item: Deref,
543 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
544{
545 type Item = <Iter::Item as Deref>::Target;
546
547 fn next(&mut self) -> Option<Self::Item> {
548 self.it.next().map(|value| {
549 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
550 })
551 }
552
553 fn size_hint(&self) -> (usize, Option<usize>) {
554 self.it.size_hint()
555 }
556}
557
558impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, I, Iter>
559where
560 Iter::IntoIter: DoubleEndedIterator,
561 Iter::Item: Deref,
562 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
563{
564 fn next_back(&mut self) -> Option<Self::Item> {
565 self.it.next_back().map(|value| {
566 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
567 })
568 }
569}
570
571impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, I, Iter>
572where
573 Iter::IntoIter: ExactSizeIterator,
574 Iter::Item: Deref,
575 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
576{
577}
578
579pub struct IterIdentityCopied<Iter: IntoIterator> {
580 it: Iter::IntoIter,
581}
582
583impl<Iter: IntoIterator> Iterator for IterIdentityCopied<Iter>
584where
585 Iter::Item: Deref,
586 <Iter::Item as Deref>::Target: Copy,
587{
588 type Item = <Iter::Item as Deref>::Target;
589
590 fn next(&mut self) -> Option<Self::Item> {
591 self.it.next().map(|i| *i)
592 }
593
594 fn size_hint(&self) -> (usize, Option<usize>) {
595 self.it.size_hint()
596 }
597}
598
599impl<Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<Iter>
600where
601 Iter::IntoIter: DoubleEndedIterator,
602 Iter::Item: Deref,
603 <Iter::Item as Deref>::Target: Copy,
604{
605 fn next_back(&mut self) -> Option<Self::Item> {
606 self.it.next_back().map(|i| *i)
607 }
608}
609
610impl<Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<Iter>
611where
612 Iter::IntoIter: ExactSizeIterator,
613 Iter::Item: Deref,
614 <Iter::Item as Deref>::Target: Copy,
615{
616}
617pub struct EarlyBinderIter<I, T> {
618 t: T,
619 _tcx: PhantomData<I>,
620}
621
622impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
623 pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
624 EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
625 }
626}
627
628impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
629 type Item = EarlyBinder<I, T::Item>;
630
631 fn next(&mut self) -> Option<Self::Item> {
632 self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
633 }
634
635 fn size_hint(&self) -> (usize, Option<usize>) {
636 self.t.size_hint()
637 }
638}
639
640impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
641 pub fn instantiate<A>(self, cx: I, args: A) -> T
642 where
643 A: SliceLike<Item = I::GenericArg>,
644 {
645 if args.is_empty() {
649 if !!self.value.has_param() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
self.value));
}
};assert!(
650 !self.value.has_param(),
651 "{:?} has parameters, but no args were provided in instantiate",
652 self.value,
653 );
654 return self.value;
655 }
656 let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
657 self.value.fold_with(&mut folder)
658 }
659
660 pub fn instantiate_identity(self) -> T {
669 self.value
670 }
671
672 pub fn no_bound_vars(self) -> Option<T> {
674 if !self.value.has_param() { Some(self.value) } else { None }
675 }
676}
677
678struct ArgFolder<'a, I: Interner> {
682 cx: I,
683 args: &'a [I::GenericArg],
684
685 binders_passed: u32,
687}
688
689impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
690 #[inline]
691 fn cx(&self) -> I {
692 self.cx
693 }
694
695 fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
696 self.binders_passed += 1;
697 let t = t.super_fold_with(self);
698 self.binders_passed -= 1;
699 t
700 }
701
702 fn fold_region(&mut self, r: I::Region) -> I::Region {
703 match r.kind() {
709 ty::ReEarlyParam(data) => {
710 let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
711 match rk {
712 Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
713 Some(other) => self.region_param_expected(data, r, other),
714 None => self.region_param_out_of_range(data, r),
715 }
716 }
717 ty::ReBound(..)
718 | ty::ReLateParam(_)
719 | ty::ReStatic
720 | ty::RePlaceholder(_)
721 | ty::ReErased
722 | ty::ReError(_) => r,
723 ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
724 }
725 }
726
727 fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
728 if !t.has_param() {
729 return t;
730 }
731
732 match t.kind() {
733 ty::Param(p) => self.ty_for_param(p, t),
734 _ => t.super_fold_with(self),
735 }
736 }
737
738 fn fold_const(&mut self, c: I::Const) -> I::Const {
739 if let ty::ConstKind::Param(p) = c.kind() {
740 self.const_for_param(p, c)
741 } else {
742 c.super_fold_with(self)
743 }
744 }
745
746 fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
747 if p.has_param() { p.super_fold_with(self) } else { p }
748 }
749
750 fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
751 if c.has_param() { c.super_fold_with(self) } else { c }
752 }
753}
754
755impl<'a, I: Interner> ArgFolder<'a, I> {
756 fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
757 let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
759 let ty = match opt_ty {
760 Some(ty::GenericArgKind::Type(ty)) => ty,
761 Some(kind) => self.type_param_expected(p, source_ty, kind),
762 None => self.type_param_out_of_range(p, source_ty),
763 };
764
765 self.shift_vars_through_binders(ty)
766 }
767
768 #[cold]
769 #[inline(never)]
770 fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
771 {
::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!(
772 "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
773 p,
774 ty,
775 p.index(),
776 kind,
777 self.args,
778 )
779 }
780
781 #[cold]
782 #[inline(never)]
783 fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
784 {
::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!(
785 "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
786 p,
787 ty,
788 p.index(),
789 self.args,
790 )
791 }
792
793 fn const_for_param(&self, p: I::ParamConst, source_ct: I::Const) -> I::Const {
794 let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
796 let ct = match opt_ct {
797 Some(ty::GenericArgKind::Const(ct)) => ct,
798 Some(kind) => self.const_param_expected(p, source_ct, kind),
799 None => self.const_param_out_of_range(p, source_ct),
800 };
801
802 self.shift_vars_through_binders(ct)
803 }
804
805 #[cold]
806 #[inline(never)]
807 fn const_param_expected(
808 &self,
809 p: I::ParamConst,
810 ct: I::Const,
811 kind: ty::GenericArgKind<I>,
812 ) -> ! {
813 {
::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!(
814 "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
815 p,
816 ct,
817 p.index(),
818 kind,
819 self.args,
820 )
821 }
822
823 #[cold]
824 #[inline(never)]
825 fn const_param_out_of_range(&self, p: I::ParamConst, ct: I::Const) -> ! {
826 {
::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!(
827 "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
828 p,
829 ct,
830 p.index(),
831 self.args,
832 )
833 }
834
835 #[cold]
836 #[inline(never)]
837 fn region_param_expected(
838 &self,
839 ebr: I::EarlyParamRegion,
840 r: I::Region,
841 kind: ty::GenericArgKind<I>,
842 ) -> ! {
843 {
::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!(
844 "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
845 ebr,
846 r,
847 ebr.index(),
848 kind,
849 self.args,
850 )
851 }
852
853 #[cold]
854 #[inline(never)]
855 fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
856 {
::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!(
857 "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
858 ebr,
859 r,
860 ebr.index(),
861 self.args,
862 )
863 }
864
865 x;#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
908 fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
909 if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
910 val
911 } else {
912 ty::shift_vars(self.cx, val, self.binders_passed)
913 }
914 }
915
916 fn shift_region_through_binders(&self, region: I::Region) -> I::Region {
917 if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
918 region
919 } else {
920 ty::shift_region(self.cx, region, self.binders_passed)
921 }
922 }
923}
924
925#[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)]
945#[cfg_attr(
946 feature = "nightly",
947 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<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for BoundVarIndexKind {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
BoundVarIndexKind::Bound(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
BoundVarIndexKind::Canonical => {}
}
}
}
};HashStable_NoContext)
948)]
949#[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)]
950pub enum BoundVarIndexKind {
951 Bound(DebruijnIndex),
952 Canonical,
953}
954
955#[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)]
959#[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> {
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)]
960#[cfg_attr(
961 feature = "nightly",
962 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
Placeholder<I, T> where
T: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
PhantomData<fn()
->
I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Placeholder {
universe: ref __binding_0,
bound: ref __binding_1,
_tcx: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
963)]
964pub struct Placeholder<I: Interner, T> {
965 pub universe: UniverseIndex,
966 pub bound: T,
967 #[type_foldable(identity)]
968 #[type_visitable(ignore)]
969 _tcx: PhantomData<fn() -> I>,
970}
971
972impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
973 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
974 if self.universe == ty::UniverseIndex::ROOT {
975 f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
976 } else {
977 f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
978 }
979 }
980}
981
982impl<I: Interner, U: Interner, T> Lift<U> for Placeholder<I, T>
983where
984 T: Lift<U>,
985{
986 type Lifted = Placeholder<U, T::Lifted>;
987
988 fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
989 Some(Placeholder {
990 universe: self.universe,
991 bound: self.bound.lift_to_interner(cx)?,
992 _tcx: PhantomData,
993 })
994 }
995}
996
997#[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)]
998#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
BoundRegionKind<I> where I: Interner, J: Interner,
I::Symbol: ::rustc_type_ir::lift::Lift<J, Lifted = J::Symbol>,
I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId> {
type Lifted = BoundRegionKind<J>;
fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
Some(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)]
999#[cfg_attr(
1000 feature = "nightly",
1001 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundRegionKind<I> where
I::Symbol: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
I::DefId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
BoundRegionKind::Anon => {}
BoundRegionKind::NamedForPrinting(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
BoundRegionKind::Named(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
BoundRegionKind::ClosureEnv => {}
}
}
}
};HashStable_NoContext)
1002)]
1003
1004pub enum BoundRegionKind<I: Interner> {
1005 Anon,
1007
1008 NamedForPrinting(I::Symbol),
1012
1013 Named(I::DefId),
1015
1016 ClosureEnv,
1019}
1020
1021impl<I: Interner> fmt::Debug for ty::BoundRegionKind<I> {
1022 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1023 match *self {
1024 ty::BoundRegionKind::Anon => f.write_fmt(format_args!("BrAnon"))write!(f, "BrAnon"),
1025 ty::BoundRegionKind::NamedForPrinting(name) => {
1026 f.write_fmt(format_args!("BrNamedForPrinting({0:?})", name))write!(f, "BrNamedForPrinting({:?})", name)
1027 }
1028 ty::BoundRegionKind::Named(did) => {
1029 f.write_fmt(format_args!("BrNamed({0:?})", did))write!(f, "BrNamed({did:?})")
1030 }
1031 ty::BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("BrEnv"))write!(f, "BrEnv"),
1032 }
1033 }
1034}
1035
1036impl<I: Interner> BoundRegionKind<I> {
1037 pub fn is_named(&self, tcx: I) -> bool {
1038 self.get_name(tcx).is_some()
1039 }
1040
1041 pub fn get_name(&self, tcx: I) -> Option<I::Symbol> {
1042 match *self {
1043 ty::BoundRegionKind::Named(def_id) => {
1044 let name = tcx.item_name(def_id);
1045 if name.is_kw_underscore_lifetime() { None } else { Some(name) }
1046 }
1047 ty::BoundRegionKind::NamedForPrinting(name) => Some(name),
1048 _ => None,
1049 }
1050 }
1051
1052 pub fn get_id(&self) -> Option<I::DefId> {
1053 match *self {
1054 ty::BoundRegionKind::Named(id) => Some(id),
1055 _ => None,
1056 }
1057 }
1058}
1059
1060#[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)]
1061#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundTyKind<I>
where I: Interner, J: Interner,
I::DefId: ::rustc_type_ir::lift::Lift<J, Lifted = J::DefId> {
type Lifted = BoundTyKind<J>;
fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
Some(match self {
BoundTyKind::Anon => { BoundTyKind::Anon }
BoundTyKind::Param(__binding_0) => {
BoundTyKind::Param(__binding_0.lift_to_interner(interner)?)
}
})
}
}
};Lift_Generic)]
1062#[cfg_attr(
1063 feature = "nightly",
1064 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundTyKind<I> where
I::DefId: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
BoundTyKind::Anon => {}
BoundTyKind::Param(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
1065)]
1066pub enum BoundTyKind<I: Interner> {
1067 Anon,
1068 Param(I::DefId),
1069}
1070
1071#[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)]
1072#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
BoundVariableKind<I> where I: Interner, J: Interner,
BoundTyKind<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
BoundTyKind<J>>,
BoundRegionKind<I>: ::rustc_type_ir::lift::Lift<J, Lifted =
BoundRegionKind<J>> {
type Lifted = BoundVariableKind<J>;
fn lift_to_interner(self, interner: J) -> Option<Self::Lifted> {
Some(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)]
1073#[cfg_attr(
1074 feature = "nightly",
1075 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundVariableKind<I> where
BoundTyKind<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>,
BoundRegionKind<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
BoundVariableKind::Ty(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
BoundVariableKind::Region(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
BoundVariableKind::Const => {}
}
}
}
};HashStable_NoContext)
1076)]
1077pub enum BoundVariableKind<I: Interner> {
1078 Ty(BoundTyKind<I>),
1079 Region(BoundRegionKind<I>),
1080 Const,
1081}
1082
1083impl<I: Interner> BoundVariableKind<I> {
1084 pub fn expect_region(self) -> BoundRegionKind<I> {
1085 match self {
1086 BoundVariableKind::Region(lt) => lt,
1087 _ => {
::core::panicking::panic_fmt(format_args!("expected a region, but found another kind"));
}panic!("expected a region, but found another kind"),
1088 }
1089 }
1090
1091 pub fn expect_ty(self) -> BoundTyKind<I> {
1092 match self {
1093 BoundVariableKind::Ty(ty) => ty,
1094 _ => {
::core::panicking::panic_fmt(format_args!("expected a type, but found another kind"));
}panic!("expected a type, but found another kind"),
1095 }
1096 }
1097
1098 pub fn expect_const(self) {
1099 match self {
1100 BoundVariableKind::Const => (),
1101 _ => {
::core::panicking::panic_fmt(format_args!("expected a const, but found another kind"));
}panic!("expected a const, but found another kind"),
1102 }
1103 }
1104}
1105
1106#[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)]
1107#[cfg_attr(
1108 feature = "nightly",
1109 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundRegion<I> where
BoundRegionKind<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_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)
1110)]
1111pub struct BoundRegion<I: Interner> {
1112 pub var: ty::BoundVar,
1113 pub kind: BoundRegionKind<I>,
1114}
1115
1116impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1117 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1118 match self.kind {
1119 BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1120 BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1121 BoundRegionKind::Named(def) => {
1122 f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1123 }
1124 BoundRegionKind::NamedForPrinting(symbol) => {
1125 f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1126 }
1127 }
1128 }
1129}
1130
1131impl<I: Interner> BoundRegion<I> {
1132 pub fn var(self) -> ty::BoundVar {
1133 self.var
1134 }
1135
1136 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1137 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())
1138 }
1139}
1140
1141pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1142
1143impl<I: Interner> PlaceholderRegion<I> {
1144 pub fn universe(self) -> UniverseIndex {
1145 self.universe
1146 }
1147
1148 pub fn var(self) -> ty::BoundVar {
1149 self.bound.var()
1150 }
1151
1152 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1153 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1154 }
1155
1156 pub fn new(ui: UniverseIndex, bound: BoundRegion<I>) -> Self {
1157 Self { universe: ui, bound, _tcx: PhantomData }
1158 }
1159
1160 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1161 let bound = BoundRegion { var, kind: BoundRegionKind::Anon };
1162 Self { universe: ui, bound, _tcx: PhantomData }
1163 }
1164}
1165
1166#[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)]
1167#[cfg_attr(
1168 feature = "nightly",
1169 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundTy<I> where
BoundTyKind<I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
1170)]
1171pub struct BoundTy<I: Interner> {
1172 pub var: ty::BoundVar,
1173 pub kind: BoundTyKind<I>,
1174}
1175
1176impl<I: Interner, U: Interner> Lift<U> for BoundTy<I>
1177where
1178 BoundTyKind<I>: Lift<U, Lifted = BoundTyKind<U>>,
1179{
1180 type Lifted = BoundTy<U>;
1181
1182 fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
1183 Some(BoundTy { var: self.var, kind: self.kind.lift_to_interner(cx)? })
1184 }
1185}
1186
1187impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1188 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1189 match self.kind {
1190 ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1191 ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1192 }
1193 }
1194}
1195
1196impl<I: Interner> BoundTy<I> {
1197 pub fn var(self) -> ty::BoundVar {
1198 self.var
1199 }
1200
1201 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1202 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())
1203 }
1204}
1205
1206pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1207
1208impl<I: Interner> PlaceholderType<I> {
1209 pub fn universe(self) -> UniverseIndex {
1210 self.universe
1211 }
1212
1213 pub fn var(self) -> ty::BoundVar {
1214 self.bound.var
1215 }
1216
1217 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1218 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1219 }
1220
1221 pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1222 Self { universe: ui, bound, _tcx: PhantomData }
1223 }
1224
1225 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1226 let bound = BoundTy { var, kind: BoundTyKind::Anon };
1227 Self { universe: ui, bound, _tcx: PhantomData }
1228 }
1229}
1230
1231#[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)]
1232#[cfg_attr(
1233 feature = "nightly",
1234 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, __CTX>
::rustc_data_structures::stable_hasher::HashStable<__CTX> for
BoundConst<I> where
PhantomData<fn()
->
I>: ::rustc_data_structures::stable_hasher::HashStable<__CTX>
{
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext)
1235)]
1236pub struct BoundConst<I: Interner> {
1237 pub var: ty::BoundVar,
1238 #[derive_where(skip(Debug))]
1239 pub _tcx: PhantomData<fn() -> I>,
1240}
1241
1242impl<I: Interner> BoundConst<I> {
1243 pub fn var(self) -> ty::BoundVar {
1244 self.var
1245 }
1246
1247 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1248 var.expect_const()
1249 }
1250
1251 pub fn new(var: ty::BoundVar) -> Self {
1252 Self { var, _tcx: PhantomData }
1253 }
1254}
1255
1256pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1257
1258impl<I: Interner> PlaceholderConst<I> {
1259 pub fn universe(self) -> UniverseIndex {
1260 self.universe
1261 }
1262
1263 pub fn var(self) -> ty::BoundVar {
1264 self.bound.var
1265 }
1266
1267 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1268 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1269 }
1270
1271 pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1272 Self { universe: ui, bound, _tcx: PhantomData }
1273 }
1274
1275 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1276 let bound = BoundConst::new(var);
1277 Self { universe: ui, bound, _tcx: PhantomData }
1278 }
1279
1280 pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1281 let mut candidates = env.caller_bounds().iter().filter_map(|clause| {
1282 match clause.kind().skip_binder() {
1284 ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1285 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());
1286
1287 match placeholder_ct.kind() {
1288 ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1289 Some(ty)
1290 }
1291 _ => None,
1292 }
1293 }
1294 _ => None,
1295 }
1296 });
1297
1298 let ty = candidates.next().unwrap_or_else(|| {
1305 {
::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1306 });
1307 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!(
1308 candidates.next().is_none(),
1309 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1310 );
1311 ty
1312 }
1313}