1use std::fmt;
2use std::hash::Hash;
3use std::marker::PhantomData;
4use std::ops::{ControlFlow, Deref};
5
6use derive_where::derive_where;
7#[cfg(feature = "nightly")]
8use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash, StableHash_NoContext};
9use rustc_type_ir_macros::{
10 GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
11};
12use tracing::instrument;
13
14use crate::data_structures::SsoHashSet;
15use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
16use crate::inherent::*;
17use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
18use crate::{
19 self as ty, Const, DebruijnIndex, Interner, PredicateProxy, Region, UniverseIndex, Unnormalized,
20};
21
22#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for Binder<I, T> where I: Interner,
T: ::core::clone::Clone {
#[inline]
fn clone(&self) -> Self {
match self {
Binder {
value: ref __field_value, bound_vars: ref __field_bound_vars }
=>
Binder {
value: ::core::clone::Clone::clone(__field_value),
bound_vars: ::core::clone::Clone::clone(__field_bound_vars),
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for Binder<I, T> where I: Interner,
T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for Binder<I, T> where I: Interner,
T: ::core::hash::Hash {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
Binder {
value: ref __field_value, bound_vars: ref __field_bound_vars }
=> {
::core::hash::Hash::hash(__field_value, __state);
::core::hash::Hash::hash(__field_bound_vars, __state);
}
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for Binder<I, T> where
I: Interner, T: ::core::cmp::PartialEq {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(Binder {
value: ref __field_value, bound_vars: ref __field_bound_vars
}, Binder {
value: ref __other_field_value,
bound_vars: ref __other_field_bound_vars }) =>
true &&
::core::cmp::PartialEq::eq(__field_value,
__other_field_value) &&
::core::cmp::PartialEq::eq(__field_bound_vars,
__other_field_bound_vars),
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::fmt::Debug for Binder<I, T> where I: Interner,
T: ::core::fmt::Debug {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
Binder {
value: ref __field_value, bound_vars: ref __field_bound_vars }
=> {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "Binder");
::core::fmt::DebugStruct::field(&mut __builder, "value",
__field_value);
::core::fmt::DebugStruct::field(&mut __builder, "bound_vars",
__field_bound_vars);
::core::fmt::DebugStruct::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner, T)]
29#[derive(const _: () =
{
unsafe impl<I: Interner, T, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for Binder<I, T> where
T: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::BoundVarKinds: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
Binder { value: ref __binding_0, bound_vars: ref __binding_1
} => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
}
}
}
}
};GenericTypeVisitable, const _: () =
{
impl<I: Interner, T, J> ::rustc_type_ir::lift::Lift<J> for
Binder<I, T> where J: Interner, I: ::rustc_type_ir::LiftInto<J>,
T: ::rustc_type_ir::lift::Lift<J> {
type Lifted =
Binder<J, <T as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
Binder { value: __binding_0, bound_vars: __binding_1 } => {
Binder {
value: __binding_0.lift_to_interner(interner),
bound_vars: __binding_1.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic)]
30#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
for Binder<I, T> where
T: ::rustc_data_structures::stable_hash::StableHash,
I::BoundVarKinds: ::rustc_data_structures::stable_hash::StableHash
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Binder { value: ref __binding_0, bound_vars: ref __binding_1
} => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext))]
31pub struct Binder<I: Interner, T> {
32 value: T,
33 bound_vars: I::BoundVarKinds,
34}
35
36impl<I: Interner, T: Eq> Eq for Binder<I, T> {}
37
38impl<I: Interner, T> Binder<I, T>
39where
40 T: TypeVisitable<I>,
41{
42 #[track_caller]
47 pub fn dummy(value: T) -> Binder<I, T> {
48 if !!value.has_escaping_bound_vars() {
{
::core::panicking::panic_fmt(format_args!("`{0:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder.",
value));
}
};assert!(
49 !value.has_escaping_bound_vars(),
50 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
51 );
52 Binder { value, bound_vars: Default::default() }
53 }
54
55 pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
56 if truecfg!(debug_assertions) {
57 let mut validator = ValidateBoundVars::new(bound_vars);
58 let _ = value.visit_with(&mut validator);
59 }
60 Binder { value, bound_vars }
61 }
62}
63
64impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
65 fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
66 folder.try_fold_binder(self)
67 }
68
69 fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
70 folder.fold_binder(self)
71 }
72}
73
74impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
75 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
76 visitor.visit_binder(self)
77 }
78}
79
80impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
81 fn try_super_fold_with<F: FallibleTypeFolder<I>>(
82 self,
83 folder: &mut F,
84 ) -> Result<Self, F::Error> {
85 self.try_map_bound(|t| t.try_fold_with(folder))
86 }
87
88 fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
89 self.map_bound(|t| t.fold_with(folder))
90 }
91}
92
93impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
94 fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
95 self.as_ref().skip_binder().visit_with(visitor)
96 }
97}
98
99impl<I: Interner, T> Binder<I, T> {
100 pub fn skip_binder(self) -> T {
114 self.value
115 }
116
117 pub fn bound_vars(&self) -> I::BoundVarKinds {
118 self.bound_vars
119 }
120
121 pub fn as_ref(&self) -> Binder<I, &T> {
122 Binder { value: &self.value, bound_vars: self.bound_vars }
123 }
124
125 pub fn as_deref(&self) -> Binder<I, &T::Target>
126 where
127 T: Deref,
128 {
129 Binder { value: &self.value, bound_vars: self.bound_vars }
130 }
131
132 pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
133 where
134 F: FnOnce(&T) -> U,
135 {
136 self.as_ref().map_bound(f)
137 }
138
139 pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
140 where
141 F: FnOnce(T) -> U,
142 {
143 let Binder { value, bound_vars } = self;
144 let value = f(value);
145 if truecfg!(debug_assertions) {
146 let mut validator = ValidateBoundVars::new(bound_vars);
147 let _ = value.visit_with(&mut validator);
148 }
149 Binder { value, bound_vars }
150 }
151
152 pub fn map_bound_no_validate_bound_vars<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
156 where
157 F: FnOnce(T) -> U,
158 {
159 let Binder { value, bound_vars } = self;
160 let value = f(value);
161 Binder { value, bound_vars }
162 }
163
164 pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
165 where
166 F: FnOnce(T) -> Result<U, E>,
167 {
168 let Binder { value, bound_vars } = self;
169 let value = f(value)?;
170 if truecfg!(debug_assertions) {
171 let mut validator = ValidateBoundVars::new(bound_vars);
172 let _ = value.visit_with(&mut validator);
173 }
174 Ok(Binder { value, bound_vars })
175 }
176
177 pub fn rebind<U>(&self, value: U) -> Binder<I, U>
187 where
188 U: TypeVisitable<I>,
189 {
190 Binder::bind_with_vars(value, self.bound_vars)
191 }
192
193 pub fn no_bound_vars(self) -> Option<T>
204 where
205 T: TypeVisitable<I>,
206 {
207 if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
209 }
210}
211
212impl<I: Interner, T> Binder<I, Option<T>> {
213 pub fn transpose(self) -> Option<Binder<I, T>> {
214 let Binder { value, bound_vars } = self;
215 value.map(|value| Binder { value, bound_vars })
216 }
217}
218
219impl<I: Interner, T: IntoIterator> Binder<I, T> {
220 pub fn iter(self) -> impl Iterator<Item = Binder<I, T::Item>> {
221 let Binder { value, bound_vars } = self;
222 value.into_iter().map(move |value| Binder { value, bound_vars })
223 }
224}
225
226pub struct ValidateBoundVars<I: Interner> {
227 bound_vars: I::BoundVarKinds,
228 binder_index: ty::DebruijnIndex,
229 visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
233}
234
235impl<I: Interner> ValidateBoundVars<I> {
236 pub fn new(bound_vars: I::BoundVarKinds) -> Self {
237 ValidateBoundVars {
238 bound_vars,
239 binder_index: ty::INNERMOST,
240 visited: SsoHashSet::default(),
241 }
242 }
243}
244
245impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
246 type Result = ControlFlow<()>;
247
248 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
249 self.binder_index.shift_in(1);
250 let result = t.super_visit_with(self);
251 self.binder_index.shift_out(1);
252 result
253 }
254
255 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
256 if t.outer_exclusive_binder() <= self.binder_index
257 || !self.visited.insert((self.binder_index, t))
258 {
259 return ControlFlow::Continue(());
260 }
261 match t.kind() {
262 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), bound_ty)
263 if debruijn == self.binder_index =>
264 {
265 let idx = bound_ty.var().as_usize();
266 let Some(bound_var) = self.bound_vars.get(idx) else {
267 {
::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);
268 };
269 bound_ty.assert_eq(bound_var);
270 }
271 _ => {}
272 };
273
274 t.super_visit_with(self)
275 }
276
277 fn visit_const(&mut self, c: Const<I>) -> Self::Result {
278 if c.outer_exclusive_binder() <= self.binder_index {
279 return ControlFlow::Continue(());
280 }
281 match c.kind() {
282 ty::ConstKind::Bound(debruijn, bound_const)
283 if debruijn == ty::BoundVarIndexKind::Bound(self.binder_index) =>
284 {
285 let idx = bound_const.var().as_usize();
286 let Some(bound_var) = self.bound_vars.get(idx) else {
287 {
::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);
288 };
289 bound_const.assert_eq(bound_var);
290 }
291 _ => {}
292 };
293
294 c.super_visit_with(self)
295 }
296
297 fn visit_region(&mut self, r: Region<I>) -> Self::Result {
298 match r.kind() {
299 ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => {
300 let idx = br.var().as_usize();
301 let Some(bound_var) = self.bound_vars.get(idx) else {
302 {
::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);
303 };
304 br.assert_eq(bound_var);
305 }
306
307 _ => (),
308 };
309
310 ControlFlow::Continue(())
311 }
312}
313
314#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for EarlyBinder<I, T> where
I: Interner, T: ::core::clone::Clone {
#[inline]
fn clone(&self) -> Self {
match self {
EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
=>
EarlyBinder {
value: ::core::clone::Clone::clone(__field_value),
_tcx: ::core::clone::Clone::clone(__field__tcx),
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for EarlyBinder<I, T> where
I: Interner, T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialOrd for EarlyBinder<I, T> where
I: Interner, T: ::core::cmp::PartialOrd {
#[inline]
fn partial_cmp(&self, __other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
match (self, __other) {
(EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
EarlyBinder {
value: ref __other_field_value, _tcx: ref __other_field__tcx
}) =>
match ::core::cmp::PartialOrd::partial_cmp(__field_value,
__other_field_value) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
match ::core::cmp::PartialOrd::partial_cmp(__field__tcx,
__other_field__tcx) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
::core::option::Option::Some(::core::cmp::Ordering::Equal),
__cmp => __cmp,
},
__cmp => __cmp,
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Ord for EarlyBinder<I, T> where I: Interner,
T: ::core::cmp::Ord {
#[inline]
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
match (self, __other) {
(EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
EarlyBinder {
value: ref __other_field_value, _tcx: ref __other_field__tcx
}) =>
match ::core::cmp::Ord::cmp(__field_value,
__other_field_value) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(__field__tcx,
__other_field__tcx) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ordering::Equal,
__cmp => __cmp,
},
__cmp => __cmp,
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for EarlyBinder<I, T> where
I: Interner, T: ::core::cmp::PartialEq {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx },
EarlyBinder {
value: ref __other_field_value, _tcx: ref __other_field__tcx
}) =>
true &&
::core::cmp::PartialEq::eq(__field_value,
__other_field_value) &&
::core::cmp::PartialEq::eq(__field__tcx,
__other_field__tcx),
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for EarlyBinder<I, T> where
I: Interner, T: ::core::hash::Hash {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
=> {
::core::hash::Hash::hash(__field_value, __state);
::core::hash::Hash::hash(__field__tcx, __state);
}
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::fmt::Debug for EarlyBinder<I, T> where
I: Interner, T: ::core::fmt::Debug {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
EarlyBinder { value: ref __field_value, _tcx: ref __field__tcx }
=> {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "EarlyBinder");
::core::fmt::DebugStruct::field(&mut __builder, "value",
__field_value);
::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
}
}
}
}#[derive_where(Clone, Copy, PartialOrd, Ord, PartialEq, Hash, Debug; I: Interner, T)]
320#[derive(const _: () =
{
unsafe impl<I: Interner, T, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for EarlyBinder<I, T>
where T: ::rustc_type_ir::GenericTypeVisitable<__V>,
PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
{
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
} => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
}
}
}
}
};GenericTypeVisitable)]
321#[cfg_attr(
322 feature = "nightly",
323 derive(const _: () =
{
impl<I: Interner, T, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for EarlyBinder<I, T> where
T: ::rustc_serialize::Encodable<__E>,
PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let EarlyBinder {
value: ref __binding_0, _tcx: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, T, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for EarlyBinder<I, T> where
T: ::rustc_serialize::Decodable<__D>,
PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
EarlyBinder {
value: ::rustc_serialize::Decodable::decode(__decoder),
_tcx: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
for EarlyBinder<I, T> where
T: ::rustc_data_structures::stable_hash::StableHash,
PhantomData<fn()
-> I>: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
EarlyBinder { value: ref __binding_0, _tcx: ref __binding_1
} => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
324)]
325pub struct EarlyBinder<I: Interner, T> {
326 value: T,
327 #[derive_where(skip(Debug))]
328 _tcx: PhantomData<fn() -> I>,
329}
330
331impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
332
333#[cfg(feature = "nightly")]
335macro_rules! generate { ($( $tt:tt )*) => { $( $tt )* } }
336
337#[cfg(feature = "nightly")]
338generate!(
339 impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}
341 impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
343);
344
345impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
346 pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {
347 let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization();
349 EarlyBinder { value, _tcx: PhantomData }
350 }
351}
352
353impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> {
354 pub fn bind_iter(value: T) -> EarlyBinder<I, T> {
355 #[cfg(debug_assertions)]
356 {
357 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()));
358 }
359
360 EarlyBinder { value, _tcx: PhantomData }
361 }
362}
363
364impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> {
365 pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> {
366 if true {
if !!value.has_rigid_aliases() {
::core::panicking::panic("assertion failed: !value.has_rigid_aliases()")
};
};debug_assert!(!value.has_rigid_aliases());
367 EarlyBinder { value, _tcx: PhantomData }
368 }
369}
370
371impl<I: Interner, T> EarlyBinder<I, T> {
372 pub fn bind_unchecked(value: T) -> EarlyBinder<I, T> {
375 EarlyBinder { value, _tcx: PhantomData }
376 }
377}
378
379impl<I: Interner, T> EarlyBinder<I, T> {
380 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
381 EarlyBinder { value: &self.value, _tcx: PhantomData }
382 }
383
384 pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
385 where
386 F: FnOnce(&T) -> U,
387 {
388 self.as_ref().map_bound(f)
389 }
390
391 pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
392 where
393 F: FnOnce(T) -> U,
394 {
395 let value = f(self.value);
396 EarlyBinder { value, _tcx: PhantomData }
397 }
398
399 pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
400 where
401 F: FnOnce(T) -> Result<U, E>,
402 {
403 let value = f(self.value)?;
404 Ok(EarlyBinder { value, _tcx: PhantomData })
405 }
406
407 pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U> {
408 EarlyBinder { value, _tcx: PhantomData }
409 }
410
411 pub fn skip_binder(self) -> T {
428 self.value
429 }
430}
431
432impl<I: Interner> EarlyBinder<I, ty::TraitRef<I>> {
433 pub fn def_id(&self) -> I::TraitId {
434 self.value.def_id
435 }
436}
437
438impl<I: Interner, T> EarlyBinder<I, Option<T>> {
439 pub fn transpose(self) -> Option<EarlyBinder<I, T>> {
440 self.value.map(|value| EarlyBinder { value, _tcx: PhantomData })
441 }
442}
443
444impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
445where
446 Iter::Item: TypeFoldable<I>,
447{
448 pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
449 where
450 A: SliceLike<Item = I::GenericArg>,
451 {
452 IterInstantiated { it: self.value.into_iter(), cx, args }
453 }
454
455 pub fn iter_identity(self) -> impl Iterator<Item = Unnormalized<I, Iter::Item>> {
458 self.value.into_iter().map(Unnormalized::new)
459 }
460}
461
462pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
463 it: Iter::IntoIter,
464 cx: I,
465 args: A,
466}
467
468impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
469where
470 Iter::Item: TypeFoldable<I>,
471 A: SliceLike<Item = I::GenericArg>,
472{
473 type Item = Unnormalized<I, Iter::Item>;
474
475 fn next(&mut self) -> Option<Self::Item> {
476 Some(
477 EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
478 .instantiate(self.cx, self.args),
479 )
480 }
481
482 fn size_hint(&self) -> (usize, Option<usize>) {
483 self.it.size_hint()
484 }
485}
486
487impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
488where
489 Iter::IntoIter: DoubleEndedIterator,
490 Iter::Item: TypeFoldable<I>,
491 A: SliceLike<Item = I::GenericArg>,
492{
493 fn next_back(&mut self) -> Option<Self::Item> {
494 Some(
495 EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
496 .instantiate(self.cx, self.args),
497 )
498 }
499}
500
501impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
502where
503 Iter::IntoIter: ExactSizeIterator,
504 Iter::Item: TypeFoldable<I>,
505 A: SliceLike<Item = I::GenericArg>,
506{
507}
508
509impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
510where
511 Iter::Item: Deref,
512 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
513{
514 pub fn iter_instantiated_copied(
515 self,
516 cx: I,
517 args: &'s [I::GenericArg],
518 ) -> IterInstantiatedCopied<'s, I, Iter> {
519 IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
520 }
521
522 pub fn iter_identity_copied(self) -> IterIdentityCopied<I, Iter> {
525 IterIdentityCopied { it: self.value.into_iter(), _tcx: PhantomData }
526 }
527}
528
529pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
530 it: Iter::IntoIter,
531 cx: I,
532 args: &'a [I::GenericArg],
533}
534
535impl<'a, I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone
536 for IterInstantiatedCopied<'a, I, Iter>
537{
538 fn clone(&self) -> IterInstantiatedCopied<'a, I, Iter> {
539 IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args }
540 }
541}
542
543impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
544where
545 Iter::Item: Deref,
546 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
547{
548 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
549
550 fn next(&mut self) -> Option<Self::Item> {
551 self.it.next().map(|value| {
552 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
553 })
554 }
555
556 fn size_hint(&self) -> (usize, Option<usize>) {
557 self.it.size_hint()
558 }
559}
560
561impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, I, Iter>
562where
563 Iter::IntoIter: DoubleEndedIterator,
564 Iter::Item: Deref,
565 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
566{
567 fn next_back(&mut self) -> Option<Self::Item> {
568 self.it.next_back().map(|value| {
569 EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
570 })
571 }
572}
573
574impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, I, Iter>
575where
576 Iter::IntoIter: ExactSizeIterator,
577 Iter::Item: Deref,
578 <Iter::Item as Deref>::Target: Copy + TypeFoldable<I>,
579{
580}
581
582pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
583 it: Iter::IntoIter,
584 _tcx: PhantomData<fn() -> I>,
585}
586
587impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> {
588 fn clone(&self) -> IterIdentityCopied<I, Iter> {
589 IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx }
590 }
591}
592
593impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
594where
595 Iter::Item: Deref,
596 <Iter::Item as Deref>::Target: Copy,
597{
598 type Item = Unnormalized<I, <Iter::Item as Deref>::Target>;
599
600 fn next(&mut self) -> Option<Self::Item> {
601 self.it.next().map(|i| Unnormalized::new(*i))
602 }
603
604 fn size_hint(&self) -> (usize, Option<usize>) {
605 self.it.size_hint()
606 }
607}
608
609impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterIdentityCopied<I, Iter>
610where
611 Iter::IntoIter: DoubleEndedIterator,
612 Iter::Item: Deref,
613 <Iter::Item as Deref>::Target: Copy,
614{
615 fn next_back(&mut self) -> Option<Self::Item> {
616 self.it.next_back().map(|i| Unnormalized::new(*i))
617 }
618}
619
620impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterIdentityCopied<I, Iter>
621where
622 Iter::IntoIter: ExactSizeIterator,
623 Iter::Item: Deref,
624 <Iter::Item as Deref>::Target: Copy,
625{
626}
627pub struct EarlyBinderIter<I, T> {
628 t: T,
629 _tcx: PhantomData<I>,
630}
631
632impl<I: Interner, T: IntoIterator> EarlyBinder<I, T> {
633 pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> {
634 EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData }
635 }
636}
637
638impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
639 type Item = EarlyBinder<I, T::Item>;
640
641 fn next(&mut self) -> Option<Self::Item> {
642 self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData })
643 }
644
645 fn size_hint(&self) -> (usize, Option<usize>) {
646 self.t.size_hint()
647 }
648}
649
650impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
651 pub fn instantiate<A>(self, cx: I, args: A) -> Unnormalized<I, T>
652 where
653 A: SliceLike<Item = I::GenericArg>,
654 {
655 if args.is_empty() {
659 if !!self.value.has_param() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has parameters, but no args were provided in instantiate",
self.value));
}
};assert!(
660 !self.value.has_param(),
661 "{:?} has parameters, but no args were provided in instantiate",
662 self.value,
663 );
664 return Unnormalized::new(self.value);
665 }
666 let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
667 Unnormalized::new(self.value.fold_with(&mut folder))
668 }
669
670 pub fn instantiate_identity(self) -> Unnormalized<I, T> {
679 Unnormalized::new(self.value)
688 }
689
690 pub fn no_bound_vars(self) -> Option<T> {
692 if !self.value.has_param() { Some(self.value) } else { None }
693 }
694}
695
696struct ArgFolder<'a, I: Interner> {
700 cx: I,
701 args: &'a [I::GenericArg],
702
703 binders_passed: u32,
705}
706
707impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
708 #[inline]
709 fn cx(&self) -> I {
710 self.cx
711 }
712
713 fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
714 self.binders_passed += 1;
715 let t = t.super_fold_with(self);
716 self.binders_passed -= 1;
717 t
718 }
719
720 fn fold_region(&mut self, r: Region<I>) -> Region<I> {
721 match r.kind() {
727 ty::ReEarlyParam(data) => {
728 let rk = self.args.get(data.index() as usize).map(|arg| arg.kind());
729 match rk {
730 Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
731 Some(other) => self.region_param_expected(data, r, other),
732 None => self.region_param_out_of_range(data, r),
733 }
734 }
735 ty::ReBound(..)
736 | ty::ReLateParam(_)
737 | ty::ReStatic
738 | ty::RePlaceholder(_)
739 | ty::ReErased
740 | ty::ReError(_) => r,
741 ty::ReVar(_) => { ::core::panicking::panic_fmt(format_args!("unexpected region: {0:?}", r)); }panic!("unexpected region: {r:?}"),
742 }
743 }
744
745 fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
746 if !t.has_param() {
747 return t;
748 }
749
750 match t.kind() {
751 ty::Param(p) => self.ty_for_param(p, t),
752 _ => t.super_fold_with(self),
753 }
754 }
755
756 fn fold_const(&mut self, c: Const<I>) -> Const<I> {
757 if let ty::ConstKind::Param(p) = c.kind() {
758 self.const_for_param(p, c)
759 } else {
760 c.super_fold_with(self)
761 }
762 }
763
764 fn fold_predicate<P: PredicateProxy<I>>(&mut self, p: P) -> P {
765 if p.has_param() { p.super_fold_with(self) } else { p }
766 }
767
768 fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses {
769 if c.has_param() { c.super_fold_with(self) } else { c }
770 }
771}
772
773impl<'a, I: Interner> ArgFolder<'a, I> {
774 fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
775 let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
777 let ty = match opt_ty {
778 Some(ty::GenericArgKind::Type(ty)) => ty,
779 Some(kind) => self.type_param_expected(p, source_ty, kind),
780 None => self.type_param_out_of_range(p, source_ty),
781 };
782
783 self.shift_vars_through_binders(ty)
784 }
785
786 #[cold]
787 #[inline(never)]
788 fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind<I>) -> ! {
789 {
::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!(
790 "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}",
791 p,
792 ty,
793 p.index(),
794 kind,
795 self.args,
796 )
797 }
798
799 #[cold]
800 #[inline(never)]
801 fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! {
802 {
::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!(
803 "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}",
804 p,
805 ty,
806 p.index(),
807 self.args,
808 )
809 }
810
811 fn const_for_param(&self, p: I::ParamConst, source_ct: Const<I>) -> Const<I> {
812 let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind());
814 let ct = match opt_ct {
815 Some(ty::GenericArgKind::Const(ct)) => ct,
816 Some(kind) => self.const_param_expected(p, source_ct, kind),
817 None => self.const_param_out_of_range(p, source_ct),
818 };
819
820 self.shift_vars_through_binders(ct)
821 }
822
823 #[cold]
824 #[inline(never)]
825 fn const_param_expected(
826 &self,
827 p: I::ParamConst,
828 ct: Const<I>,
829 kind: ty::GenericArgKind<I>,
830 ) -> ! {
831 {
::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!(
832 "expected const for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
833 p,
834 ct,
835 p.index(),
836 kind,
837 self.args,
838 )
839 }
840
841 #[cold]
842 #[inline(never)]
843 fn const_param_out_of_range(&self, p: I::ParamConst, ct: Const<I>) -> ! {
844 {
::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!(
845 "const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
846 p,
847 ct,
848 p.index(),
849 self.args,
850 )
851 }
852
853 #[cold]
854 #[inline(never)]
855 fn region_param_expected(
856 &self,
857 ebr: I::EarlyParamRegion,
858 r: Region<I>,
859 kind: ty::GenericArgKind<I>,
860 ) -> ! {
861 {
::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!(
862 "expected region for `{:?}` ({:?}/{}) but found {:?} when instantiating args={:?}",
863 ebr,
864 r,
865 ebr.index(),
866 kind,
867 self.args,
868 )
869 }
870
871 #[cold]
872 #[inline(never)]
873 fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: Region<I>) -> ! {
874 {
::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!(
875 "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
876 ebr,
877 r,
878 ebr.index(),
879 self.args,
880 )
881 }
882
883 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("shift_vars_through_binders",
"rustc_type_ir::binder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5d8fec0669a64607db9ccbf663e7c23125bf4748/compiler/rustc_type_ir/src/binder.rs"),
::tracing_core::__macro_support::Option::Some(925u32),
::tracing_core::__macro_support::Option::Some("rustc_type_ir::binder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("val")
}> =
::tracing::__macro_support::FieldName::new("val");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("binders_passed")
}> =
::tracing::__macro_support::FieldName::new("binders_passed");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&val)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&self.binders_passed
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: T = loop {};
return __tracing_attr_fake_return;
}
{
if self.binders_passed == 0 ||
!val.has_escaping_bound_vars() {
val
} else { ty::shift_vars(self.cx, val, self.binders_passed) }
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/5d8fec0669a64607db9ccbf663e7c23125bf4748/compiler/rustc_type_ir/src/binder.rs:925",
"rustc_type_ir::binder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5d8fec0669a64607db9ccbf663e7c23125bf4748/compiler/rustc_type_ir/src/binder.rs"),
::tracing_core::__macro_support::Option::Some(925u32),
::tracing_core::__macro_support::Option::Some("rustc_type_ir::binder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
926 fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
927 if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
928 val
929 } else {
930 ty::shift_vars(self.cx, val, self.binders_passed)
931 }
932 }
933
934 fn shift_region_through_binders(&self, region: Region<I>) -> Region<I> {
935 if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
936 region
937 } else {
938 ty::shift_region(self.cx, region, self.binders_passed)
939 }
940 }
941}
942
943#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for BoundVarIndexKind { }
#[automatically_derived]
impl ::core::clone::Clone for BoundVarIndexKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<DebruijnIndex>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for BoundVarIndexKind { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for BoundVarIndexKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Bound(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Bound",
&__self_0),
Self::Canonical =>
::core::fmt::Formatter::write_str(f, "Canonical"),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for BoundVarIndexKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for BoundVarIndexKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Bound(__self_0), Self::Bound(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for BoundVarIndexKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DebruijnIndex>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for BoundVarIndexKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Bound(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
963#[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))]
964#[derive(const _: () =
{
impl<I> ::rustc_type_ir::TypeVisitable<I> for BoundVarIndexKind where
I: Interner {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
BoundVarIndexKind::Bound(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
BoundVarIndexKind::Canonical => {}
}
<__V::Result as ::rustc_type_ir::VisitorResult>::output()
}
}
};TypeVisitable_Generic, const _: () =
{
unsafe impl<__V> ::rustc_type_ir::GenericTypeVisitable<__V> for
BoundVarIndexKind where
DebruijnIndex: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundVarIndexKind::Bound(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
BoundVarIndexKind::Canonical => {}
}
}
}
};GenericTypeVisitable, const _: () =
{
impl<I> ::rustc_type_ir::TypeFoldable<I> for BoundVarIndexKind where
I: Interner {
fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
BoundVarIndexKind::Bound(__binding_0) => {
BoundVarIndexKind::Bound(::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
BoundVarIndexKind::Canonical => {
BoundVarIndexKind::Canonical
}
})
}
fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
__folder: &mut __F) -> Self {
match self {
BoundVarIndexKind::Bound(__binding_0) => {
BoundVarIndexKind::Bound(::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder))
}
BoundVarIndexKind::Canonical => {
BoundVarIndexKind::Canonical
}
}
}
}
};TypeFoldable_Generic)]
965pub enum BoundVarIndexKind {
966 Bound(DebruijnIndex),
967 Canonical,
968}
969
970#[automatically_derived]
impl<I: Interner, T> ::core::clone::Clone for Placeholder<I, T> where
I: Interner, T: ::core::clone::Clone {
#[inline]
fn clone(&self) -> Self {
match self {
Placeholder {
universe: ref __field_universe,
bound: ref __field_bound,
_tcx: ref __field__tcx } =>
Placeholder {
universe: ::core::clone::Clone::clone(__field_universe),
bound: ::core::clone::Clone::clone(__field_bound),
_tcx: ::core::clone::Clone::clone(__field__tcx),
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::marker::Copy for Placeholder<I, T> where
I: Interner, T: ::core::marker::Copy {
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialOrd for Placeholder<I, T> where
I: Interner, T: ::core::cmp::PartialOrd {
#[inline]
fn partial_cmp(&self, __other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
match (self, __other) {
(Placeholder {
universe: ref __field_universe,
bound: ref __field_bound,
_tcx: ref __field__tcx }, Placeholder {
universe: ref __other_field_universe,
bound: ref __other_field_bound,
_tcx: ref __other_field__tcx }) =>
match ::core::cmp::PartialOrd::partial_cmp(__field_universe,
__other_field_universe) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
match ::core::cmp::PartialOrd::partial_cmp(__field_bound,
__other_field_bound) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
match ::core::cmp::PartialOrd::partial_cmp(__field__tcx,
__other_field__tcx) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
::core::option::Option::Some(::core::cmp::Ordering::Equal),
__cmp => __cmp,
},
__cmp => __cmp,
},
__cmp => __cmp,
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Ord for Placeholder<I, T> where I: Interner,
T: ::core::cmp::Ord {
#[inline]
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
match (self, __other) {
(Placeholder {
universe: ref __field_universe,
bound: ref __field_bound,
_tcx: ref __field__tcx }, Placeholder {
universe: ref __other_field_universe,
bound: ref __other_field_bound,
_tcx: ref __other_field__tcx }) =>
match ::core::cmp::Ord::cmp(__field_universe,
__other_field_universe) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(__field_bound,
__other_field_bound) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(__field__tcx,
__other_field__tcx) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ordering::Equal,
__cmp => __cmp,
},
__cmp => __cmp,
},
__cmp => __cmp,
},
}
}
}
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::PartialEq for Placeholder<I, T> where
I: Interner, T: ::core::cmp::PartialEq {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(Placeholder {
universe: ref __field_universe,
bound: ref __field_bound,
_tcx: ref __field__tcx }, Placeholder {
universe: ref __other_field_universe,
bound: ref __other_field_bound,
_tcx: ref __other_field__tcx }) =>
true &&
::core::cmp::PartialEq::eq(__field_universe,
__other_field_universe) &&
::core::cmp::PartialEq::eq(__field_bound,
__other_field_bound) &&
::core::cmp::PartialEq::eq(__field__tcx,
__other_field__tcx),
}
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner, T> DeriveWhereAssertEq for Placeholder<I, T> where
I: Interner, T: ::core::cmp::Eq {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<UniverseIndex>;
let _: __AssertEq<T>;
let _: __AssertEq<PhantomData<fn() -> I>>;
}
}
};
#[automatically_derived]
impl<I: Interner, T> ::core::cmp::Eq for Placeholder<I, T> where I: Interner,
T: ::core::cmp::Eq {
}
#[automatically_derived]
impl<I: Interner, T> ::core::hash::Hash for Placeholder<I, T> where
I: Interner, T: ::core::hash::Hash {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
Placeholder {
universe: ref __field_universe,
bound: ref __field_bound,
_tcx: ref __field__tcx } => {
::core::hash::Hash::hash(__field_universe, __state);
::core::hash::Hash::hash(__field_bound, __state);
::core::hash::Hash::hash(__field__tcx, __state);
}
}
}
}#[derive_where(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash; I: Interner, T)]
974#[derive(const _: () =
{
impl<I: Interner, T> ::rustc_type_ir::TypeVisitable<I> for
Placeholder<I, T> where I: Interner,
T: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
Placeholder {
universe: ref __binding_0, bound: ref __binding_1, .. } => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_type_ir::VisitorResult>::output()
}
}
};TypeVisitable_Generic, const _: () =
{
impl<I: Interner, T> ::rustc_type_ir::TypeFoldable<I> for
Placeholder<I, T> where I: Interner,
T: ::rustc_type_ir::TypeFoldable<I>,
T: ::rustc_type_ir::TypeFoldable<I> {
fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
Placeholder {
universe: __binding_0, bound: __binding_1, _tcx: __binding_2
} => {
Placeholder {
universe: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
bound: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
_tcx: __binding_2,
}
}
})
}
fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
__folder: &mut __F) -> Self {
match self {
Placeholder {
universe: __binding_0, bound: __binding_1, _tcx: __binding_2
} => {
Placeholder {
universe: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
bound: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
__folder),
_tcx: __binding_2,
}
}
}
}
}
};TypeFoldable_Generic, const _: () =
{
unsafe impl<I: Interner, T, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for Placeholder<I, T>
where UniverseIndex: ::rustc_type_ir::GenericTypeVisitable<__V>,
T: ::rustc_type_ir::GenericTypeVisitable<__V>,
PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
{
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
Placeholder {
universe: ref __binding_0,
bound: ref __binding_1,
_tcx: ref __binding_2 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_2,
__visitor);
}
}
}
}
}
};GenericTypeVisitable, const _: () =
{
impl<I: Interner, T, J> ::rustc_type_ir::lift::Lift<J> for
Placeholder<I, T> where J: Interner,
I: ::rustc_type_ir::LiftInto<J>, T: ::rustc_type_ir::lift::Lift<J>
{
type Lifted =
Placeholder<J, <T as ::rustc_type_ir::lift::Lift<J>>::Lifted>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
Placeholder {
universe: __binding_0, bound: __binding_1, _tcx: __binding_2
} => {
Placeholder {
universe: __binding_0,
bound: __binding_1.lift_to_interner(interner),
_tcx: PhantomData,
}
}
}
}
}
};Lift_Generic)]
975#[cfg_attr(
976 feature = "nightly",
977 derive(const _: () =
{
impl<I: Interner, T, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for Placeholder<I, T> where
T: ::rustc_serialize::Encodable<__E>,
PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let Placeholder {
universe: ref __binding_0,
bound: ref __binding_1,
_tcx: ref __binding_2 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, T, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for Placeholder<I, T> where
T: ::rustc_serialize::Decodable<__D>,
PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
Placeholder {
universe: ::rustc_serialize::Decodable::decode(__decoder),
bound: ::rustc_serialize::Decodable::decode(__decoder),
_tcx: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner, T> ::rustc_data_structures::stable_hash::StableHash
for Placeholder<I, T> where
T: ::rustc_data_structures::stable_hash::StableHash,
PhantomData<fn()
-> I>: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Placeholder {
universe: ref __binding_0,
bound: ref __binding_1,
_tcx: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
978)]
979pub struct Placeholder<I: Interner, T> {
980 #[lift(identity)]
981 pub universe: UniverseIndex,
982 pub bound: T,
983 #[type_foldable(identity)]
984 #[type_visitable(ignore)]
985 _tcx: PhantomData<fn() -> I>,
986}
987
988impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
989 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
990 if self.universe == ty::UniverseIndex::ROOT {
991 f.write_fmt(format_args!("!{0:?}", self.bound))write!(f, "!{:?}", self.bound)
992 } else {
993 f.write_fmt(format_args!("!{0}_{1:?}", self.universe.index(), self.bound))write!(f, "!{}_{:?}", self.universe.index(), self.bound)
994 }
995 }
996}
997
998#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundRegionKind<I> where
I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundRegionKind<I> where
I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundRegionKind<I> where
I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
if ::core::mem::discriminant(self) ==
::core::mem::discriminant(__other) {
match (self, __other) {
(BoundRegionKind::NamedForPrinting(ref __field_0),
BoundRegionKind::NamedForPrinting(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(BoundRegionKind::Named(ref __field_0),
BoundRegionKind::Named(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => true,
}
} else { false }
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundRegionKind<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<I::Symbol>;
let _: __AssertEq<I::DefId>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundRegionKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundRegionKind<I> where I: Interner
{
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundRegionKind::Anon => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
}
BoundRegionKind::NamedForPrinting(ref __field_0) => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_0, __state);
}
BoundRegionKind::Named(ref __field_0) => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_0, __state);
}
BoundRegionKind::ClosureEnv => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
999#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
BoundRegionKind<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = BoundRegionKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
BoundRegionKind::Anon => { BoundRegionKind::Anon }
BoundRegionKind::NamedForPrinting(__binding_0) => {
BoundRegionKind::NamedForPrinting(__binding_0.lift_to_interner(interner))
}
BoundRegionKind::Named(__binding_0) => {
BoundRegionKind::Named(__binding_0.lift_to_interner(interner))
}
BoundRegionKind::ClosureEnv => {
BoundRegionKind::ClosureEnv
}
}
}
}
};Lift_Generic, const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for BoundRegionKind<I>
where I::Symbol: ::rustc_type_ir::GenericTypeVisitable<__V>,
I::DefId: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundRegionKind::Anon => {}
BoundRegionKind::NamedForPrinting(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
BoundRegionKind::Named(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
BoundRegionKind::ClosureEnv => {}
}
}
}
};GenericTypeVisitable)]
1000#[cfg_attr(
1001 feature = "nightly",
1002 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)
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 == I::Symbol::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::clone::Clone for BoundTyKind<I> where I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundTyKind<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundTyKind<I> where I: Interner
{
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
if ::core::mem::discriminant(self) ==
::core::mem::discriminant(__other) {
match (self, __other) {
(BoundTyKind::Param(ref __field_0),
BoundTyKind::Param(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => true,
}
} else { false }
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundTyKind<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<I::DefId>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundTyKind<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundTyKind<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
BoundTyKind::Anon =>
::core::fmt::Formatter::write_str(__f, "Anon"),
BoundTyKind::Param(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Param");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
}
}
}
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundTyKind<I> where I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundTyKind::Anon => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
}
BoundTyKind::Param(ref __field_0) => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_0, __state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)]
1061#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundTyKind<I>
where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
type Lifted = BoundTyKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
BoundTyKind::Anon => { BoundTyKind::Anon }
BoundTyKind::Param(__binding_0) => {
BoundTyKind::Param(__binding_0.lift_to_interner(interner))
}
}
}
}
};Lift_Generic, const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for BoundTyKind<I>
where I::DefId: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundTyKind::Anon => {}
BoundTyKind::Param(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
}
}
}
};GenericTypeVisitable)]
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> ::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)
1065)]
1066pub enum BoundTyKind<I: Interner> {
1067 Anon,
1068 Param(I::DefId),
1069}
1070
1071#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundVariableKind<I> where
I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundVariableKind<I> where
I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundVariableKind<I> where
I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
if ::core::mem::discriminant(self) ==
::core::mem::discriminant(__other) {
match (self, __other) {
(BoundVariableKind::Ty(ref __field_0),
BoundVariableKind::Ty(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
(BoundVariableKind::Region(ref __field_0),
BoundVariableKind::Region(ref __other_field_0)) =>
true &&
::core::cmp::PartialEq::eq(__field_0, __other_field_0),
_ => true,
}
} else { false }
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundVariableKind<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<BoundTyKind<I>>;
let _: __AssertEq<BoundRegionKind<I>>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundVariableKind<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundVariableKind<I> where
I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
BoundVariableKind::Ty(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Ty");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
BoundVariableKind::Region(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Region");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
BoundVariableKind::Const =>
::core::fmt::Formatter::write_str(__f, "Const"),
}
}
}
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundVariableKind<I> where
I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundVariableKind::Ty(ref __field_0) => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_0, __state);
}
BoundVariableKind::Region(ref __field_0) => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
::core::hash::Hash::hash(__field_0, __state);
}
BoundVariableKind::Const => {
::core::hash::Hash::hash(&::core::mem::discriminant(self),
__state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)]
1072#[derive(const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for
BoundVariableKind<I> where J: Interner,
I: ::rustc_type_ir::LiftInto<J> {
type Lifted = BoundVariableKind<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
BoundVariableKind::Ty(__binding_0) => {
BoundVariableKind::Ty(__binding_0.lift_to_interner(interner))
}
BoundVariableKind::Region(__binding_0) => {
BoundVariableKind::Region(__binding_0.lift_to_interner(interner))
}
BoundVariableKind::Const => { BoundVariableKind::Const }
}
}
}
};Lift_Generic, const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for
BoundVariableKind<I> where
BoundTyKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V>,
BoundRegionKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundVariableKind::Ty(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
BoundVariableKind::Region(ref __binding_0) => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
}
BoundVariableKind::Const => {}
}
}
}
};GenericTypeVisitable)]
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> ::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)
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::clone::Clone for BoundRegion<I> where I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundRegion<I> where I: Interner {
}
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundRegion<I> where I: Interner
{
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(BoundRegion { var: ref __field_var, kind: ref __field_kind },
BoundRegion {
var: ref __other_field_var, kind: ref __other_field_kind }) =>
true &&
::core::cmp::PartialEq::eq(__field_var, __other_field_var)
&&
::core::cmp::PartialEq::eq(__field_kind,
__other_field_kind),
}
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundRegion<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<ty::BoundVar>;
let _: __AssertEq<BoundRegionKind<I>>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundRegion<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundRegion<I> where I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundRegion { var: ref __field_var, kind: ref __field_kind } => {
::core::hash::Hash::hash(__field_var, __state);
::core::hash::Hash::hash(__field_kind, __state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
1107#[derive(const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for BoundRegion<I>
where ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
BoundRegionKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
=> {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
}
}
}
}
};GenericTypeVisitable, const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundRegion<I>
where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
type Lifted = BoundRegion<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
BoundRegion { var: __binding_0, kind: __binding_1 } => {
BoundRegion {
var: __binding_0,
kind: __binding_1.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic)]
1108#[cfg_attr(
1109 feature = "nightly",
1110 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for BoundRegion<I> where
BoundRegionKind<I>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let BoundRegion { var: ref __binding_0, kind: ref __binding_1
} = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
BoundRegion<I> where
BoundRegionKind<I>: ::rustc_data_structures::stable_hash::StableHash
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
BoundRegion { var: ref __binding_0, kind: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext, const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for BoundRegion<I> where
BoundRegionKind<I>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
BoundRegion {
var: ::rustc_serialize::Decodable::decode(__decoder),
kind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext)
1111)]
1112pub struct BoundRegion<I: Interner> {
1113 #[lift(identity)]
1114 pub var: ty::BoundVar,
1115 pub kind: BoundRegionKind<I>,
1116}
1117
1118impl<I: Interner> core::fmt::Debug for BoundRegion<I> {
1119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1120 match self.kind {
1121 BoundRegionKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1122 BoundRegionKind::ClosureEnv => f.write_fmt(format_args!("{0:?}.Env", self.var))write!(f, "{:?}.Env", self.var),
1123 BoundRegionKind::Named(def) => {
1124 f.write_fmt(format_args!("{0:?}.Named({1:?})", self.var, def))write!(f, "{:?}.Named({:?})", self.var, def)
1125 }
1126 BoundRegionKind::NamedForPrinting(symbol) => {
1127 f.write_fmt(format_args!("{0:?}.NamedAnon({1:?})", self.var, symbol))write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
1128 }
1129 }
1130 }
1131}
1132
1133impl<I: Interner> BoundRegion<I> {
1134 pub fn var(self) -> ty::BoundVar {
1135 self.var
1136 }
1137
1138 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1139 {
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())
1140 }
1141}
1142
1143pub type PlaceholderRegion<I> = ty::Placeholder<I, BoundRegion<I>>;
1144
1145impl<I: Interner> PlaceholderRegion<I> {
1146 pub fn universe(self) -> UniverseIndex {
1147 self.universe
1148 }
1149
1150 pub fn var(self) -> ty::BoundVar {
1151 self.bound.var()
1152 }
1153
1154 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1155 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1156 }
1157
1158 pub fn new(ui: UniverseIndex, bound: BoundRegion<I>) -> Self {
1159 Self { universe: ui, bound, _tcx: PhantomData }
1160 }
1161
1162 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1163 let bound = BoundRegion { var, kind: BoundRegionKind::Anon };
1164 Self { universe: ui, bound, _tcx: PhantomData }
1165 }
1166}
1167
1168#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundTy<I> where I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundTy<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundTy<I> where I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(BoundTy { var: ref __field_var, kind: ref __field_kind },
BoundTy {
var: ref __other_field_var, kind: ref __other_field_kind }) =>
true &&
::core::cmp::PartialEq::eq(__field_var, __other_field_var)
&&
::core::cmp::PartialEq::eq(__field_kind,
__other_field_kind),
}
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundTy<I> where I: Interner
{
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<ty::BoundVar>;
let _: __AssertEq<BoundTyKind<I>>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundTy<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundTy<I> where I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundTy { var: ref __field_var, kind: ref __field_kind } => {
::core::hash::Hash::hash(__field_var, __state);
::core::hash::Hash::hash(__field_kind, __state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
1169#[derive(const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for BoundTy<I> where
ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
BoundTyKind<I>: ::rustc_type_ir::GenericTypeVisitable<__V> {
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
}
}
}
}
};GenericTypeVisitable, const _: () =
{
impl<I: Interner, J> ::rustc_type_ir::lift::Lift<J> for BoundTy<I>
where J: Interner, I: ::rustc_type_ir::LiftInto<J> {
type Lifted = BoundTy<J>;
fn lift_to_interner(self, interner: J) -> Self::Lifted {
match self {
BoundTy { var: __binding_0, kind: __binding_1 } => {
BoundTy {
var: __binding_0,
kind: __binding_1.lift_to_interner(interner),
}
}
}
}
}
};Lift_Generic)]
1170#[cfg_attr(
1171 feature = "nightly",
1172 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for BoundTy<I> where
BoundTyKind<I>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let BoundTy { var: ref __binding_0, kind: ref __binding_1 } =
*self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for BoundTy<I> where
BoundTyKind<I>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
BoundTy {
var: ::rustc_serialize::Decodable::decode(__decoder),
kind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
BoundTy<I> where
BoundTyKind<I>: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
BoundTy { var: ref __binding_0, kind: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
1173)]
1174pub struct BoundTy<I: Interner> {
1175 #[lift(identity)]
1176 pub var: ty::BoundVar,
1177 pub kind: BoundTyKind<I>,
1178}
1179
1180impl<I: Interner> fmt::Debug for ty::BoundTy<I> {
1181 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1182 match self.kind {
1183 ty::BoundTyKind::Anon => f.write_fmt(format_args!("{0:?}", self.var))write!(f, "{:?}", self.var),
1184 ty::BoundTyKind::Param(def_id) => f.write_fmt(format_args!("{0:?}", def_id))write!(f, "{def_id:?}"),
1185 }
1186 }
1187}
1188
1189impl<I: Interner> BoundTy<I> {
1190 pub fn var(self) -> ty::BoundVar {
1191 self.var
1192 }
1193
1194 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1195 {
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())
1196 }
1197}
1198
1199pub type PlaceholderType<I> = ty::Placeholder<I, BoundTy<I>>;
1200
1201impl<I: Interner> PlaceholderType<I> {
1202 pub fn universe(self) -> UniverseIndex {
1203 self.universe
1204 }
1205
1206 pub fn var(self) -> ty::BoundVar {
1207 self.bound.var
1208 }
1209
1210 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1211 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1212 }
1213
1214 pub fn new(ui: UniverseIndex, bound: BoundTy<I>) -> Self {
1215 Self { universe: ui, bound, _tcx: PhantomData }
1216 }
1217
1218 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1219 let bound = BoundTy { var, kind: BoundTyKind::Anon };
1220 Self { universe: ui, bound, _tcx: PhantomData }
1221 }
1222}
1223
1224#[automatically_derived]
impl<I: Interner> ::core::clone::Clone for BoundConst<I> where I: Interner {
#[inline]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]
impl<I: Interner> ::core::marker::Copy for BoundConst<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::cmp::PartialEq for BoundConst<I> where I: Interner {
#[inline]
fn eq(&self, __other: &Self) -> ::core::primitive::bool {
match (self, __other) {
(BoundConst { var: ref __field_var, _tcx: ref __field__tcx },
BoundConst {
var: ref __other_field_var, _tcx: ref __other_field__tcx }) =>
true &&
::core::cmp::PartialEq::eq(__field_var, __other_field_var)
&&
::core::cmp::PartialEq::eq(__field__tcx,
__other_field__tcx),
}
}
}
#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for BoundConst<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
BoundConst { var: ref __field_var, _tcx: ref __field__tcx } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "BoundConst");
::core::fmt::DebugStruct::field(&mut __builder, "var",
__field_var);
::core::fmt::DebugStruct::finish_non_exhaustive(&mut __builder)
}
}
}
}
const _: () =
{
trait DeriveWhereAssertEq {
fn assert(&self);
}
impl<I: Interner> DeriveWhereAssertEq for BoundConst<I> where
I: Interner {
fn assert(&self) {
struct __AssertEq<__T: ::core::cmp::Eq +
?::core::marker::Sized>(::core::marker::PhantomData<__T>);
let _: __AssertEq<ty::BoundVar>;
let _: __AssertEq<PhantomData<fn() -> I>>;
}
}
};
#[automatically_derived]
impl<I: Interner> ::core::cmp::Eq for BoundConst<I> where I: Interner { }
#[automatically_derived]
impl<I: Interner> ::core::hash::Hash for BoundConst<I> where I: Interner {
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
match self {
BoundConst { var: ref __field_var, _tcx: ref __field__tcx } => {
::core::hash::Hash::hash(__field_var, __state);
::core::hash::Hash::hash(__field__tcx, __state);
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Debug, Eq, Hash; I: Interner)]
1225#[derive(const _: () =
{
unsafe impl<I: Interner, __V>
::rustc_type_ir::GenericTypeVisitable<__V> for BoundConst<I> where
ty::BoundVar: ::rustc_type_ir::GenericTypeVisitable<__V>,
PhantomData<fn() -> I>: ::rustc_type_ir::GenericTypeVisitable<__V>
{
fn generic_visit_with(&self, __visitor: &mut __V) {
match *self {
BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
=> {
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_0,
__visitor);
}
{
::rustc_type_ir::GenericTypeVisitable::<__V>::generic_visit_with(__binding_1,
__visitor);
}
}
}
}
}
};GenericTypeVisitable)]
1226#[cfg_attr(
1227 feature = "nightly",
1228 derive(const _: () =
{
impl<I: Interner, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for BoundConst<I> where
PhantomData<fn() -> I>: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let BoundConst { var: ref __binding_0, _tcx: ref __binding_1
} = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<I: Interner, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for BoundConst<I> where
PhantomData<fn() -> I>: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
BoundConst {
var: ::rustc_serialize::Decodable::decode(__decoder),
_tcx: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl<I: Interner> ::rustc_data_structures::stable_hash::StableHash for
BoundConst<I> where
PhantomData<fn()
-> I>: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
BoundConst { var: ref __binding_0, _tcx: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash_NoContext)
1229)]
1230pub struct BoundConst<I: Interner> {
1231 pub var: ty::BoundVar,
1232 #[derive_where(skip(Debug))]
1233 pub _tcx: PhantomData<fn() -> I>,
1234}
1235
1236impl<I: Interner> BoundConst<I> {
1237 pub fn var(self) -> ty::BoundVar {
1238 self.var
1239 }
1240
1241 pub fn assert_eq(self, var: BoundVariableKind<I>) {
1242 var.expect_const()
1243 }
1244
1245 pub fn new(var: ty::BoundVar) -> Self {
1246 Self { var, _tcx: PhantomData }
1247 }
1248}
1249
1250pub type PlaceholderConst<I> = ty::Placeholder<I, BoundConst<I>>;
1251
1252impl<I: Interner> PlaceholderConst<I> {
1253 pub fn universe(self) -> UniverseIndex {
1254 self.universe
1255 }
1256
1257 pub fn var(self) -> ty::BoundVar {
1258 self.bound.var
1259 }
1260
1261 pub fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1262 Self { universe: ui, bound: self.bound, _tcx: PhantomData }
1263 }
1264
1265 pub fn new(ui: UniverseIndex, bound: BoundConst<I>) -> Self {
1266 Self { universe: ui, bound, _tcx: PhantomData }
1267 }
1268
1269 pub fn new_anon(ui: UniverseIndex, var: ty::BoundVar) -> Self {
1270 let bound = BoundConst::new(var);
1271 Self { universe: ui, bound, _tcx: PhantomData }
1272 }
1273
1274 pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty {
1275 let mut candidates = env.caller_bounds().filter_map(|clause| {
1276 match clause.kind().skip_binder() {
1278 ty::ClauseKind::ConstArgHasType(placeholder_ct, ty) => {
1279 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());
1280
1281 match placeholder_ct.kind() {
1282 ty::ConstKind::Placeholder(placeholder_ct) if placeholder_ct == self => {
1283 Some(ty)
1284 }
1285 _ => None,
1286 }
1287 }
1288 _ => None,
1289 }
1290 });
1291
1292 let ty = candidates.next().unwrap_or_else(|| {
1299 {
::core::panicking::panic_fmt(format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env));
};panic!("cannot find `{self:?}` in param-env: {env:#?}");
1300 });
1301 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!(
1302 candidates.next().is_none(),
1303 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
1304 );
1305 ty
1306 }
1307}