1 #![allow(rustc::usage_of_ty_tykind)]
3 use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
6 use crate::DebruijnIndex;
8 use crate::HashStableContext;
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 {
559 Bool => Formatter::write_str(f, "Bool"),
560 Char => Formatter::write_str(f, "Char"),
561 Int(f0) => Formatter::debug_tuple_field1_finish(f, "Int", f0),
562 Uint(f0) => Formatter::debug_tuple_field1_finish(f, "Uint", f0),
563 Float(f0) => Formatter::debug_tuple_field1_finish(f, "Float", f0),
564 Adt(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Adt", f0, f1),
565 Foreign(f0) => Formatter::debug_tuple_field1_finish(f, "Foreign", f0),
566 Str => Formatter::write_str(f, "Str"),
567 Array(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Array", f0, f1),
568 Slice(f0) => Formatter::debug_tuple_field1_finish(f, "Slice", f0),
569 RawPtr(f0) => Formatter::debug_tuple_field1_finish(f, "RawPtr", f0),
570 Ref(f0, f1, f2) => Formatter::debug_tuple_field3_finish(f, "Ref", f0, f1, f2),
571 FnDef(f0, f1) => Formatter::debug_tuple_field2_finish(f, "FnDef", f0, f1),
572 FnPtr(f0) => Formatter::debug_tuple_field1_finish(f, "FnPtr", f0),
573 Dynamic(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Dynamic", f0, f1),
574 Closure(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Closure", f0, f1),
575 Generator(f0, f1, f2) => {
576 Formatter::debug_tuple_field3_finish(f, "Generator", f0, f1, f2)
578 GeneratorWitness(f0) => Formatter::debug_tuple_field1_finish(f, "GeneratorWitness", f0),
579 Never => Formatter::write_str(f, "Never"),
580 Tuple(f0) => Formatter::debug_tuple_field1_finish(f, "Tuple", f0),
581 Projection(f0) => Formatter::debug_tuple_field1_finish(f, "Projection", f0),
582 Opaque(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Opaque", f0, f1),
583 Param(f0) => Formatter::debug_tuple_field1_finish(f, "Param", f0),
584 Bound(f0, f1) => Formatter::debug_tuple_field2_finish(f, "Bound", f0, f1),
585 Placeholder(f0) => Formatter::debug_tuple_field1_finish(f, "Placeholder", f0),
586 Infer(f0) => Formatter::debug_tuple_field1_finish(f, "Infer", f0),
587 TyKind::Error(f0) => Formatter::debug_tuple_field1_finish(f, "Error", f0),
592 // This is manually implemented because a derive would require `I: Encodable`
593 impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I>
595 I::DelaySpanBugEmitted: Encodable<E>,
596 I::AdtDef: Encodable<E>,
597 I::SubstsRef: Encodable<E>,
598 I::DefId: Encodable<E>,
600 I::Const: Encodable<E>,
601 I::Region: Encodable<E>,
602 I::TypeAndMut: Encodable<E>,
603 I::Mutability: Encodable<E>,
604 I::Movability: Encodable<E>,
605 I::PolyFnSig: Encodable<E>,
606 I::ListBinderExistentialPredicate: Encodable<E>,
607 I::BinderListTy: Encodable<E>,
608 I::ListTy: Encodable<E>,
609 I::ProjectionTy: Encodable<E>,
610 I::ParamTy: Encodable<E>,
611 I::BoundTy: Encodable<E>,
612 I::PlaceholderType: Encodable<E>,
613 I::InferTy: Encodable<E>,
614 I::DelaySpanBugEmitted: Encodable<E>,
615 I::PredicateKind: Encodable<E>,
616 I::AllocId: Encodable<E>,
618 fn encode(&self, e: &mut E) {
619 let disc = tykind_discriminant(self);
621 Bool => e.emit_enum_variant(disc, |_| {}),
622 Char => e.emit_enum_variant(disc, |_| {}),
623 Int(i) => e.emit_enum_variant(disc, |e| {
626 Uint(u) => e.emit_enum_variant(disc, |e| {
629 Float(f) => e.emit_enum_variant(disc, |e| {
632 Adt(adt, substs) => e.emit_enum_variant(disc, |e| {
636 Foreign(def_id) => e.emit_enum_variant(disc, |e| {
639 Str => e.emit_enum_variant(disc, |_| {}),
640 Array(t, c) => e.emit_enum_variant(disc, |e| {
644 Slice(t) => e.emit_enum_variant(disc, |e| {
647 RawPtr(tam) => e.emit_enum_variant(disc, |e| {
650 Ref(r, t, m) => e.emit_enum_variant(disc, |e| {
655 FnDef(def_id, substs) => e.emit_enum_variant(disc, |e| {
659 FnPtr(polyfnsig) => e.emit_enum_variant(disc, |e| {
662 Dynamic(l, r) => e.emit_enum_variant(disc, |e| {
666 Closure(def_id, substs) => e.emit_enum_variant(disc, |e| {
670 Generator(def_id, substs, m) => e.emit_enum_variant(disc, |e| {
675 GeneratorWitness(b) => e.emit_enum_variant(disc, |e| {
678 Never => e.emit_enum_variant(disc, |_| {}),
679 Tuple(substs) => e.emit_enum_variant(disc, |e| {
682 Projection(p) => e.emit_enum_variant(disc, |e| {
685 Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| {
689 Param(p) => e.emit_enum_variant(disc, |e| {
692 Bound(d, b) => e.emit_enum_variant(disc, |e| {
696 Placeholder(p) => e.emit_enum_variant(disc, |e| {
699 Infer(i) => e.emit_enum_variant(disc, |e| {
702 Error(d) => e.emit_enum_variant(disc, |e| {
709 // This is manually implemented because a derive would require `I: Decodable`
710 impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I>
712 I::DelaySpanBugEmitted: Decodable<D>,
713 I::AdtDef: Decodable<D>,
714 I::SubstsRef: Decodable<D>,
715 I::DefId: Decodable<D>,
717 I::Const: Decodable<D>,
718 I::Region: Decodable<D>,
719 I::TypeAndMut: Decodable<D>,
720 I::Mutability: Decodable<D>,
721 I::Movability: Decodable<D>,
722 I::PolyFnSig: Decodable<D>,
723 I::ListBinderExistentialPredicate: Decodable<D>,
724 I::BinderListTy: Decodable<D>,
725 I::ListTy: Decodable<D>,
726 I::ProjectionTy: Decodable<D>,
727 I::ParamTy: Decodable<D>,
728 I::BoundTy: Decodable<D>,
729 I::PlaceholderType: Decodable<D>,
730 I::InferTy: Decodable<D>,
731 I::DelaySpanBugEmitted: Decodable<D>,
732 I::PredicateKind: Decodable<D>,
733 I::AllocId: Decodable<D>,
735 fn decode(d: &mut D) -> Self {
736 match Decoder::read_usize(d) {
739 2 => Int(Decodable::decode(d)),
740 3 => Uint(Decodable::decode(d)),
741 4 => Float(Decodable::decode(d)),
742 5 => Adt(Decodable::decode(d), Decodable::decode(d)),
743 6 => Foreign(Decodable::decode(d)),
745 8 => Array(Decodable::decode(d), Decodable::decode(d)),
746 9 => Slice(Decodable::decode(d)),
747 10 => RawPtr(Decodable::decode(d)),
748 11 => Ref(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
749 12 => FnDef(Decodable::decode(d), Decodable::decode(d)),
750 13 => FnPtr(Decodable::decode(d)),
751 14 => Dynamic(Decodable::decode(d), Decodable::decode(d)),
752 15 => Closure(Decodable::decode(d), Decodable::decode(d)),
753 16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
754 17 => GeneratorWitness(Decodable::decode(d)),
756 19 => Tuple(Decodable::decode(d)),
757 20 => Projection(Decodable::decode(d)),
758 21 => Opaque(Decodable::decode(d), Decodable::decode(d)),
759 22 => Param(Decodable::decode(d)),
760 23 => Bound(Decodable::decode(d), Decodable::decode(d)),
761 24 => Placeholder(Decodable::decode(d)),
762 25 => Infer(Decodable::decode(d)),
763 26 => Error(Decodable::decode(d)),
767 "invalid enum variant tag while decoding `{}`, expected 0..{}",
775 // This is not a derived impl because a derive would require `I: HashStable`
776 #[allow(rustc::usage_of_ty_tykind)]
777 impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for TyKind<I>
779 I::AdtDef: HashStable<CTX>,
780 I::DefId: HashStable<CTX>,
781 I::SubstsRef: HashStable<CTX>,
782 I::Ty: HashStable<CTX>,
783 I::Const: HashStable<CTX>,
784 I::TypeAndMut: HashStable<CTX>,
785 I::PolyFnSig: HashStable<CTX>,
786 I::ListBinderExistentialPredicate: HashStable<CTX>,
787 I::Region: HashStable<CTX>,
788 I::Movability: HashStable<CTX>,
789 I::Mutability: HashStable<CTX>,
790 I::BinderListTy: HashStable<CTX>,
791 I::ListTy: HashStable<CTX>,
792 I::ProjectionTy: HashStable<CTX>,
793 I::BoundTy: HashStable<CTX>,
794 I::ParamTy: HashStable<CTX>,
795 I::PlaceholderType: HashStable<CTX>,
796 I::InferTy: HashStable<CTX>,
797 I::DelaySpanBugEmitted: HashStable<CTX>,
803 __hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
805 std::mem::discriminant(self).hash_stable(__hcx, __hasher);
810 i.hash_stable(__hcx, __hasher);
813 u.hash_stable(__hcx, __hasher);
816 f.hash_stable(__hcx, __hasher);
818 Adt(adt, substs) => {
819 adt.hash_stable(__hcx, __hasher);
820 substs.hash_stable(__hcx, __hasher);
823 def_id.hash_stable(__hcx, __hasher);
827 t.hash_stable(__hcx, __hasher);
828 c.hash_stable(__hcx, __hasher);
831 t.hash_stable(__hcx, __hasher);
834 tam.hash_stable(__hcx, __hasher);
837 r.hash_stable(__hcx, __hasher);
838 t.hash_stable(__hcx, __hasher);
839 m.hash_stable(__hcx, __hasher);
841 FnDef(def_id, substs) => {
842 def_id.hash_stable(__hcx, __hasher);
843 substs.hash_stable(__hcx, __hasher);
845 FnPtr(polyfnsig) => {
846 polyfnsig.hash_stable(__hcx, __hasher);
849 l.hash_stable(__hcx, __hasher);
850 r.hash_stable(__hcx, __hasher);
852 Closure(def_id, substs) => {
853 def_id.hash_stable(__hcx, __hasher);
854 substs.hash_stable(__hcx, __hasher);
856 Generator(def_id, substs, m) => {
857 def_id.hash_stable(__hcx, __hasher);
858 substs.hash_stable(__hcx, __hasher);
859 m.hash_stable(__hcx, __hasher);
861 GeneratorWitness(b) => {
862 b.hash_stable(__hcx, __hasher);
866 substs.hash_stable(__hcx, __hasher);
869 p.hash_stable(__hcx, __hasher);
871 Opaque(def_id, substs) => {
872 def_id.hash_stable(__hcx, __hasher);
873 substs.hash_stable(__hcx, __hasher);
876 p.hash_stable(__hcx, __hasher);
879 d.hash_stable(__hcx, __hasher);
880 b.hash_stable(__hcx, __hasher);
883 p.hash_stable(__hcx, __hasher);
886 i.hash_stable(__hcx, __hasher);
889 d.hash_stable(__hcx, __hasher);
895 /// Representation of regions. Note that the NLL checker uses a distinct
896 /// representation of regions. For this reason, it internally replaces all the
897 /// regions with inference variables -- the index of the variable is then used
898 /// to index into internal NLL data structures. See `rustc_const_eval::borrow_check`
899 /// module for more information.
901 /// Note: operations are on the wrapper `Region` type, which is interned,
902 /// rather than this type.
904 /// ## The Region lattice within a given function
906 /// In general, the region lattice looks like
909 /// static ----------+-----...------+ (greatest)
911 /// early-bound and | |
915 /// empty(root) placeholder(U1) |
917 /// | / placeholder(Un)
922 /// empty(Un) -------- (smallest)
925 /// Early-bound/free regions are the named lifetimes in scope from the
926 /// function declaration. They have relationships to one another
927 /// determined based on the declared relationships from the
930 /// Note that inference variables and bound regions are not included
931 /// in this diagram. In the case of inference variables, they should
932 /// be inferred to some other region from the diagram. In the case of
933 /// bound regions, they are excluded because they don't make sense to
934 /// include -- the diagram indicates the relationship between free
937 /// ## Inference variables
939 /// During region inference, we sometimes create inference variables,
940 /// represented as `ReVar`. These will be inferred by the code in
941 /// `infer::lexical_region_resolve` to some free region from the
942 /// lattice above (the minimal region that meets the
945 /// During NLL checking, where regions are defined differently, we
946 /// also use `ReVar` -- in that case, the index is used to index into
947 /// the NLL region checker's data structures. The variable may in fact
948 /// represent either a free region or an inference variable, in that
953 /// These are regions that are stored behind a binder and must be substituted
954 /// with some concrete region before being used. There are two kind of
955 /// bound regions: early-bound, which are bound in an item's `Generics`,
956 /// and are substituted by an `InternalSubsts`, and late-bound, which are part of
957 /// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by
958 /// the likes of `liberate_late_bound_regions`. The distinction exists
959 /// because higher-ranked lifetimes aren't supported in all places. See [1][2].
961 /// Unlike `Param`s, bound regions are not supposed to exist "in the wild"
962 /// outside their binder, e.g., in types passed to type inference, and
963 /// should first be substituted (by placeholder regions, free regions,
964 /// or region variables).
966 /// ## Placeholder and Free Regions
968 /// One often wants to work with bound regions without knowing their precise
969 /// identity. For example, when checking a function, the lifetime of a borrow
970 /// can end up being assigned to some region parameter. In these cases,
971 /// it must be ensured that bounds on the region can't be accidentally
972 /// assumed without being checked.
974 /// To do this, we replace the bound regions with placeholder markers,
975 /// which don't satisfy any relation not explicitly provided.
977 /// There are two kinds of placeholder regions in rustc: `ReFree` and
978 /// `RePlaceholder`. When checking an item's body, `ReFree` is supposed
979 /// to be used. These also support explicit bounds: both the internally-stored
980 /// *scope*, which the region is assumed to outlive, as well as other
981 /// relations stored in the `FreeRegionMap`. Note that these relations
982 /// aren't checked when you `make_subregion` (or `eq_types`), only by
983 /// `resolve_regions_and_report_errors`.
985 /// When working with higher-ranked types, some region relations aren't
986 /// yet known, so you can't just call `resolve_regions_and_report_errors`.
987 /// `RePlaceholder` is designed for this purpose. In these contexts,
988 /// there's also the risk that some inference variable laying around will
989 /// get unified with your placeholder region: if you want to check whether
990 /// `for<'a> Foo<'_>: 'a`, and you substitute your bound region `'a`
991 /// with a placeholder region `'%a`, the variable `'_` would just be
992 /// instantiated to the placeholder region `'%a`, which is wrong because
993 /// the inference variable is supposed to satisfy the relation
994 /// *for every value of the placeholder region*. To ensure that doesn't
995 /// happen, you can use `leak_check`. This is more clearly explained
996 /// by the [rustc dev guide].
998 /// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/
999 /// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/
1000 /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
1001 pub enum RegionKind<I: Interner> {
1002 /// Region bound in a type or fn declaration which will be
1003 /// substituted 'early' -- that is, at the same time when type
1004 /// parameters are substituted.
1005 ReEarlyBound(I::EarlyBoundRegion),
1007 /// Region bound in a function scope, which will be substituted when the
1008 /// function is called.
1009 ReLateBound(DebruijnIndex, I::BoundRegion),
1011 /// When checking a function body, the types of all arguments and so forth
1012 /// that refer to bound region parameters are modified to refer to free
1013 /// region parameters.
1014 ReFree(I::FreeRegion),
1016 /// Static data that has an "infinite" lifetime. Top in the region lattice.
1019 /// A region variable. Should not exist outside of type inference.
1020 ReVar(I::RegionVid),
1022 /// A placeholder region -- basically, the higher-ranked version of `ReFree`.
1023 /// Should not exist outside of type inference.
1024 RePlaceholder(I::PlaceholderRegion),
1026 /// Erased region, used by trait selection, in MIR and during codegen.
1030 // This is manually implemented for `RegionKind` because `std::mem::discriminant`
1031 // returns an opaque value that is `PartialEq` but not `PartialOrd`
1033 const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
1035 ReEarlyBound(_) => 0,
1036 ReLateBound(_, _) => 1,
1040 RePlaceholder(_) => 5,
1045 // This is manually implemented because a derive would require `I: Copy`
1046 impl<I: Interner> Copy for RegionKind<I>
1048 I::EarlyBoundRegion: Copy,
1049 I::BoundRegion: Copy,
1050 I::FreeRegion: Copy,
1052 I::PlaceholderRegion: Copy,
1056 // This is manually implemented because a derive would require `I: Clone`
1057 impl<I: Interner> Clone for RegionKind<I> {
1058 fn clone(&self) -> Self {
1060 ReEarlyBound(a) => ReEarlyBound(a.clone()),
1061 ReLateBound(a, b) => ReLateBound(a.clone(), b.clone()),
1062 ReFree(a) => ReFree(a.clone()),
1063 ReStatic => ReStatic,
1064 ReVar(a) => ReVar(a.clone()),
1065 RePlaceholder(a) => RePlaceholder(a.clone()),
1066 ReErased => ReErased,
1071 // This is manually implemented because a derive would require `I: PartialEq`
1072 impl<I: Interner> PartialEq for RegionKind<I> {
1074 fn eq(&self, other: &RegionKind<I>) -> bool {
1075 let __self_vi = regionkind_discriminant(self);
1076 let __arg_1_vi = regionkind_discriminant(other);
1077 if __self_vi == __arg_1_vi {
1078 match (&*self, &*other) {
1079 (&ReEarlyBound(ref __self_0), &ReEarlyBound(ref __arg_1_0)) => {
1080 __self_0 == __arg_1_0
1083 &ReLateBound(ref __self_0, ref __self_1),
1084 &ReLateBound(ref __arg_1_0, ref __arg_1_1),
1085 ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1,
1086 (&ReFree(ref __self_0), &ReFree(ref __arg_1_0)) => __self_0 == __arg_1_0,
1087 (&ReStatic, &ReStatic) => true,
1088 (&ReVar(ref __self_0), &ReVar(ref __arg_1_0)) => __self_0 == __arg_1_0,
1089 (&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
1090 __self_0 == __arg_1_0
1092 (&ReErased, &ReErased) => true,
1101 // This is manually implemented because a derive would require `I: Eq`
1102 impl<I: Interner> Eq for RegionKind<I> {}
1104 // This is manually implemented because a derive would require `I: PartialOrd`
1105 impl<I: Interner> PartialOrd for RegionKind<I> {
1107 fn partial_cmp(&self, other: &RegionKind<I>) -> Option<Ordering> {
1108 Some(Ord::cmp(self, other))
1112 // This is manually implemented because a derive would require `I: Ord`
1113 impl<I: Interner> Ord for RegionKind<I> {
1115 fn cmp(&self, other: &RegionKind<I>) -> Ordering {
1116 let __self_vi = regionkind_discriminant(self);
1117 let __arg_1_vi = regionkind_discriminant(other);
1118 if __self_vi == __arg_1_vi {
1119 match (&*self, &*other) {
1120 (&ReEarlyBound(ref __self_0), &ReEarlyBound(ref __arg_1_0)) => {
1121 Ord::cmp(__self_0, __arg_1_0)
1124 &ReLateBound(ref __self_0, ref __self_1),
1125 &ReLateBound(ref __arg_1_0, ref __arg_1_1),
1126 ) => match Ord::cmp(__self_0, __arg_1_0) {
1127 Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
1130 (&ReFree(ref __self_0), &ReFree(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
1131 (&ReStatic, &ReStatic) => Ordering::Equal,
1132 (&ReVar(ref __self_0), &ReVar(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
1133 (&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
1134 Ord::cmp(__self_0, __arg_1_0)
1136 (&ReErased, &ReErased) => Ordering::Equal,
1137 _ => Ordering::Equal,
1140 Ord::cmp(&__self_vi, &__arg_1_vi)
1145 // This is manually implemented because a derive would require `I: Hash`
1146 impl<I: Interner> hash::Hash for RegionKind<I> {
1147 fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
1149 (&ReEarlyBound(ref __self_0),) => {
1150 hash::Hash::hash(®ionkind_discriminant(self), state);
1151 hash::Hash::hash(__self_0, state)
1153 (&ReLateBound(ref __self_0, ref __self_1),) => {
1154 hash::Hash::hash(®ionkind_discriminant(self), state);
1155 hash::Hash::hash(__self_0, state);
1156 hash::Hash::hash(__self_1, state)
1158 (&ReFree(ref __self_0),) => {
1159 hash::Hash::hash(®ionkind_discriminant(self), state);
1160 hash::Hash::hash(__self_0, state)
1163 hash::Hash::hash(®ionkind_discriminant(self), state);
1165 (&ReVar(ref __self_0),) => {
1166 hash::Hash::hash(®ionkind_discriminant(self), state);
1167 hash::Hash::hash(__self_0, state)
1169 (&RePlaceholder(ref __self_0),) => {
1170 hash::Hash::hash(®ionkind_discriminant(self), state);
1171 hash::Hash::hash(__self_0, state)
1174 hash::Hash::hash(®ionkind_discriminant(self), state);
1180 // This is manually implemented because a derive would require `I: Debug`
1181 impl<I: Interner> fmt::Debug for RegionKind<I> {
1182 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1184 ReEarlyBound(ref data) => write!(f, "ReEarlyBound({:?})", data),
1186 ReLateBound(binder_id, ref bound_region) => {
1187 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
1190 ReFree(ref fr) => fr.fmt(f),
1192 ReStatic => write!(f, "ReStatic"),
1194 ReVar(ref vid) => vid.fmt(f),
1196 RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
1198 ReErased => write!(f, "ReErased"),
1203 // This is manually implemented because a derive would require `I: Encodable`
1204 impl<I: Interner, E: TyEncoder> Encodable<E> for RegionKind<I>
1206 I::EarlyBoundRegion: Encodable<E>,
1207 I::BoundRegion: Encodable<E>,
1208 I::FreeRegion: Encodable<E>,
1209 I::RegionVid: Encodable<E>,
1210 I::PlaceholderRegion: Encodable<E>,
1212 fn encode(&self, e: &mut E) {
1213 let disc = regionkind_discriminant(self);
1215 ReEarlyBound(a) => e.emit_enum_variant(disc, |e| {
1218 ReLateBound(a, b) => e.emit_enum_variant(disc, |e| {
1222 ReFree(a) => e.emit_enum_variant(disc, |e| {
1225 ReStatic => e.emit_enum_variant(disc, |_| {}),
1226 ReVar(a) => e.emit_enum_variant(disc, |e| {
1229 RePlaceholder(a) => e.emit_enum_variant(disc, |e| {
1232 ReErased => e.emit_enum_variant(disc, |_| {}),
1237 // This is manually implemented because a derive would require `I: Decodable`
1238 impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for RegionKind<I>
1240 I::EarlyBoundRegion: Decodable<D>,
1241 I::BoundRegion: Decodable<D>,
1242 I::FreeRegion: Decodable<D>,
1243 I::RegionVid: Decodable<D>,
1244 I::PlaceholderRegion: Decodable<D>,
1246 fn decode(d: &mut D) -> Self {
1247 match Decoder::read_usize(d) {
1248 0 => ReEarlyBound(Decodable::decode(d)),
1249 1 => ReLateBound(Decodable::decode(d), Decodable::decode(d)),
1250 2 => ReFree(Decodable::decode(d)),
1252 4 => ReVar(Decodable::decode(d)),
1253 5 => RePlaceholder(Decodable::decode(d)),
1258 "invalid enum variant tag while decoding `{}`, expected 0..{}",
1266 // This is not a derived impl because a derive would require `I: HashStable`
1267 impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for RegionKind<I>
1269 I::EarlyBoundRegion: HashStable<CTX>,
1270 I::BoundRegion: HashStable<CTX>,
1271 I::FreeRegion: HashStable<CTX>,
1272 I::RegionVid: HashStable<CTX>,
1273 I::PlaceholderRegion: HashStable<CTX>,
1279 hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
1281 std::mem::discriminant(self).hash_stable(hcx, hasher);
1283 ReErased | ReStatic => {
1284 // No variant fields to hash for these ...
1286 ReLateBound(db, br) => {
1287 db.hash_stable(hcx, hasher);
1288 br.hash_stable(hcx, hasher);
1290 ReEarlyBound(eb) => {
1291 eb.hash_stable(hcx, hasher);
1293 ReFree(ref free_region) => {
1294 free_region.hash_stable(hcx, hasher);
1296 RePlaceholder(p) => {
1297 p.hash_stable(hcx, hasher);
1300 reg.hash_stable(hcx, hasher);