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
77impl<I: Interner, T> Binder<I, T>
78where
79 T: TypeVisitable<I>,
80{
81 #[track_caller]
86 pub fn dummy(value: T) -> Binder<I, T> {
87 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!(
88 !value.has_escaping_bound_vars(),
89 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
90 );
91 Binder { value, bound_vars: Default::default() }
92 }
93
94 pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
95 if truecfg!(debug_assertions) {
96 let mut validator = ValidateBoundVars::new(bound_vars);
97 let _ = value.visit_with(&mut validator);
98 }
99 Binder { value, bound_vars }
100 }
101}
102
103impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
104 fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
105 folder.try_fold_binder(self)
106 }
107
108 fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
109 folder.fold_binder(self)
110 }
111}
112
113impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
114 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
115 visitor.visit_binder(self)
116 }
117}
118
119impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
120 fn try_super_fold_with<F: FallibleTypeFolder<I>>(
121 self,
122 folder: &mut F,
123 ) -> Result<Self, F::Error> {
124 self.try_map_bound(|t| t.try_fold_with(folder))
125 }
126
127 fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
128 self.map_bound(|t| t.fold_with(folder))
129 }
130}
131
132impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
133 fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
134 self.as_ref().skip_binder().visit_with(visitor)
135 }
136}
137
138impl<I: Interner, T> Binder<I, T> {
139 pub fn skip_binder(self) -> T {
153 self.value
154 }
155
156 pub fn bound_vars(&self) -> I::BoundVarKinds {
157 self.bound_vars
158 }
159
160 pub fn as_ref(&self) -> Binder<I, &T> {
161 Binder { value: &self.value, bound_vars: self.bound_vars }
162 }
163
164 pub fn as_deref(&self) -> Binder<I, &T::Target>
165 where
166 T: Deref,
167 {
168 Binder { value: &self.value, bound_vars: self.bound_vars }
169 }
170
171 pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
172 where
173 F: FnOnce(&T) -> U,
174 {
175 self.as_ref().map_bound(f)
176 }
177
178 pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
179 where
180 F: FnOnce(T) -> U,
181 {
182 let Binder { value, bound_vars } = self;
183 let value = f(value);
184 if truecfg!(debug_assertions) {
185 let mut validator = ValidateBoundVars::new(bound_vars);
186 let _ = value.visit_with(&mut validator);
187 }
188 Binder { value, bound_vars }
189 }
190
191 pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
192 where
193 F: FnOnce(T) -> Result<U, E>,
194 {
195 let Binder { value, bound_vars } = self;
196 let value = f(value)?;
197 if truecfg!(debug_assertions) {
198 let mut validator = ValidateBoundVars::new(bound_vars);
199 let _ = value.visit_with(&mut validator);
200 }
201 Ok(Binder { value, bound_vars })
202 }
203
204 pub fn rebind<U>(&self, value: U) -> Binder<I, U>
214 where
215 U: TypeVisitable<I>,
216 {
217 Binder::bind_with_vars(value, self.bound_vars)
218 }
219
220 pub fn no_bound_vars(self) -> Option<T>
231 where
232 T: TypeVisitable<I>,
233 {
234 if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
236 }
237}
238
239impl<I: Interner, T> Binder<I, Option<T>> {
240 pub fn transpose(self) -> Option<Binder<I, T>> {
241 let Binder { value, bound_vars } = self;
242 value.map(|value| Binder { value, bound_vars })
243 }
244}
245
246impl<I: Interner, T: IntoIterator> Binder<I, T> {
247 pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
248 let Binder { value, bound_vars } = self;
249 value.into_iter().map(move |value| Binder { value, bound_vars })
250 }
251}
252
253pub struct ValidateBoundVars<I: Interner> {
254 bound_vars: I::BoundVarKinds,
255 binder_index: ty::DebruijnIndex,
256 visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
260}
261
262impl<I: Interner> ValidateBoundVars<I> {
263 pub fn new(bound_vars: I::BoundVarKinds) -> Self {
264 ValidateBoundVars {
265 bound_vars,
266 binder_index: ty::INNERMOST,
267 visited: SsoHashSet::default(),
268 }
269 }
270}
271
272impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
273 type Result = ControlFlow<()>;
274
275 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
276 self.binder_index.shift_in(1);
277 let result = t.super_visit_with(self);
278 self.binder_index.shift_out(1);
279 result
280 }
281
282 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
283 if t.outer_exclusive_binder() < self.binder_index
284 || !self.visited.insert((self.binder_index, t))
285 {
286 return ControlFlow::Break(());
287 }
288 match t.kind() {
289 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
290 if debruijn == self.binder_index =>
291 {
292 let idx = bound_ty.var().as_usize();
293 if self.bound_vars.len() <= idx {
294 {
::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);
295 }
296 bound_ty.assert_eq(self.bound_vars.get(idx).unwrap());
297 }
298 _ => {}
299 };
300
301 t.super_visit_with(self)
302 }
303
304 fn visit_const(&mut self, c: I::Const) -> Self::Result {
305 if c.outer_exclusive_binder() < self.binder_index {
306 return ControlFlow::Break(());
307 }
308 match c.kind() {
309 ty::ConstKind::Bound(debruijn, bound_const)
310 if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
311 {
312 let idx = bound_const.var().as_usize();
313 if self.bound_vars.len() <= idx {
314 {
::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);
315 }
316 bound_const.assert_eq(self.bound_vars.get(idx).unwrap());
317 }
318 _ => {}
319 };
320
321 c.super_visit_with(self)
322 }
323
324 fn visit_region(&mut self, r: I::Region) -> Self::Result {
325 match r.kind() {
326 ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
327 let idx = br.var().as_usize();
328 if self.bound_vars.len() <= idx {
329 {
::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);
330 }
331 br.assert_eq(self.bound_vars.get(idx).unwrap());
332 }
333
334 _ => (),
335 };
336
337 ControlFlow::Continue(())
338 }
339}
340
341#[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)]
347#[derive(GenericTypeVisitable)]
348#[cfg_attr(
349 feature = "nightly",
350 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)
351)]
352pub struct EarlyBinder<I: Interner, T> {
353 value: T,
354 #[derive_where(skip(Debug))]
355 _tcx: PhantomData<fn() -> I>,
356}
357
358impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
359
360#[cfg(feature = "nightly")]
362macro_rules! generate { ($( $tt:tt )*) => { $( $tt )* } }
363
364#[cfg(feature = "nightly")]
365generate!(
366 impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
368 impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
370);
371
372impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
373 pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {
374 let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization();
376 EarlyBinder { value, _tcx: PhantomData }
377 }
378}
379
380impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> {
381 pub fn bind_iter(value: T) -> EarlyBinder<I, T> {
382 #[cfg(debug_assertions)]
383 {
384 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()));
385 }
386
387 EarlyBinder { value, _tcx: PhantomData }
388 }
389}
390
391impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> {
392 pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> {
393 if true {
if !!value.has_rigid_aliases() {
::core::panicking::panic("assertion failed: !value.has_rigid_aliases()")
};
};debug_assert!(!value.has_rigid_aliases());
394 EarlyBinder { value, _tcx: PhantomData }
395 }
396}
397
398impl<I: Interner, T> EarlyBinder<I, T> {
399 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
400 EarlyBinder { value: &self.value, _tcx: PhantomData }
401 }
402
403 pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
404 where
405 F: FnOnce(&T) -> U,
406 {
407 self.as_ref().map_bound(f)
408 }
409
410 pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
411 where
412 F: FnOnce(T) -> U,
413 {
414 let value = f(self.value);
415 EarlyBinder { value, _tcx: PhantomData }
416 }
417
418 pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
419 where
420 F: FnOnce(T) -> Result<U, E>,
421 {
422 let value = f(self.value)?;
423 Ok(EarlyBinder { value, _tcx: PhantomData })
424 }
425
426 pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
427 EarlyBinder { value, _tcx: PhantomData }
428 }
429
430 pub fn skip_binder(self) -> T {
447 self.value
448 }
449}
450
451impl<I: Interner, T> EarlyBinder<I, Option<T>> {
452 pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
453 self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
454 }
455}
456
457impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
458where
459 Iter::Item: TypeFoldable<I>,
460{
461 pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
462 where
463 A: SliceLike<Item = I::GenericArg>,
464 {
465 IterInstantiated { it: self.value.into_iter(), cx, args }
466 }
467
468 pub fn iter_identity(self) -> impl Iterator<Item = Unnormalized<I, Iter::Item>> {
471 self.value.into_iter().map(Unnormalized::new)
472 }
473}
474
475pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
476 it: Iter::IntoIter,
477 cx: I,
478 args: A,
479}
480
481impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
482where
483 Iter::Item: TypeFoldable<I>,
484 A: SliceLike<Item = I::GenericArg>,
485{
486 type Item = Unnormalized<I, Iter::Item>;
487
488 fn next(&mut self) -> Option<Self::Item> {
489 Some(
490 EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
491 .instantiate(self.cx, self.args),
492 )
493 }
494
495 fn size_hint(&self) -> (usize, Option<usize>) {
496 self.it.size_hint()
497 }
498}
499
500impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
501where
502 Iter::IntoIter: DoubleEndedIterator,
503 Iter::Item: TypeFoldable<I>,
504 A: SliceLike<Item = I::GenericArg>,
505{
506 fn next_back(&mut self) -> Option<Self::Item> {
507 Some(
508 EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
509 .instantiate(self.cx, self.args),
510 )
511 }
512}
513
514impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
515where
516 Iter::IntoIter: ExactSizeIterator,
517 Iter::Item: TypeFoldable<I>,
518 A: SliceLike<Item = I::GenericArg>,
519{
520}
521
522impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
523where
524 Iter::Item: Deref,
525 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
526{
527 pub fn iter_instantiated_copied(
528 self,
529 cx: I,
530 args: &'s [I::GenericArg],
531 ) -> IterInstantiatedCopied<'s, I, Iter> {
532 IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
533 }
534
535 pub fn iter_identity_copied(self) -> IterIdentityCopied<I, Iter> {
538 IterIdentityCopied { it: self.value.into_iter(), _tcx: PhantomData }
539 }
540}
541
542pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
543 it: Iter::IntoIter,
544 cx: I,
545 args: &'a [I::GenericArg],
546}
547
548impl<'a, I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone
549 for IterInstantiatedCopied<'a, I, Iter>
550{
551 fn clone(&self) -> IterInstantiatedCopied<'a, I, Iter> {
552 IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args }
553 }
554}
555
556impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
557where
558 Iter::Item: Deref,
559 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
560{
561 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
562
563 fn next(&mut self) -> Option<Self::Item> {
564 self.it.next().map(|value| {
565 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
566 })
567 }
568
569 fn size_hint(&self) -> (usize, Option<usize>) {
570 self.it.size_hint()
571 }
572}
573
574impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, I, Iter>
575where
576 Iter::IntoIter: DoubleEndedIterator,
577 Iter::Item: Deref,
578 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
579{
580 fn next_back(&mut self) -> Option<Self::Item> {
581 self.it.next_back().map(|value| {
582 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
583 })
584 }
585}
586
587impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, I, Iter>
588where
589 Iter::IntoIter: ExactSizeIterator,
590 Iter::Item: Deref,
591 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
592{
593}
594
595pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
596 it: Iter::IntoIter,
597 _tcx: PhantomData<fn() -> I>,
598}
599
600impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> {
601 fn clone(&self) -> IterIdentityCopied<I, Iter> {
602 IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx }
603 }
604}
605
606impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
607where
608 Iter::Item: Deref,
609 <Iter::Item as Deref>::Target: Copy,
610{
611 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
612
613 fn next(&mut self) -> Option<Self::Item> {
614 self.it.next().map(|i| Unnormalized::new(*i))
615 }
616
617 fn size_hint(&self) -> (usize, Option<usize>) {
618 self.it.size_hint()
619 }
620}
621
622impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<I, Iter>
623where
624 Iter::IntoIter: DoubleEndedIterator,
625 Iter::Item: Deref,
626 <Iter::Item as Deref>::Target: Copy,
627{
628 fn next_back(&mut self) -> Option<Self::Item> {
629 self.it.next_back().map(|i| Unnormalized::new(*i))
630 }
631}
632
633impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<I, Iter>
634where
635 Iter::IntoIter: ExactSizeIterator,
636 Iter::Item: Deref,
637 <Iter::Item as Deref>::Target: Copy,
638{
639}
640pub struct EarlyBinderIter<I, T> {
641 t: T,
642 _tcx: PhantomData<I>,
643}
644
645impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
646 pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
647 EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
648 }
649}
650
651impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
652 type Item = EarlyBinder<I, T::Item>;
653
654 fn next(&mut self) -> Option<Self::Item> {
655 self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
656 }
657
658 fn size_hint(&self) -> (usize, Option<usize>) {
659 self.t.size_hint()
660 }
661}
662
663impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
664 pub fn instantiate<A>(self, cx: I, args: A) -> Unnormalized<I, T>
665 where
666 A: SliceLike<Item = I::GenericArg>,
667 {
668 if args.is_empty() {
672 if !!self.value.has_param() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
self.value));
}
};assert!(
673 !self.value.has_param(),
674 "{:?} has parameters, but no args were provided in instantiate",
675 self.value,
676 );
677 return Unnormalized::new(self.value);
678 }
679 let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
680 Unnormalized::new(self.value.fold_with(&mut folder))
681 }
682
683 pub fn instantiate_identity(self) -> Unnormalized<I, T> {
692 Unnormalized::new(self.value)
701 }
702
703 pub fn no_bound_vars(self) -> Option<T> {
705 if !self.value.has_param() { Some(self.value) } else { None }
706 }
707}
708
709struct ArgFolder<'a, I: Interner> {
713 cx: I,
714 args: &'a [I::GenericArg],
715
716 binders_passed: u32,
718}
719
720impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
721 #[inline]
722 fn cx(&self) -> I {
723 self.cx
724 }
725
726 fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
727 self.binders_passed += 1;
728 let t = t.super_fold_with(self);
729 self.binders_passed -= 1;
730 t
731 }
732
733 fn fold_region(&mut self, r: I::Region) -> I::Region {
734 match r.kind() {
740 ty::ReEarlyParam(data) => {
741 let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
742 match rk {
743 Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
744 Some(other) => self.region_param_expected(data, r, other),
745 None => self.region_param_out_of_range(data, r),
746 }
747 }
748 ty::ReBound(..)
749 | ty::ReLateParam(_)
750 | ty::ReStatic
751 | ty::RePlaceholder(_)
752 | ty::ReErased
753 | ty::ReError(_) => r,
754 ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
755 }
756 }
757
758 fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
759 if !t.has_param() {
760 return t;
761 }
762
763 match t.kind() {
764 ty::Param(p) => self.ty_for_param(p, t),
765 _ => t.super_fold_with(self),
766 }
767 }
768
769 fn fold_const(&mut self, c: I::Const) -> I::Const {
770 if let ty::ConstKind::Param(p) = c.kind() {
771 self.const_for_param(p, c)
772 } else {
773 c.super_fold_with(self)
774 }
775 }
776
777 fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
778 if p.has_param() { p.super_fold_with(self) } else { p }
779 }
780
781 fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
782 if c.has_param() { c.super_fold_with(self) } else { c }
783 }
784}
785
786impl<'a, I: Interner> ArgFolder<'a, I> {
787 fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
788 let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
790 let ty = match opt_ty {
791 Some(ty::GenericArgKind::Type(ty)) => ty,
792 Some(kind) => self.type_param_expected(p, source_ty, kind),
793 None => self.type_param_out_of_range(p, source_ty),
794 };
795
796 self.shift_vars_through_binders(ty)
797 }
798
799 #[cold]
800 #[inline(never)]
801 fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
802 {
::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!(
803 "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
804 p,
805 ty,
806 p.index(),
807 kind,
808 self.args,
809 )
810 }
811
812 #[cold]
813 #[inline(never)]
814 fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
815 {
::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!(
816 "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
817 p,
818 ty,
819 p.index(),
820 self.args,
821 )
822 }
823
824 fn const_for_param(&self, p: I::ParamConst, source_ct: I::Const) -> I::Const {
825 let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
827 let ct = match opt_ct {
828 Some(ty::GenericArgKind::Const(ct)) => ct,
829 Some(kind) => self.const_param_expected(p, source_ct, kind),
830 None => self.const_param_out_of_range(p, source_ct),
831 };
832
833 self.shift_vars_through_binders(ct)
834 }
835
836 #[cold]
837 #[inline(never)]
838 fn const_param_expected(
839 &self,
840 p: I::ParamConst,
841 ct: I::Const,
842 kind: ty::GenericArgKind<I>,
843 ) -> ! {
844 {
::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!(
845 "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
846 p,
847 ct,
848 p.index(),
849 kind,
850 self.args,
851 )
852 }
853
854 #[cold]
855 #[inline(never)]
856 fn const_param_out_of_range(&self, p: I::ParamConst, ct: I::Const) -> ! {
857 {
::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!(
858 "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
859 p,
860 ct,
861 p.index(),
862 self.args,
863 )
864 }
865
866 #[cold]
867 #[inline(never)]
868 fn region_param_expected(
869 &self,
870 ebr: I::EarlyParamRegion,
871 r: I::Region,
872 kind: ty::GenericArgKind<I>,
873 ) -> ! {
874 {
::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!(
875 "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
876 ebr,
877 r,
878 ebr.index(),
879 kind,
880 self.args,
881 )
882 }
883
884 #[cold]
885 #[inline(never)]
886 fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
887 {
::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!(
888 "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
889 ebr,
890 r,
891 ebr.index(),
892 self.args,
893 )
894 }
895
896 x;#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
939 fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
940 if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
941 val
942 } else {
943 ty::shift_vars(self.cx, val, self.binders_passed)
944 }
945 }
946
947 fn shift_region_through_binders(&self, region: I::Region) -> I::Region {
948 if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
949 region
950 } else {
951 ty::shift_region(self.cx, region, self.binders_passed)
952 }
953 }
954}
955
956#[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)]
976#[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))]
977#[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)]
978pub enum BoundVarIndexKind {
979 Bound(DebruijnIndex),
980 Canonical,
981}
982
983#[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)]
987#[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)]
988#[cfg_attr(
989 feature = "nightly",
990 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)
991)]
992pub struct Placeholder<I: Interner, T> {
993 #[lift(identity)]
994 pub universe: UniverseIndex,
995 pub bound: T,
996 #[type_foldable(identity)]
997 #[type_visitable(ignore)]
998 _tcx: PhantomData<fn() -> I>,
999}
1000
1001impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
1002 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1003 if self.universe == ty::UniverseIndex::ROOT {
1004 f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
1005 } else {
1006 f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
1007 }
1008 }
1009}
1010
1011#[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)]
1012#[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)]
1013#[cfg_attr(
1014 feature = "nightly",
1015 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)
1016)]
1017pub enum BoundRegionKind<I: Interner> {
1018 Anon,
1020
1021 NamedForPrinting(I::Symbol),
1025
1026 Named(I::DefId),
1028
1029 ClosureEnv,
1032}
1033
1034impl<I: Interner> fmt::Debug for ty::BoundRegionKind<I> {
1035 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1036 match *self {
1037 ty::BoundRegionKind::Anon => f.write_fmt(format_args!("BrAnon"))write!(f, "BrAnon"),
1038 ty::BoundRegionKind::NamedForPrinting(name) => {
1039 f.write_fmt(format_args!("BrNamedForPrinting({0:?})", name))write!(f, "BrNamedForPrinting({:?})", name)
1040 }
1041 ty::BoundRegionKind::Named(did) => {
1042 f.write_fmt(format_args!("BrNamed({0:?})", did))write!(f, "BrNamed({did:?})")
1043 }
1044 ty::BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("BrEnv"))write!(f, "BrEnv"),
1045 }
1046 }
1047}
1048
1049impl<I: Interner> BoundRegionKind<I> {
1050 pub fn is_named(&self, tcx: I) -> bool {
1051 self.get_name(tcx).is_some()
1052 }
1053
1054 pub fn get_name(&self, tcx: I) -> Option<I::Symbol> {
1055 match *self {
1056 ty::BoundRegionKind::Named(def_id) => {
1057 let name = tcx.item_name(def_id);
1058 if name.is_kw_underscore_lifetime() { None } else { Some(name) }
1059 }
1060 ty::BoundRegionKind::NamedForPrinting(name) => Some(name),
1061 _ => None,
1062 }
1063 }
1064
1065 pub fn get_id(&self) -> Option<I::DefId> {
1066 match *self {
1067 ty::BoundRegionKind::Named(id) => Some(id),
1068 _ => None,
1069 }
1070 }
1071}
1072
1073#[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)]
1074#[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)]
1075#[cfg_attr(
1076 feature = "nightly",
1077 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)
1078)]
1079pub enum BoundTyKind<I: Interner> {
1080 Anon,
1081 Param(I::DefId),
1082}
1083
1084#[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)]
1085#[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)]
1086#[cfg_attr(
1087 feature = "nightly",
1088 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)
1089)]
1090pub enum BoundVariableKind<I: Interner> {
1091 Ty(BoundTyKind<I>),
1092 Region(BoundRegionKind<I>),
1093 Const,
1094}
1095
1096impl<I: Interner> BoundVariableKind<I> {
1097 pub fn expect_region(self) -> BoundRegionKind<I> {
1098 match self {
1099 BoundVariableKind::Region(lt) => lt,
1100 _ => {
::core::panicking::panic_fmt(format_args!("expected a region, but found another kind"));
}panic!("expected a region, but found another kind"),
1101 }
1102 }
1103
1104 pub fn expect_ty(self) -> BoundTyKind<I> {
1105 match self {
1106 BoundVariableKind::Ty(ty) => ty,
1107 _ => {
::core::panicking::panic_fmt(format_args!("expected a type, but found another kind"));
}panic!("expected a type, but found another kind"),
1108 }
1109 }
1110
1111 pub fn expect_const(self) {
1112 match self {
1113 BoundVariableKind::Const => (),
1114 _ => {
::core::panicking::panic_fmt(format_args!("expected a const, but found another kind"));
}panic!("expected a const, but found another kind"),
1115 }
1116 }
1117}
1118
1119#[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)]
1120#[derive(GenericTypeVisitable)]
1121#[cfg_attr(
1122 feature = "nightly",
1123 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)
1124)]
1125pub struct BoundRegion<I: Interner> {
1126 pub var: ty::BoundVar,
1127 pub kind: BoundRegionKind<I>,
1128}
1129
1130impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1131 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1132 match self.kind {
1133 BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1134 BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1135 BoundRegionKind::Named(def) => {
1136 f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1137 }
1138 BoundRegionKind::NamedForPrinting(symbol) => {
1139 f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1140 }
1141 }
1142 }
1143}
1144
1145impl<I: Interner> BoundRegion<I> {
1146 pub fn var(self) -> ty::BoundVar {
1147 self.var
1148 }
1149
1150 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1151 {
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())
1152 }
1153}
1154
1155pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1156
1157impl<I: Interner> PlaceholderRegion<I> {
1158 pub fn universe(self) -> UniverseIndex {
1159 self.universe
1160 }
1161
1162 pub fn var(self) -> ty::BoundVar {
1163 self.bound.var()
1164 }
1165
1166 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1167 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1168 }
1169
1170 pub fn new(ui: UniverseIndex, bound: BoundRegion<I>) -> Self {
1171 Self { universe: ui, bound, _tcx: PhantomData }
1172 }
1173
1174 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1175 let bound = BoundRegion { var, kind: BoundRegionKind::Anon };
1176 Self { universe: ui, bound, _tcx: PhantomData }
1177 }
1178}
1179
1180#[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)]
1181#[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)]
1182#[cfg_attr(
1183 feature = "nightly",
1184 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)
1185)]
1186pub struct BoundTy<I: Interner> {
1187 #[lift(identity)]
1188 pub var: ty::BoundVar,
1189 pub kind: BoundTyKind<I>,
1190}
1191
1192impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1193 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1194 match self.kind {
1195 ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1196 ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1197 }
1198 }
1199}
1200
1201impl<I: Interner> BoundTy<I> {
1202 pub fn var(self) -> ty::BoundVar {
1203 self.var
1204 }
1205
1206 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1207 {
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())
1208 }
1209}
1210
1211pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1212
1213impl<I: Interner> PlaceholderType<I> {
1214 pub fn universe(self) -> UniverseIndex {
1215 self.universe
1216 }
1217
1218 pub fn var(self) -> ty::BoundVar {
1219 self.bound.var
1220 }
1221
1222 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1223 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1224 }
1225
1226 pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1227 Self { universe: ui, bound, _tcx: PhantomData }
1228 }
1229
1230 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1231 let bound = BoundTy { var, kind: BoundTyKind::Anon };
1232 Self { universe: ui, bound, _tcx: PhantomData }
1233 }
1234}
1235
1236#[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)]
1237#[derive(GenericTypeVisitable)]
1238#[cfg_attr(
1239 feature = "nightly",
1240 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)
1241)]
1242pub struct BoundConst<I: Interner> {
1243 pub var: ty::BoundVar,
1244 #[derive_where(skip(Debug))]
1245 pub _tcx: PhantomData<fn() -> I>,
1246}
1247
1248impl<I: Interner> BoundConst<I> {
1249 pub fn var(self) -> ty::BoundVar {
1250 self.var
1251 }
1252
1253 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1254 var.expect_const()
1255 }
1256
1257 pub fn new(var: ty::BoundVar) -> Self {
1258 Self { var, _tcx: PhantomData }
1259 }
1260}
1261
1262pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1263
1264impl<I: Interner> PlaceholderConst<I> {
1265 pub fn universe(self) -> UniverseIndex {
1266 self.universe
1267 }
1268
1269 pub fn var(self) -> ty::BoundVar {
1270 self.bound.var
1271 }
1272
1273 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1274 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1275 }
1276
1277 pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1278 Self { universe: ui, bound, _tcx: PhantomData }
1279 }
1280
1281 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1282 let bound = BoundConst::new(var);
1283 Self { universe: ui, bound, _tcx: PhantomData }
1284 }
1285
1286 pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1287 let mut candidates = env.caller_bounds().iter().filter_map(|clause| {
1288 match clause.kind().skip_binder() {
1290 ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1291 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());
1292
1293 match placeholder_ct.kind() {
1294 ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1295 Some(ty)
1296 }
1297 _ => None,
1298 }
1299 }
1300 _ => None,
1301 }
1302 });
1303
1304 let ty = candidates.next().unwrap_or_else(|| {
1311 {
::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1312 });
1313 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!(
1314 candidates.next().is_none(),
1315 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1316 );
1317 ty
1318 }
1319}