1 #![allow(rustc::usage_of_ty_tykind)]
3 use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
6 use crate::DebruijnIndex;
13 use crate::UniverseIndex;
15 use self::RegionKind::*;
18 use rustc_data_structures::stable_hasher::HashStable;
19 use rustc_serialize::{Decodable, Decoder, Encodable};
21 /// Defines the kinds of types used by the type system.
23 /// Types written by the user start out as `hir::TyKind` and get
24 /// converted to this representation using `AstConv::ast_ty_to_ty`.
25 #[rustc_diagnostic_item = "IrTyKind"]
26 pub enum TyKind<I: Interner> {
27 /// The primitive boolean type. Written as `bool`.
30 /// The primitive character type; holds a Unicode scalar value
31 /// (a non-surrogate code point). Written as `char`.
34 /// A primitive signed integer type. For example, `i32`.
37 /// A primitive unsigned integer type. For example, `u32`.
40 /// A primitive floating-point type. For example, `f64`.
43 /// Algebraic data types (ADT). For example: structures, enumerations and unions.
45 /// For example, the type `List<i32>` would be represented using the `AdtDef`
46 /// for `struct List<T>` and the substs `[i32]`.
48 /// Note that generic parameters in fields only get lazily substituted
49 /// by using something like `adt_def.all_fields().map(|field| field.ty(tcx, substs))`.
50 Adt(I::AdtDef, I::SubstsRef),
52 /// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
55 /// The pointee of a string slice. Written as `str`.
58 /// An array with the given length. Written as `[T; N]`.
59 Array(I::Ty, I::Const),
61 /// The pointee of an array slice. Written as `[T]`.
64 /// A raw pointer. Written as `*mut T` or `*const T`
65 RawPtr(I::TypeAndMut),
67 /// A reference; a pointer with an associated lifetime. Written as
68 /// `&'a mut T` or `&'a T`.
69 Ref(I::Region, I::Ty, I::Mutability),
71 /// The anonymous type of a function declaration/definition. Each
72 /// function has a unique type.
74 /// For the function `fn foo() -> i32 { 3 }` this type would be
75 /// shown to the user as `fn() -> i32 {foo}`.
77 /// For example the type of `bar` here:
79 /// fn foo() -> i32 { 1 }
80 /// let bar = foo; // bar: fn() -> i32 {foo}
82 FnDef(I::DefId, I::SubstsRef),
84 /// A pointer to a function. Written as `fn() -> i32`.
86 /// Note that both functions and closures start out as either
87 /// [FnDef] or [Closure] which can be then be coerced to this variant.
89 /// For example the type of `bar` here:
92 /// fn foo() -> i32 { 1 }
93 /// let bar: fn() -> i32 = foo;
97 /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
98 Dynamic(I::ListBinderExistentialPredicate, I::Region),
100 /// The anonymous type of a closure. Used to represent the type of `|a| a`.
102 /// Closure substs contain both the - potentially substituted - generic parameters
103 /// of its parent and some synthetic parameters. See the documentation for
104 /// `ClosureSubsts` for more details.
105 Closure(I::DefId, I::SubstsRef),
107 /// The anonymous type of a generator. Used to represent the type of
110 /// For more info about generator substs, visit the documentation for
111 /// `GeneratorSubsts`.
112 Generator(I::DefId, I::SubstsRef, I::Movability),
114 /// A type representing the types stored inside a generator.
115 /// This should only appear as part of the `GeneratorSubsts`.
117 /// Note that the captured variables for generators are stored separately
118 /// using a tuple in the same way as for closures.
120 /// Unlike upvars, the witness can reference lifetimes from
121 /// inside of the generator itself. To deal with them in
122 /// the type of the generator, we convert them to higher ranked
123 /// lifetimes bound by the witness itself.
125 /// Looking at the following example, the witness for this generator
126 /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
128 /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?)
129 /// #![feature(generators)]
131 /// let x = &vec![3];
137 GeneratorWitness(I::BinderListTy),
139 /// The never type `!`.
142 /// A tuple type. For example, `(i32, bool)`.
145 /// The projection of an associated type. For example,
146 /// `<T as Trait<..>>::N`.
147 Projection(I::ProjectionTy),
149 /// Opaque (`impl Trait`) type found in a return type.
151 /// The `DefId` comes either from
152 /// * the `impl Trait` ast::Ty node,
153 /// * or the `type Foo = impl Trait` declaration
155 /// For RPIT the substitutions are for the generics of the function,
156 /// while for TAIT it is used for the generic parameters of the alias.
158 /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type.
159 Opaque(I::DefId, I::SubstsRef),
161 /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
164 /// Bound type variable, used to represent the `'a` in `for<'a> fn(&'a ())`.
166 /// For canonical queries, we replace inference variables with bound variables,
167 /// so e.g. when checking whether `&'_ (): Trait<_>` holds, we canonicalize that to
168 /// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
169 /// back to inference variables in a new inference context when inside of the query.
171 /// See the `rustc-dev-guide` for more details about
172 /// [higher-ranked trait bounds][1] and [canonical queries][2].
174 /// [1]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
175 /// [2]: https://rustc-dev-guide.rust-lang.org/traits/canonical-queries.html
176 Bound(DebruijnIndex, I::BoundTy),
178 /// A placeholder type, used during higher ranked subtyping to instantiate
180 Placeholder(I::PlaceholderType),
182 /// A type variable used during type checking.
184 /// Similar to placeholders, inference variables also live in a universe to
185 /// correctly deal with higher ranked types. Though unlike placeholders,
186 /// that universe is stored in the `InferCtxt` instead of directly
187 /// inside of the type.
190 /// A placeholder for a type which could not be computed; this is
191 /// propagated to avoid useless error messages.
192 Error(I::DelaySpanBugEmitted),
195 impl<I: Interner> TyKind<I> {
197 pub fn is_primitive(&self) -> bool {
198 matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
202 // This is manually implemented for `TyKind` because `std::mem::discriminant`
203 // returns an opaque value that is `PartialEq` but not `PartialOrd`
205 const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
223 Generator(_, _, _) => 16,
224 GeneratorWitness(_) => 17,
231 Placeholder(_) => 24,
237 // This is manually implemented because a derive would require `I: Clone`
238 impl<I: Interner> Clone for TyKind<I> {
239 fn clone(&self) -> Self {
243 Int(i) => Int(i.clone()),
244 Uint(u) => Uint(u.clone()),
245 Float(f) => Float(f.clone()),
246 Adt(d, s) => Adt(d.clone(), s.clone()),
247 Foreign(d) => Foreign(d.clone()),
249 Array(t, c) => Array(t.clone(), c.clone()),
250 Slice(t) => Slice(t.clone()),
251 RawPtr(t) => RawPtr(t.clone()),
252 Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()),
253 FnDef(d, s) => FnDef(d.clone(), s.clone()),
254 FnPtr(s) => FnPtr(s.clone()),
255 Dynamic(p, r) => Dynamic(p.clone(), r.clone()),
256 Closure(d, s) => Closure(d.clone(), s.clone()),
257 Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()),
258 GeneratorWitness(g) => GeneratorWitness(g.clone()),
260 Tuple(t) => Tuple(t.clone()),
261 Projection(p) => Projection(p.clone()),
262 Opaque(d, s) => Opaque(d.clone(), s.clone()),
263 Param(p) => Param(p.clone()),
264 Bound(d, b) => Bound(d.clone(), b.clone()),
265 Placeholder(p) => Placeholder(p.clone()),
266 Infer(t) => Infer(t.clone()),
267 Error(e) => Error(e.clone()),
272 // This is manually implemented because a derive would require `I: PartialEq`
273 impl<I: Interner> PartialEq for TyKind<I> {
275 fn eq(&self, other: &TyKind<I>) -> bool {
276 let __self_vi = tykind_discriminant(self);
277 let __arg_1_vi = tykind_discriminant(other);
278 if __self_vi == __arg_1_vi {
279 match (&*self, &*other) {
280 (&Int(ref __self_0), &Int(ref __arg_1_0)) => __self_0 == __arg_1_0,
281 (&Uint(ref __self_0), &Uint(ref __arg_1_0)) => __self_0 == __arg_1_0,
282 (&Float(ref __self_0), &Float(ref __arg_1_0)) => __self_0 == __arg_1_0,
283 (&Adt(ref __self_0, ref __self_1), &Adt(ref __arg_1_0, ref __arg_1_1)) => {
284 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
286 (&Foreign(ref __self_0), &Foreign(ref __arg_1_0)) => __self_0 == __arg_1_0,
287 (&Array(ref __self_0, ref __self_1), &Array(ref __arg_1_0, ref __arg_1_1)) => {
288 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
290 (&Slice(ref __self_0), &Slice(ref __arg_1_0)) => __self_0 == __arg_1_0,
291 (&RawPtr(ref __self_0), &RawPtr(ref __arg_1_0)) => __self_0 == __arg_1_0,
293 &Ref(ref __self_0, ref __self_1, ref __self_2),
294 &Ref(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
295 ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1 && __self_2 == __arg_1_2,
296 (&FnDef(ref __self_0, ref __self_1), &FnDef(ref __arg_1_0, ref __arg_1_1)) => {
297 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
299 (&FnPtr(ref __self_0), &FnPtr(ref __arg_1_0)) => __self_0 == __arg_1_0,
300 (&Dynamic(ref __self_0, ref __self_1), &Dynamic(ref __arg_1_0, ref __arg_1_1)) => {
301 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
303 (&Closure(ref __self_0, ref __self_1), &Closure(ref __arg_1_0, ref __arg_1_1)) => {
304 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
307 &Generator(ref __self_0, ref __self_1, ref __self_2),
308 &Generator(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
309 ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1 && __self_2 == __arg_1_2,
310 (&GeneratorWitness(ref __self_0), &GeneratorWitness(ref __arg_1_0)) => {
311 __self_0 == __arg_1_0
313 (&Tuple(ref __self_0), &Tuple(ref __arg_1_0)) => __self_0 == __arg_1_0,
314 (&Projection(ref __self_0), &Projection(ref __arg_1_0)) => __self_0 == __arg_1_0,
315 (&Opaque(ref __self_0, ref __self_1), &Opaque(ref __arg_1_0, ref __arg_1_1)) => {
316 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
318 (&Param(ref __self_0), &Param(ref __arg_1_0)) => __self_0 == __arg_1_0,
319 (&Bound(ref __self_0, ref __self_1), &Bound(ref __arg_1_0, ref __arg_1_1)) => {
320 __self_0 == __arg_1_0 && __self_1 == __arg_1_1
322 (&Placeholder(ref __self_0), &Placeholder(ref __arg_1_0)) => __self_0 == __arg_1_0,
323 (&Infer(ref __self_0), &Infer(ref __arg_1_0)) => __self_0 == __arg_1_0,
324 (&Error(ref __self_0), &Error(ref __arg_1_0)) => __self_0 == __arg_1_0,
333 // This is manually implemented because a derive would require `I: Eq`
334 impl<I: Interner> Eq for TyKind<I> {}
336 // This is manually implemented because a derive would require `I: PartialOrd`
337 impl<I: Interner> PartialOrd for TyKind<I> {
339 fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> {
340 Some(Ord::cmp(self, other))
344 // This is manually implemented because a derive would require `I: Ord`
345 impl<I: Interner> Ord for TyKind<I> {
347 fn cmp(&self, other: &TyKind<I>) -> Ordering {
348 let __self_vi = tykind_discriminant(self);
349 let __arg_1_vi = tykind_discriminant(other);
350 if __self_vi == __arg_1_vi {
351 match (&*self, &*other) {
352 (&Int(ref __self_0), &Int(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
353 (&Uint(ref __self_0), &Uint(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
354 (&Float(ref __self_0), &Float(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
355 (&Adt(ref __self_0, ref __self_1), &Adt(ref __arg_1_0, ref __arg_1_1)) => {
356 match Ord::cmp(__self_0, __arg_1_0) {
357 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
361 (&Foreign(ref __self_0), &Foreign(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
362 (&Array(ref __self_0, ref __self_1), &Array(ref __arg_1_0, ref __arg_1_1)) => {
363 match Ord::cmp(__self_0, __arg_1_0) {
364 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
368 (&Slice(ref __self_0), &Slice(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
369 (&RawPtr(ref __self_0), &RawPtr(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
371 &Ref(ref __self_0, ref __self_1, ref __self_2),
372 &Ref(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
373 ) => match Ord::cmp(__self_0, __arg_1_0) {
374 Ordering::Equal => match Ord::cmp(__self_1, __arg_1_1) {
375 Ordering::Equal => Ord::cmp(__self_2, __arg_1_2),
380 (&FnDef(ref __self_0, ref __self_1), &FnDef(ref __arg_1_0, ref __arg_1_1)) => {
381 match Ord::cmp(__self_0, __arg_1_0) {
382 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
386 (&FnPtr(ref __self_0), &FnPtr(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
387 (&Dynamic(ref __self_0, ref __self_1), &Dynamic(ref __arg_1_0, ref __arg_1_1)) => {
388 match Ord::cmp(__self_0, __arg_1_0) {
389 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
393 (&Closure(ref __self_0, ref __self_1), &Closure(ref __arg_1_0, ref __arg_1_1)) => {
394 match Ord::cmp(__self_0, __arg_1_0) {
395 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
400 &Generator(ref __self_0, ref __self_1, ref __self_2),
401 &Generator(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
402 ) => match Ord::cmp(__self_0, __arg_1_0) {
403 Ordering::Equal => match Ord::cmp(__self_1, __arg_1_1) {
404 Ordering::Equal => Ord::cmp(__self_2, __arg_1_2),
409 (&GeneratorWitness(ref __self_0), &GeneratorWitness(ref __arg_1_0)) => {
410 Ord::cmp(__self_0, __arg_1_0)
412 (&Tuple(ref __self_0), &Tuple(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
413 (&Projection(ref __self_0), &Projection(ref __arg_1_0)) => {
414 Ord::cmp(__self_0, __arg_1_0)
416 (&Opaque(ref __self_0, ref __self_1), &Opaque(ref __arg_1_0, ref __arg_1_1)) => {
417 match Ord::cmp(__self_0, __arg_1_0) {
418 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
422 (&Param(ref __self_0), &Param(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
423 (&Bound(ref __self_0, ref __self_1), &Bound(ref __arg_1_0, ref __arg_1_1)) => {
424 match Ord::cmp(__self_0, __arg_1_0) {
425 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
429 (&Placeholder(ref __self_0), &Placeholder(ref __arg_1_0)) => {
430 Ord::cmp(__self_0, __arg_1_0)
432 (&Infer(ref __self_0), &Infer(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
433 (&Error(ref __self_0), &Error(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
434 _ => Ordering::Equal,
437 Ord::cmp(&__self_vi, &__arg_1_vi)
442 // This is manually implemented because a derive would require `I: Hash`
443 impl<I: Interner> hash::Hash for TyKind<I> {
444 fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
446 (&Int(ref __self_0),) => {
447 hash::Hash::hash(&tykind_discriminant(self), state);
448 hash::Hash::hash(__self_0, state)
450 (&Uint(ref __self_0),) => {
451 hash::Hash::hash(&tykind_discriminant(self), state);
452 hash::Hash::hash(__self_0, state)
454 (&Float(ref __self_0),) => {
455 hash::Hash::hash(&tykind_discriminant(self), state);
456 hash::Hash::hash(__self_0, state)
458 (&Adt(ref __self_0, ref __self_1),) => {
459 hash::Hash::hash(&tykind_discriminant(self), state);
460 hash::Hash::hash(__self_0, state);
461 hash::Hash::hash(__self_1, state)
463 (&Foreign(ref __self_0),) => {
464 hash::Hash::hash(&tykind_discriminant(self), state);
465 hash::Hash::hash(__self_0, state)
467 (&Array(ref __self_0, ref __self_1),) => {
468 hash::Hash::hash(&tykind_discriminant(self), state);
469 hash::Hash::hash(__self_0, state);
470 hash::Hash::hash(__self_1, state)
472 (&Slice(ref __self_0),) => {
473 hash::Hash::hash(&tykind_discriminant(self), state);
474 hash::Hash::hash(__self_0, state)
476 (&RawPtr(ref __self_0),) => {
477 hash::Hash::hash(&tykind_discriminant(self), state);
478 hash::Hash::hash(__self_0, state)
480 (&Ref(ref __self_0, ref __self_1, ref __self_2),) => {
481 hash::Hash::hash(&tykind_discriminant(self), state);
482 hash::Hash::hash(__self_0, state);
483 hash::Hash::hash(__self_1, state);
484 hash::Hash::hash(__self_2, state)
486 (&FnDef(ref __self_0, ref __self_1),) => {
487 hash::Hash::hash(&tykind_discriminant(self), state);
488 hash::Hash::hash(__self_0, state);
489 hash::Hash::hash(__self_1, state)
491 (&FnPtr(ref __self_0),) => {
492 hash::Hash::hash(&tykind_discriminant(self), state);
493 hash::Hash::hash(__self_0, state)
495 (&Dynamic(ref __self_0, ref __self_1),) => {
496 hash::Hash::hash(&tykind_discriminant(self), state);
497 hash::Hash::hash(__self_0, state);
498 hash::Hash::hash(__self_1, state)
500 (&Closure(ref __self_0, ref __self_1),) => {
501 hash::Hash::hash(&tykind_discriminant(self), state);
502 hash::Hash::hash(__self_0, state);
503 hash::Hash::hash(__self_1, state)
505 (&Generator(ref __self_0, ref __self_1, ref __self_2),) => {
506 hash::Hash::hash(&tykind_discriminant(self), state);
507 hash::Hash::hash(__self_0, state);
508 hash::Hash::hash(__self_1, state);
509 hash::Hash::hash(__self_2, state)
511 (&GeneratorWitness(ref __self_0),) => {
512 hash::Hash::hash(&tykind_discriminant(self), state);
513 hash::Hash::hash(__self_0, state)
515 (&Tuple(ref __self_0),) => {
516 hash::Hash::hash(&tykind_discriminant(self), state);
517 hash::Hash::hash(__self_0, state)
519 (&Projection(ref __self_0),) => {
520 hash::Hash::hash(&tykind_discriminant(self), state);
521 hash::Hash::hash(__self_0, state)
523 (&Opaque(ref __self_0, ref __self_1),) => {
524 hash::Hash::hash(&tykind_discriminant(self), state);
525 hash::Hash::hash(__self_0, state);
526 hash::Hash::hash(__self_1, state)
528 (&Param(ref __self_0),) => {
529 hash::Hash::hash(&tykind_discriminant(self), state);
530 hash::Hash::hash(__self_0, state)
532 (&Bound(ref __self_0, ref __self_1),) => {
533 hash::Hash::hash(&tykind_discriminant(self), state);
534 hash::Hash::hash(__self_0, state);
535 hash::Hash::hash(__self_1, state)
537 (&Placeholder(ref __self_0),) => {
538 hash::Hash::hash(&tykind_discriminant(self), state);
539 hash::Hash::hash(__self_0, state)
541 (&Infer(ref __self_0),) => {
542 hash::Hash::hash(&tykind_discriminant(self), state);
543 hash::Hash::hash(__self_0, state)
545 (&Error(ref __self_0),) => {
546 hash::Hash::hash(&tykind_discriminant(self), state);
547 hash::Hash::hash(__self_0, state)
549 _ => hash::Hash::hash(&tykind_discriminant(self), state),
554 // This is manually implemented because a derive would require `I: Debug`
555 impl<I: Interner> fmt::Debug for TyKind<I> {
556 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
558 (&Bool,) => fmt::Formatter::write_str(f, "Bool"),
559 (&Char,) => fmt::Formatter::write_str(f, "Char"),
560 (&Int(ref __self_0),) => {
561 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Int");
562 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
563 fmt::DebugTuple::finish(debug_trait_builder)
565 (&Uint(ref __self_0),) => {
566 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Uint");
567 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
568 fmt::DebugTuple::finish(debug_trait_builder)
570 (&Float(ref __self_0),) => {
571 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Float");
572 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
573 fmt::DebugTuple::finish(debug_trait_builder)
575 (&Adt(ref __self_0, ref __self_1),) => {
576 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Adt");
577 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
578 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
579 fmt::DebugTuple::finish(debug_trait_builder)
581 (&Foreign(ref __self_0),) => {
582 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Foreign");
583 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
584 fmt::DebugTuple::finish(debug_trait_builder)
586 (&Str,) => fmt::Formatter::write_str(f, "Str"),
587 (&Array(ref __self_0, ref __self_1),) => {
588 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Array");
589 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
590 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
591 fmt::DebugTuple::finish(debug_trait_builder)
593 (&Slice(ref __self_0),) => {
594 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Slice");
595 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
596 fmt::DebugTuple::finish(debug_trait_builder)
598 (&RawPtr(ref __self_0),) => {
599 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "RawPtr");
600 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
601 fmt::DebugTuple::finish(debug_trait_builder)
603 (&Ref(ref __self_0, ref __self_1, ref __self_2),) => {
604 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Ref");
605 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
606 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
607 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_2);
608 fmt::DebugTuple::finish(debug_trait_builder)
610 (&FnDef(ref __self_0, ref __self_1),) => {
611 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "FnDef");
612 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
613 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
614 fmt::DebugTuple::finish(debug_trait_builder)
616 (&FnPtr(ref __self_0),) => {
617 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "FnPtr");
618 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
619 fmt::DebugTuple::finish(debug_trait_builder)
621 (&Dynamic(ref __self_0, ref __self_1),) => {
622 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Dynamic");
623 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
624 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
625 fmt::DebugTuple::finish(debug_trait_builder)
627 (&Closure(ref __self_0, ref __self_1),) => {
628 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Closure");
629 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
630 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
631 fmt::DebugTuple::finish(debug_trait_builder)
633 (&Generator(ref __self_0, ref __self_1, ref __self_2),) => {
634 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Generator");
635 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
636 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
637 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_2);
638 fmt::DebugTuple::finish(debug_trait_builder)
640 (&GeneratorWitness(ref __self_0),) => {
641 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "GeneratorWitness");
642 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
643 fmt::DebugTuple::finish(debug_trait_builder)
645 (&Never,) => fmt::Formatter::write_str(f, "Never"),
646 (&Tuple(ref __self_0),) => {
647 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Tuple");
648 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
649 fmt::DebugTuple::finish(debug_trait_builder)
651 (&Projection(ref __self_0),) => {
652 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Projection");
653 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
654 fmt::DebugTuple::finish(debug_trait_builder)
656 (&Opaque(ref __self_0, ref __self_1),) => {
657 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Opaque");
658 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
659 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
660 fmt::DebugTuple::finish(debug_trait_builder)
662 (&Param(ref __self_0),) => {
663 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Param");
664 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
665 fmt::DebugTuple::finish(debug_trait_builder)
667 (&Bound(ref __self_0, ref __self_1),) => {
668 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Bound");
669 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
670 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
671 fmt::DebugTuple::finish(debug_trait_builder)
673 (&Placeholder(ref __self_0),) => {
674 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Placeholder");
675 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
676 fmt::DebugTuple::finish(debug_trait_builder)
678 (&Infer(ref __self_0),) => {
679 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Infer");
680 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
681 fmt::DebugTuple::finish(debug_trait_builder)
683 (&Error(ref __self_0),) => {
684 let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Error");
685 let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
686 fmt::DebugTuple::finish(debug_trait_builder)
692 // This is manually implemented because a derive would require `I: Encodable`
693 impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I>
695 I::DelaySpanBugEmitted: Encodable<E>,
696 I::AdtDef: Encodable<E>,
697 I::SubstsRef: Encodable<E>,
698 I::DefId: Encodable<E>,
700 I::Const: Encodable<E>,
701 I::Region: Encodable<E>,
702 I::TypeAndMut: Encodable<E>,
703 I::Mutability: Encodable<E>,
704 I::Movability: Encodable<E>,
705 I::PolyFnSig: Encodable<E>,
706 I::ListBinderExistentialPredicate: Encodable<E>,
707 I::BinderListTy: Encodable<E>,
708 I::ListTy: Encodable<E>,
709 I::ProjectionTy: Encodable<E>,
710 I::ParamTy: Encodable<E>,
711 I::BoundTy: Encodable<E>,
712 I::PlaceholderType: Encodable<E>,
713 I::InferTy: Encodable<E>,
714 I::DelaySpanBugEmitted: Encodable<E>,
715 I::PredicateKind: Encodable<E>,
716 I::AllocId: Encodable<E>,
718 fn encode(&self, e: &mut E) {
719 let disc = tykind_discriminant(self);
721 Bool => e.emit_enum_variant(disc, |_| {}),
722 Char => e.emit_enum_variant(disc, |_| {}),
723 Int(i) => e.emit_enum_variant(disc, |e| {
726 Uint(u) => e.emit_enum_variant(disc, |e| {
729 Float(f) => e.emit_enum_variant(disc, |e| {
732 Adt(adt, substs) => e.emit_enum_variant(disc, |e| {
736 Foreign(def_id) => e.emit_enum_variant(disc, |e| {
739 Str => e.emit_enum_variant(disc, |_| {}),
740 Array(t, c) => e.emit_enum_variant(disc, |e| {
744 Slice(t) => e.emit_enum_variant(disc, |e| {
747 RawPtr(tam) => e.emit_enum_variant(disc, |e| {
750 Ref(r, t, m) => e.emit_enum_variant(disc, |e| {
755 FnDef(def_id, substs) => e.emit_enum_variant(disc, |e| {
759 FnPtr(polyfnsig) => e.emit_enum_variant(disc, |e| {
762 Dynamic(l, r) => e.emit_enum_variant(disc, |e| {
766 Closure(def_id, substs) => e.emit_enum_variant(disc, |e| {
770 Generator(def_id, substs, m) => e.emit_enum_variant(disc, |e| {
775 GeneratorWitness(b) => e.emit_enum_variant(disc, |e| {
778 Never => e.emit_enum_variant(disc, |_| {}),
779 Tuple(substs) => e.emit_enum_variant(disc, |e| {
782 Projection(p) => e.emit_enum_variant(disc, |e| {
785 Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| {
789 Param(p) => e.emit_enum_variant(disc, |e| {
792 Bound(d, b) => e.emit_enum_variant(disc, |e| {
796 Placeholder(p) => e.emit_enum_variant(disc, |e| {
799 Infer(i) => e.emit_enum_variant(disc, |e| {
802 Error(d) => e.emit_enum_variant(disc, |e| {
809 // This is manually implemented because a derive would require `I: Decodable`
810 impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I>
812 I::DelaySpanBugEmitted: Decodable<D>,
813 I::AdtDef: Decodable<D>,
814 I::SubstsRef: Decodable<D>,
815 I::DefId: Decodable<D>,
817 I::Const: Decodable<D>,
818 I::Region: Decodable<D>,
819 I::TypeAndMut: Decodable<D>,
820 I::Mutability: Decodable<D>,
821 I::Movability: Decodable<D>,
822 I::PolyFnSig: Decodable<D>,
823 I::ListBinderExistentialPredicate: Decodable<D>,
824 I::BinderListTy: Decodable<D>,
825 I::ListTy: Decodable<D>,
826 I::ProjectionTy: Decodable<D>,
827 I::ParamTy: Decodable<D>,
828 I::BoundTy: Decodable<D>,
829 I::PlaceholderType: Decodable<D>,
830 I::InferTy: Decodable<D>,
831 I::DelaySpanBugEmitted: Decodable<D>,
832 I::PredicateKind: Decodable<D>,
833 I::AllocId: Decodable<D>,
835 fn decode(d: &mut D) -> Self {
836 match Decoder::read_usize(d) {
839 2 => Int(Decodable::decode(d)),
840 3 => Uint(Decodable::decode(d)),
841 4 => Float(Decodable::decode(d)),
842 5 => Adt(Decodable::decode(d), Decodable::decode(d)),
843 6 => Foreign(Decodable::decode(d)),
845 8 => Array(Decodable::decode(d), Decodable::decode(d)),
846 9 => Slice(Decodable::decode(d)),
847 10 => RawPtr(Decodable::decode(d)),
848 11 => Ref(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
849 12 => FnDef(Decodable::decode(d), Decodable::decode(d)),
850 13 => FnPtr(Decodable::decode(d)),
851 14 => Dynamic(Decodable::decode(d), Decodable::decode(d)),
852 15 => Closure(Decodable::decode(d), Decodable::decode(d)),
853 16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
854 17 => GeneratorWitness(Decodable::decode(d)),
856 19 => Tuple(Decodable::decode(d)),
857 20 => Projection(Decodable::decode(d)),
858 21 => Opaque(Decodable::decode(d), Decodable::decode(d)),
859 22 => Param(Decodable::decode(d)),
860 23 => Bound(Decodable::decode(d), Decodable::decode(d)),
861 24 => Placeholder(Decodable::decode(d)),
862 25 => Infer(Decodable::decode(d)),
863 26 => Error(Decodable::decode(d)),
867 "invalid enum variant tag while decoding `{}`, expected 0..{}",
875 // This is not a derived impl because a derive would require `I: HashStable`
876 #[allow(rustc::usage_of_ty_tykind)]
877 impl<CTX, I: Interner> HashStable<CTX> for TyKind<I>
879 I::AdtDef: HashStable<CTX>,
880 I::DefId: HashStable<CTX>,
881 I::SubstsRef: HashStable<CTX>,
882 I::Ty: HashStable<CTX>,
883 I::Const: HashStable<CTX>,
884 I::TypeAndMut: HashStable<CTX>,
885 I::PolyFnSig: HashStable<CTX>,
886 I::ListBinderExistentialPredicate: HashStable<CTX>,
887 I::Region: HashStable<CTX>,
888 I::Movability: HashStable<CTX>,
889 I::Mutability: HashStable<CTX>,
890 I::BinderListTy: HashStable<CTX>,
891 I::ListTy: HashStable<CTX>,
892 I::ProjectionTy: HashStable<CTX>,
893 I::BoundTy: HashStable<CTX>,
894 I::ParamTy: HashStable<CTX>,
895 I::PlaceholderType: HashStable<CTX>,
896 I::InferTy: HashStable<CTX>,
897 I::DelaySpanBugEmitted: HashStable<CTX>,
903 __hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
905 std::mem::discriminant(self).hash_stable(__hcx, __hasher);
910 i.hash_stable(__hcx, __hasher);
913 u.hash_stable(__hcx, __hasher);
916 f.hash_stable(__hcx, __hasher);
918 Adt(adt, substs) => {
919 adt.hash_stable(__hcx, __hasher);
920 substs.hash_stable(__hcx, __hasher);
923 def_id.hash_stable(__hcx, __hasher);
927 t.hash_stable(__hcx, __hasher);
928 c.hash_stable(__hcx, __hasher);
931 t.hash_stable(__hcx, __hasher);
934 tam.hash_stable(__hcx, __hasher);
937 r.hash_stable(__hcx, __hasher);
938 t.hash_stable(__hcx, __hasher);
939 m.hash_stable(__hcx, __hasher);
941 FnDef(def_id, substs) => {
942 def_id.hash_stable(__hcx, __hasher);
943 substs.hash_stable(__hcx, __hasher);
945 FnPtr(polyfnsig) => {
946 polyfnsig.hash_stable(__hcx, __hasher);
949 l.hash_stable(__hcx, __hasher);
950 r.hash_stable(__hcx, __hasher);
952 Closure(def_id, substs) => {
953 def_id.hash_stable(__hcx, __hasher);
954 substs.hash_stable(__hcx, __hasher);
956 Generator(def_id, substs, m) => {
957 def_id.hash_stable(__hcx, __hasher);
958 substs.hash_stable(__hcx, __hasher);
959 m.hash_stable(__hcx, __hasher);
961 GeneratorWitness(b) => {
962 b.hash_stable(__hcx, __hasher);
966 substs.hash_stable(__hcx, __hasher);
969 p.hash_stable(__hcx, __hasher);
971 Opaque(def_id, substs) => {
972 def_id.hash_stable(__hcx, __hasher);
973 substs.hash_stable(__hcx, __hasher);
976 p.hash_stable(__hcx, __hasher);
979 d.hash_stable(__hcx, __hasher);
980 b.hash_stable(__hcx, __hasher);
983 p.hash_stable(__hcx, __hasher);
986 i.hash_stable(__hcx, __hasher);
989 d.hash_stable(__hcx, __hasher);
995 /// Representation of regions. Note that the NLL checker uses a distinct
996 /// representation of regions. For this reason, it internally replaces all the
997 /// regions with inference variables -- the index of the variable is then used
998 /// to index into internal NLL data structures. See `rustc_const_eval::borrow_check`
999 /// module for more information.
1001 /// Note: operations are on the wrapper `Region` type, which is interned,
1002 /// rather than this type.
1004 /// ## The Region lattice within a given function
1006 /// In general, the region lattice looks like
1009 /// static ----------+-----...------+ (greatest)
1011 /// early-bound and | |
1012 /// free regions | |
1015 /// empty(root) placeholder(U1) |
1017 /// | / placeholder(Un)
1022 /// empty(Un) -------- (smallest)
1025 /// Early-bound/free regions are the named lifetimes in scope from the
1026 /// function declaration. They have relationships to one another
1027 /// determined based on the declared relationships from the
1030 /// Note that inference variables and bound regions are not included
1031 /// in this diagram. In the case of inference variables, they should
1032 /// be inferred to some other region from the diagram. In the case of
1033 /// bound regions, they are excluded because they don't make sense to
1034 /// include -- the diagram indicates the relationship between free
1037 /// ## Inference variables
1039 /// During region inference, we sometimes create inference variables,
1040 /// represented as `ReVar`. These will be inferred by the code in
1041 /// `infer::lexical_region_resolve` to some free region from the
1042 /// lattice above (the minimal region that meets the
1045 /// During NLL checking, where regions are defined differently, we
1046 /// also use `ReVar` -- in that case, the index is used to index into
1047 /// the NLL region checker's data structures. The variable may in fact
1048 /// represent either a free region or an inference variable, in that
1051 /// ## Bound Regions
1053 /// These are regions that are stored behind a binder and must be substituted
1054 /// with some concrete region before being used. There are two kind of
1055 /// bound regions: early-bound, which are bound in an item's `Generics`,
1056 /// and are substituted by an `InternalSubsts`, and late-bound, which are part of
1057 /// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by
1058 /// the likes of `liberate_late_bound_regions`. The distinction exists
1059 /// because higher-ranked lifetimes aren't supported in all places. See [1][2].
1061 /// Unlike `Param`s, bound regions are not supposed to exist "in the wild"
1062 /// outside their binder, e.g., in types passed to type inference, and
1063 /// should first be substituted (by placeholder regions, free regions,
1064 /// or region variables).
1066 /// ## Placeholder and Free Regions
1068 /// One often wants to work with bound regions without knowing their precise
1069 /// identity. For example, when checking a function, the lifetime of a borrow
1070 /// can end up being assigned to some region parameter. In these cases,
1071 /// it must be ensured that bounds on the region can't be accidentally
1072 /// assumed without being checked.
1074 /// To do this, we replace the bound regions with placeholder markers,
1075 /// which don't satisfy any relation not explicitly provided.
1077 /// There are two kinds of placeholder regions in rustc: `ReFree` and
1078 /// `RePlaceholder`. When checking an item's body, `ReFree` is supposed
1079 /// to be used. These also support explicit bounds: both the internally-stored
1080 /// *scope*, which the region is assumed to outlive, as well as other
1081 /// relations stored in the `FreeRegionMap`. Note that these relations
1082 /// aren't checked when you `make_subregion` (or `eq_types`), only by
1083 /// `resolve_regions_and_report_errors`.
1085 /// When working with higher-ranked types, some region relations aren't
1086 /// yet known, so you can't just call `resolve_regions_and_report_errors`.
1087 /// `RePlaceholder` is designed for this purpose. In these contexts,
1088 /// there's also the risk that some inference variable laying around will
1089 /// get unified with your placeholder region: if you want to check whether
1090 /// `for<'a> Foo<'_>: 'a`, and you substitute your bound region `'a`
1091 /// with a placeholder region `'%a`, the variable `'_` would just be
1092 /// instantiated to the placeholder region `'%a`, which is wrong because
1093 /// the inference variable is supposed to satisfy the relation
1094 /// *for every value of the placeholder region*. To ensure that doesn't
1095 /// happen, you can use `leak_check`. This is more clearly explained
1096 /// by the [rustc dev guide].
1098 /// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/
1099 /// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/
1100 /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
1101 pub enum RegionKind<I: Interner> {
1102 /// Region bound in a type or fn declaration which will be
1103 /// substituted 'early' -- that is, at the same time when type
1104 /// parameters are substituted.
1105 ReEarlyBound(I::EarlyBoundRegion),
1107 /// Region bound in a function scope, which will be substituted when the
1108 /// function is called.
1109 ReLateBound(DebruijnIndex, I::BoundRegion),
1111 /// When checking a function body, the types of all arguments and so forth
1112 /// that refer to bound region parameters are modified to refer to free
1113 /// region parameters.
1114 ReFree(I::FreeRegion),
1116 /// Static data that has an "infinite" lifetime. Top in the region lattice.
1119 /// A region variable. Should not exist outside of type inference.
1120 ReVar(I::RegionVid),
1122 /// A placeholder region -- basically, the higher-ranked version of `ReFree`.
1123 /// Should not exist outside of type inference.
1124 RePlaceholder(I::PlaceholderRegion),
1126 /// Empty lifetime is for data that is never accessed. We tag the
1127 /// empty lifetime with a universe -- the idea is that we don't
1128 /// want `exists<'a> { forall<'b> { 'b: 'a } }` to be satisfiable.
1129 /// Therefore, the `'empty` in a universe `U` is less than all
1130 /// regions visible from `U`, but not less than regions not visible
1132 ReEmpty(UniverseIndex),
1134 /// Erased region, used by trait selection, in MIR and during codegen.
1138 // This is manually implemented for `RegionKind` because `std::mem::discriminant`
1139 // returns an opaque value that is `PartialEq` but not `PartialOrd`
1141 const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
1143 ReEarlyBound(_) => 0,
1144 ReLateBound(_, _) => 1,
1148 RePlaceholder(_) => 5,
1154 // This is manually implemented because a derive would require `I: Copy`
1155 impl<I: Interner> Copy for RegionKind<I>
1157 I::EarlyBoundRegion: Copy,
1158 I::BoundRegion: Copy,
1159 I::FreeRegion: Copy,
1161 I::PlaceholderRegion: Copy,
1165 // This is manually implemented because a derive would require `I: Clone`
1166 impl<I: Interner> Clone for RegionKind<I> {
1167 fn clone(&self) -> Self {
1169 ReEarlyBound(a) => ReEarlyBound(a.clone()),
1170 ReLateBound(a, b) => ReLateBound(a.clone(), b.clone()),
1171 ReFree(a) => ReFree(a.clone()),
1172 ReStatic => ReStatic,
1173 ReVar(a) => ReVar(a.clone()),
1174 RePlaceholder(a) => RePlaceholder(a.clone()),
1175 ReEmpty(a) => ReEmpty(a.clone()),
1176 ReErased => ReErased,
1181 // This is manually implemented because a derive would require `I: PartialEq`
1182 impl<I: Interner> PartialEq for RegionKind<I> {
1184 fn eq(&self, other: &RegionKind<I>) -> bool {
1185 let __self_vi = regionkind_discriminant(self);
1186 let __arg_1_vi = regionkind_discriminant(other);
1187 if __self_vi == __arg_1_vi {
1188 match (&*self, &*other) {
1189 (&ReEarlyBound(ref __self_0), &ReEarlyBound(ref __arg_1_0)) => {
1190 __self_0 == __arg_1_0
1193 &ReLateBound(ref __self_0, ref __self_1),
1194 &ReLateBound(ref __arg_1_0, ref __arg_1_1),
1195 ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1,
1196 (&ReFree(ref __self_0), &ReFree(ref __arg_1_0)) => __self_0 == __arg_1_0,
1197 (&ReStatic, &ReStatic) => true,
1198 (&ReVar(ref __self_0), &ReVar(ref __arg_1_0)) => __self_0 == __arg_1_0,
1199 (&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
1200 __self_0 == __arg_1_0
1202 (&ReEmpty(ref __self_0), &ReEmpty(ref __arg_1_0)) => __self_0 == __arg_1_0,
1203 (&ReErased, &ReErased) => true,
1212 // This is manually implemented because a derive would require `I: Eq`
1213 impl<I: Interner> Eq for RegionKind<I> {}
1215 // This is manually implemented because a derive would require `I: PartialOrd`
1216 impl<I: Interner> PartialOrd for RegionKind<I> {
1218 fn partial_cmp(&self, other: &RegionKind<I>) -> Option<Ordering> {
1219 Some(Ord::cmp(self, other))
1223 // This is manually implemented because a derive would require `I: Ord`
1224 impl<I: Interner> Ord for RegionKind<I> {
1226 fn cmp(&self, other: &RegionKind<I>) -> Ordering {
1227 let __self_vi = regionkind_discriminant(self);
1228 let __arg_1_vi = regionkind_discriminant(other);
1229 if __self_vi == __arg_1_vi {
1230 match (&*self, &*other) {
1231 (&ReEarlyBound(ref __self_0), &ReEarlyBound(ref __arg_1_0)) => {
1232 Ord::cmp(__self_0, __arg_1_0)
1235 &ReLateBound(ref __self_0, ref __self_1),
1236 &ReLateBound(ref __arg_1_0, ref __arg_1_1),
1237 ) => match Ord::cmp(__self_0, __arg_1_0) {
1238 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
1241 (&ReFree(ref __self_0), &ReFree(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
1242 (&ReStatic, &ReStatic) => Ordering::Equal,
1243 (&ReVar(ref __self_0), &ReVar(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
1244 (&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
1245 Ord::cmp(__self_0, __arg_1_0)
1247 (&ReEmpty(ref __self_0), &ReEmpty(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
1248 (&ReErased, &ReErased) => Ordering::Equal,
1249 _ => Ordering::Equal,
1252 Ord::cmp(&__self_vi, &__arg_1_vi)
1257 // This is manually implemented because a derive would require `I: Hash`
1258 impl<I: Interner> hash::Hash for RegionKind<I> {
1259 fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
1261 (&ReEarlyBound(ref __self_0),) => {
1262 hash::Hash::hash(®ionkind_discriminant(self), state);
1263 hash::Hash::hash(__self_0, state)
1265 (&ReLateBound(ref __self_0, ref __self_1),) => {
1266 hash::Hash::hash(®ionkind_discriminant(self), state);
1267 hash::Hash::hash(__self_0, state);
1268 hash::Hash::hash(__self_1, state)
1270 (&ReFree(ref __self_0),) => {
1271 hash::Hash::hash(®ionkind_discriminant(self), state);
1272 hash::Hash::hash(__self_0, state)
1275 hash::Hash::hash(®ionkind_discriminant(self), state);
1277 (&ReVar(ref __self_0),) => {
1278 hash::Hash::hash(®ionkind_discriminant(self), state);
1279 hash::Hash::hash(__self_0, state)
1281 (&RePlaceholder(ref __self_0),) => {
1282 hash::Hash::hash(®ionkind_discriminant(self), state);
1283 hash::Hash::hash(__self_0, state)
1285 (&ReEmpty(ref __self_0),) => {
1286 hash::Hash::hash(®ionkind_discriminant(self), state);
1287 hash::Hash::hash(__self_0, state)
1290 hash::Hash::hash(®ionkind_discriminant(self), state);
1296 // This is manually implemented because a derive would require `I: Debug`
1297 impl<I: Interner> fmt::Debug for RegionKind<I> {
1298 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1300 ReEarlyBound(ref data) => write!(f, "ReEarlyBound({:?})", data),
1302 ReLateBound(binder_id, ref bound_region) => {
1303 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
1306 ReFree(ref fr) => fr.fmt(f),
1308 ReStatic => write!(f, "ReStatic"),
1310 ReVar(ref vid) => vid.fmt(f),
1312 RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
1314 ReEmpty(ui) => write!(f, "ReEmpty({:?})", ui),
1316 ReErased => write!(f, "ReErased"),
1321 // This is manually implemented because a derive would require `I: Encodable`
1322 impl<I: Interner, E: TyEncoder> Encodable<E> for RegionKind<I>
1324 I::EarlyBoundRegion: Encodable<E>,
1325 I::BoundRegion: Encodable<E>,
1326 I::FreeRegion: Encodable<E>,
1327 I::RegionVid: Encodable<E>,
1328 I::PlaceholderRegion: Encodable<E>,
1330 fn encode(&self, e: &mut E) {
1331 let disc = regionkind_discriminant(self);
1333 ReEarlyBound(a) => e.emit_enum_variant(disc, |e| {
1336 ReLateBound(a, b) => e.emit_enum_variant(disc, |e| {
1340 ReFree(a) => e.emit_enum_variant(disc, |e| {
1343 ReStatic => e.emit_enum_variant(disc, |_| {}),
1344 ReVar(a) => e.emit_enum_variant(disc, |e| {
1347 RePlaceholder(a) => e.emit_enum_variant(disc, |e| {
1350 ReEmpty(a) => e.emit_enum_variant(disc, |e| {
1353 ReErased => e.emit_enum_variant(disc, |_| {}),
1358 // This is manually implemented because a derive would require `I: Decodable`
1359 impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for RegionKind<I>
1361 I::EarlyBoundRegion: Decodable<D>,
1362 I::BoundRegion: Decodable<D>,
1363 I::FreeRegion: Decodable<D>,
1364 I::RegionVid: Decodable<D>,
1365 I::PlaceholderRegion: Decodable<D>,
1367 fn decode(d: &mut D) -> Self {
1368 match Decoder::read_usize(d) {
1369 0 => ReEarlyBound(Decodable::decode(d)),
1370 1 => ReLateBound(Decodable::decode(d), Decodable::decode(d)),
1371 2 => ReFree(Decodable::decode(d)),
1373 4 => ReVar(Decodable::decode(d)),
1374 5 => RePlaceholder(Decodable::decode(d)),
1375 6 => ReEmpty(Decodable::decode(d)),
1380 "invalid enum variant tag while decoding `{}`, expected 0..{}",
1388 // This is not a derived impl because a derive would require `I: HashStable`
1389 impl<CTX, I: Interner> HashStable<CTX> for RegionKind<I>
1391 I::EarlyBoundRegion: HashStable<CTX>,
1392 I::BoundRegion: HashStable<CTX>,
1393 I::FreeRegion: HashStable<CTX>,
1394 I::RegionVid: HashStable<CTX>,
1395 I::PlaceholderRegion: HashStable<CTX>,
1401 hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
1403 std::mem::discriminant(self).hash_stable(hcx, hasher);
1405 ReErased | ReStatic => {
1406 // No variant fields to hash for these ...
1408 ReEmpty(universe) => {
1409 universe.hash_stable(hcx, hasher);
1411 ReLateBound(db, br) => {
1412 db.hash_stable(hcx, hasher);
1413 br.hash_stable(hcx, hasher);
1415 ReEarlyBound(eb) => {
1416 eb.hash_stable(hcx, hasher);
1418 ReFree(ref free_region) => {
1419 free_region.hash_stable(hcx, hasher);
1421 RePlaceholder(p) => {
1422 p.hash_stable(hcx, hasher);
1425 reg.hash_stable(hcx, hasher);