]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_ty.rs
Rollup merge of #58970 - pnkfelix:issue-58158-size-of-assoc-type-ice, r=petrochenkov
[rust.git] / src / librustc / ich / impls_ty.rs
1 //! This module contains `HashStable` implementations for various data types
2 //! from rustc::ty in no particular order.
3
4 use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
5 use rustc_data_structures::fx::FxHashMap;
6 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
7                                            StableHasher, StableHasherResult};
8 use std::cell::RefCell;
9 use std::hash as std_hash;
10 use std::mem;
11 use crate::middle::region;
12 use crate::infer;
13 use crate::traits;
14 use crate::ty;
15 use crate::mir;
16
17 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
18 for &'gcx ty::List<T>
19     where T: HashStable<StableHashingContext<'a>> {
20     fn hash_stable<W: StableHasherResult>(&self,
21                                           hcx: &mut StableHashingContext<'a>,
22                                           hasher: &mut StableHasher<W>) {
23         thread_local! {
24             static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
25                 RefCell::new(Default::default());
26         }
27
28         let hash = CACHE.with(|cache| {
29             let key = (self.as_ptr() as usize, self.len());
30             if let Some(&hash) = cache.borrow().get(&key) {
31                 return hash;
32             }
33
34             let mut hasher = StableHasher::new();
35             (&self[..]).hash_stable(hcx, &mut hasher);
36
37             let hash: Fingerprint = hasher.finish();
38             cache.borrow_mut().insert(key, hash);
39             hash
40         });
41
42         hash.hash_stable(hcx, hasher);
43     }
44 }
45
46 impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T>
47     where T: HashStable<StableHashingContext<'a>>
48 {
49     type KeyType = Fingerprint;
50
51     #[inline]
52     fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
53         let mut hasher = StableHasher::new();
54         let mut hcx: StableHashingContext<'a> = hcx.clone();
55         self.hash_stable(&mut hcx, &mut hasher);
56         hasher.finish()
57     }
58 }
59
60 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
61     fn hash_stable<W: StableHasherResult>(&self,
62                                           hcx: &mut StableHashingContext<'a>,
63                                           hasher: &mut StableHasher<W>) {
64         self.unpack().hash_stable(hcx, hasher);
65     }
66 }
67
68 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
69 for ty::subst::UnpackedKind<'gcx> {
70     fn hash_stable<W: StableHasherResult>(&self,
71                                           hcx: &mut StableHashingContext<'a>,
72                                           hasher: &mut StableHasher<W>) {
73         mem::discriminant(self).hash_stable(hcx, hasher);
74         match self {
75             ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
76             ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
77             ty::subst::UnpackedKind::Const(ct) => ct.hash_stable(hcx, hasher),
78         }
79     }
80 }
81
82 impl<'a> HashStable<StableHashingContext<'a>>
83 for ty::RegionKind {
84     fn hash_stable<W: StableHasherResult>(&self,
85                                           hcx: &mut StableHashingContext<'a>,
86                                           hasher: &mut StableHasher<W>) {
87         mem::discriminant(self).hash_stable(hcx, hasher);
88         match *self {
89             ty::ReErased |
90             ty::ReStatic |
91             ty::ReEmpty => {
92                 // No variant fields to hash for these ...
93             }
94             ty::ReLateBound(db, ty::BrAnon(i)) => {
95                 db.hash_stable(hcx, hasher);
96                 i.hash_stable(hcx, hasher);
97             }
98             ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
99                 db.hash_stable(hcx, hasher);
100                 def_id.hash_stable(hcx, hasher);
101                 name.hash_stable(hcx, hasher);
102             }
103             ty::ReLateBound(db, ty::BrEnv) => {
104                 db.hash_stable(hcx, hasher);
105             }
106             ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
107                 def_id.hash_stable(hcx, hasher);
108                 index.hash_stable(hcx, hasher);
109                 name.hash_stable(hcx, hasher);
110             }
111             ty::ReScope(scope) => {
112                 scope.hash_stable(hcx, hasher);
113             }
114             ty::ReFree(ref free_region) => {
115                 free_region.hash_stable(hcx, hasher);
116             }
117             ty::ReClosureBound(vid) => {
118                 vid.hash_stable(hcx, hasher);
119             }
120             ty::ReLateBound(..) |
121             ty::ReVar(..) |
122             ty::RePlaceholder(..) => {
123                 bug!("StableHasher: unexpected region {:?}", *self)
124             }
125         }
126     }
127 }
128
129 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
130     #[inline]
131     fn hash_stable<W: StableHasherResult>(&self,
132                                           hcx: &mut StableHashingContext<'a>,
133                                           hasher: &mut StableHasher<W>) {
134         self.index().hash_stable(hcx, hasher);
135     }
136 }
137
138 impl<'gcx, 'tcx> HashStable<StableHashingContext<'gcx>> for ty::ConstVid<'tcx> {
139     #[inline]
140     fn hash_stable<W: StableHasherResult>(&self,
141                                           hcx: &mut StableHashingContext<'gcx>,
142                                           hasher: &mut StableHasher<W>) {
143         self.index.hash_stable(hcx, hasher);
144     }
145 }
146
147 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundVar {
148     #[inline]
149     fn hash_stable<W: StableHasherResult>(&self,
150                                           hcx: &mut StableHashingContext<'gcx>,
151                                           hasher: &mut StableHasher<W>) {
152         self.index().hash_stable(hcx, hasher);
153     }
154 }
155
156 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
157 for ty::adjustment::AutoBorrow<'gcx> {
158     fn hash_stable<W: StableHasherResult>(&self,
159                                           hcx: &mut StableHashingContext<'a>,
160                                           hasher: &mut StableHasher<W>) {
161         mem::discriminant(self).hash_stable(hcx, hasher);
162         match *self {
163             ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
164                 region.hash_stable(hcx, hasher);
165                 mutability.hash_stable(hcx, hasher);
166             }
167             ty::adjustment::AutoBorrow::RawPtr(mutability) => {
168                 mutability.hash_stable(hcx, hasher);
169             }
170         }
171     }
172 }
173
174 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
175 for ty::adjustment::Adjust<'gcx> {
176     fn hash_stable<W: StableHasherResult>(&self,
177                                           hcx: &mut StableHashingContext<'a>,
178                                           hasher: &mut StableHasher<W>) {
179         mem::discriminant(self).hash_stable(hcx, hasher);
180         match *self {
181             ty::adjustment::Adjust::NeverToAny |
182             ty::adjustment::Adjust::ReifyFnPointer |
183             ty::adjustment::Adjust::UnsafeFnPointer |
184             ty::adjustment::Adjust::ClosureFnPointer |
185             ty::adjustment::Adjust::MutToConstPointer |
186             ty::adjustment::Adjust::Unsize => {}
187             ty::adjustment::Adjust::Deref(ref overloaded) => {
188                 overloaded.hash_stable(hcx, hasher);
189             }
190             ty::adjustment::Adjust::Borrow(ref autoref) => {
191                 autoref.hash_stable(hcx, hasher);
192             }
193         }
194     }
195 }
196
197 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
198 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
199 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
200 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
201     Yes,
202     No
203 });
204
205 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
206     fn hash_stable<W: StableHasherResult>(&self,
207                                           hcx: &mut StableHashingContext<'gcx>,
208                                           hasher: &mut StableHasher<W>) {
209         mem::discriminant(self).hash_stable(hcx, hasher);
210         match *self {
211             ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
212                 allow_two_phase_borrow.hash_stable(hcx, hasher);
213             }
214             ty::adjustment::AutoBorrowMutability::Immutable => {}
215         }
216     }
217 }
218
219 impl_stable_hash_for!(tuple_struct ty::util::NeedsDrop { value });
220
221 impl_stable_hash_for!(tuple_struct ty::AdtSizedConstraint<'tcx> { list });
222
223 impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
224
225 impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
226
227 impl_stable_hash_for!(enum ty::BorrowKind {
228     ImmBorrow,
229     UniqueImmBorrow,
230     MutBorrow
231 });
232
233 impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] {
234     ByValue,
235     ByRef(up_var_borrow),
236 });
237
238 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
239     yield_ty,
240     return_ty
241 });
242
243 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
244     inputs_and_output,
245     c_variadic,
246     unsafety,
247     abi
248 });
249
250 impl_stable_hash_for!(struct ty::ResolvedOpaqueTy<'tcx> {
251     concrete_type,
252     substs
253 });
254
255 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
256     where T: HashStable<StableHashingContext<'a>>
257 {
258     fn hash_stable<W: StableHasherResult>(&self,
259                                           hcx: &mut StableHashingContext<'a>,
260                                           hasher: &mut StableHasher<W>) {
261         self.skip_binder().hash_stable(hcx, hasher);
262     }
263 }
264
265 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
266
267 impl_stable_hash_for!(enum ty::Visibility {
268     Public,
269     Restricted(def_id),
270     Invisible
271 });
272
273 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
274 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
275 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
276 impl_stable_hash_for!(impl<A, B> for tuple_struct ty::OutlivesPredicate<A, B> { a, b });
277 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
278 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
279
280 impl_stable_hash_for!(
281     impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] {
282         Trait(pred),
283         Subtype(pred),
284         RegionOutlives(pred),
285         TypeOutlives(pred),
286         Projection(pred),
287         WellFormed(ty),
288         ObjectSafe(def_id),
289         ClosureKind(def_id, closure_substs, closure_kind),
290         ConstEvaluatable(def_id, substs),
291     }
292 );
293
294 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
295     fn hash_stable<W: StableHasherResult>(&self,
296                                           _: &mut StableHashingContext<'a>,
297                                           hasher: &mut StableHasher<W>) {
298         std_hash::Hash::hash(self, hasher);
299     }
300 }
301
302 impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
303     fn hash_stable<W: StableHasherResult>(&self,
304                                           _: &mut StableHashingContext<'a>,
305                                           hasher: &mut StableHasher<W>) {
306         std_hash::Hash::hash(self, hasher);
307     }
308 }
309
310 impl_stable_hash_for!(
311     impl<'tcx> for enum ty::InferConst<'tcx> [ ty::InferConst ] {
312         Var(vid),
313         Fresh(i),
314         Canonical(debruijn, var),
315     }
316 );
317
318 impl_stable_hash_for!(enum ty::VariantDiscr {
319     Explicit(def_id),
320     Relative(distance)
321 });
322
323 impl_stable_hash_for!(struct ty::FieldDef {
324     did,
325     ident -> (ident.name),
326     vis,
327 });
328
329 impl_stable_hash_for!(
330     impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
331         Param(param),
332         Infer(infer),
333         Scalar(val),
334         Slice(a, b),
335         ByRef(ptr, alloc),
336     }
337 );
338
339 impl_stable_hash_for!(struct crate::mir::interpret::RawConst<'tcx> {
340     alloc_id,
341     ty,
342 });
343
344 impl_stable_hash_for! {
345     impl<Tag> for struct mir::interpret::Pointer<Tag> {
346         alloc_id,
347         offset,
348         tag,
349     }
350 }
351
352 impl_stable_hash_for!(
353     impl<Tag> for enum mir::interpret::Scalar<Tag> [ mir::interpret::Scalar ] {
354         Bits { bits, size },
355         Ptr(ptr),
356     }
357 );
358
359 impl_stable_hash_for!(
360     impl<'tcx> for enum mir::interpret::AllocKind<'tcx> [ mir::interpret::AllocKind ] {
361         Function(instance),
362         Static(def_id),
363         Memory(mem),
364     }
365 );
366
367 // AllocIds get resolved to whatever they point to (to be stable)
368 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
369     fn hash_stable<W: StableHasherResult>(
370         &self,
371         hcx: &mut StableHashingContext<'a>,
372         hasher: &mut StableHasher<W>,
373     ) {
374         ty::tls::with_opt(|tcx| {
375             trace!("hashing {:?}", *self);
376             let tcx = tcx.expect("can't hash AllocIds during hir lowering");
377             let alloc_kind = tcx.alloc_map.lock().get(*self);
378             alloc_kind.hash_stable(hcx, hasher);
379         });
380     }
381 }
382
383 // Allocations treat their relocations specially
384 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
385     fn hash_stable<W: StableHasherResult>(
386         &self,
387         hcx: &mut StableHashingContext<'a>,
388         hasher: &mut StableHasher<W>,
389     ) {
390         self.bytes.hash_stable(hcx, hasher);
391         for reloc in self.relocations.iter() {
392             reloc.hash_stable(hcx, hasher);
393         }
394         self.undef_mask.hash_stable(hcx, hasher);
395         self.align.hash_stable(hcx, hasher);
396         self.mutability.hash_stable(hcx, hasher);
397     }
398 }
399
400 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
401     Immutable,
402     Mutable
403 });
404
405 impl_stable_hash_for!(struct ty::Const<'tcx> {
406     ty,
407     val
408 });
409
410 impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] {
411     Unevaluated(did, substs),
412     Evaluated(c)
413 });
414
415 impl_stable_hash_for!(enum mir::interpret::ErrorHandled {
416     Reported,
417     TooGeneric
418 });
419
420 impl_stable_hash_for!(struct mir::interpret::FrameInfo<'tcx> {
421     call_site,
422     lint_root,
423     instance
424 });
425
426 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
427 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
428
429 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
430     parent,
431     predicates
432 });
433
434 impl_stable_hash_for!(
435     impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O>
436         [ mir::interpret::EvalErrorKind ]
437     {
438         FunctionArgCountMismatch,
439         DanglingPointerDeref,
440         DoubleFree,
441         InvalidMemoryAccess,
442         InvalidFunctionPointer,
443         InvalidBool,
444         InvalidNullPointerUsage,
445         ReadPointerAsBytes,
446         ReadBytesAsPointer,
447         ReadForeignStatic,
448         InvalidPointerMath,
449         DeadLocal,
450         StackFrameLimitReached,
451         OutOfTls,
452         TlsOutOfBounds,
453         CalledClosureAsFunction,
454         VtableForArgumentlessMethod,
455         ModifiedConstantMemory,
456         ModifiedStatic,
457         AssumptionNotHeld,
458         InlineAsm,
459         ReallocateNonBasePtr,
460         DeallocateNonBasePtr,
461         HeapAllocZeroBytes,
462         Unreachable,
463         ReadFromReturnPointer,
464         UnimplementedTraitSelection,
465         TypeckError,
466         TooGeneric,
467         DerefFunctionPointer,
468         ExecuteMemory,
469         OverflowNeg,
470         RemainderByZero,
471         DivisionByZero,
472         GeneratorResumedAfterReturn,
473         GeneratorResumedAfterPanic,
474         ReferencedConstant,
475         InfiniteLoop,
476         ReadUndefBytes(offset),
477         InvalidDiscriminant(val),
478         Panic { msg, file, line, col },
479         MachineError(err),
480         FunctionAbiMismatch(a, b),
481         FunctionArgMismatch(a, b),
482         FunctionRetMismatch(a, b),
483         NoMirFor(s),
484         UnterminatedCString(ptr),
485         PointerOutOfBounds { ptr, check, allocation_size },
486         InvalidBoolOp(bop),
487         Unimplemented(s),
488         BoundsCheck { len, index },
489         Intrinsic(s),
490         InvalidChar(c),
491         AbiViolation(s),
492         AlignmentCheckFailed { required, has },
493         ValidationFailure(s),
494         TypeNotPrimitive(ty),
495         ReallocatedWrongMemoryKind(a, b),
496         DeallocatedWrongMemoryKind(a, b),
497         IncorrectAllocationInformation(a, b, c, d),
498         Layout(lay),
499         HeapAllocNonPowerOfTwoAlignment(n),
500         PathNotFound(v),
501         Overflow(op),
502     }
503 );
504
505 impl_stable_hash_for!(enum mir::interpret::InboundsCheck {
506     Live,
507     MaybeDead
508 });
509
510 impl_stable_hash_for!(enum ty::Variance {
511     Covariant,
512     Invariant,
513     Contravariant,
514     Bivariant
515 });
516
517 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
518     Struct(index)
519 });
520
521 impl_stable_hash_for!(struct ty::Generics {
522     parent,
523     parent_count,
524     params,
525     // Reverse map to each param's `index` field, from its `def_id`.
526     param_def_id_to_index -> _, // Don't hash this
527     has_self,
528     has_late_bound_regions,
529 });
530
531 impl_stable_hash_for!(struct ty::GenericParamDef {
532     name,
533     def_id,
534     index,
535     pure_wrt_drop,
536     kind
537 });
538
539 impl_stable_hash_for!(enum ty::GenericParamDefKind {
540     Lifetime,
541     Type { has_default, object_lifetime_default, synthetic },
542     Const,
543 });
544
545 impl_stable_hash_for!(
546     impl<T> for enum crate::middle::resolve_lifetime::Set1<T>
547         [ crate::middle::resolve_lifetime::Set1 ]
548     {
549         Empty,
550         Many,
551         One(value),
552     }
553 );
554
555 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::LifetimeDefOrigin {
556     ExplicitOrElided,
557     InBand,
558     Error,
559 });
560
561 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::Region {
562     Static,
563     EarlyBound(index, decl, is_in_band),
564     LateBound(db_index, decl, is_in_band),
565     LateBoundAnon(db_index, anon_index),
566     Free(call_site_scope_data, decl)
567 });
568
569 impl_stable_hash_for!(enum ty::cast::CastKind {
570     CoercionCast,
571     PtrPtrCast,
572     PtrAddrCast,
573     AddrPtrCast,
574     NumericCast,
575     EnumCast,
576     PrimIntCast,
577     U8CharCast,
578     ArrayPtrCast,
579     FnPtrPtrCast,
580     FnPtrAddrCast
581 });
582
583 impl_stable_hash_for!(struct crate::middle::region::Scope { id, data });
584
585 impl_stable_hash_for!(enum crate::middle::region::ScopeData {
586     Node,
587     CallSite,
588     Arguments,
589     Destruction,
590     Remainder(first_statement_index)
591 });
592
593 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
594     type KeyType = region::Scope;
595
596     #[inline]
597     fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
598         *self
599     }
600 }
601
602 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
603     custom_kind
604 });
605
606 impl_stable_hash_for!(struct ty::FreeRegion {
607     scope,
608     bound_region
609 });
610
611 impl_stable_hash_for!(enum ty::BoundRegion {
612     BrAnon(index),
613     BrNamed(def_id, name),
614     BrFresh(index),
615     BrEnv
616 });
617
618 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
619 for ty::TyKind<'gcx>
620 {
621     fn hash_stable<W: StableHasherResult>(&self,
622                                           hcx: &mut StableHashingContext<'a>,
623                                           hasher: &mut StableHasher<W>) {
624         use crate::ty::TyKind::*;
625
626         mem::discriminant(self).hash_stable(hcx, hasher);
627         match *self {
628             Bool  |
629             Char  |
630             Str   |
631             Error |
632             Never => {
633                 // Nothing more to hash.
634             }
635             Int(int_ty) => {
636                 int_ty.hash_stable(hcx, hasher);
637             }
638             Uint(uint_ty) => {
639                 uint_ty.hash_stable(hcx, hasher);
640             }
641             Float(float_ty)  => {
642                 float_ty.hash_stable(hcx, hasher);
643             }
644             Adt(adt_def, substs) => {
645                 adt_def.hash_stable(hcx, hasher);
646                 substs.hash_stable(hcx, hasher);
647             }
648             Array(inner_ty, len) => {
649                 inner_ty.hash_stable(hcx, hasher);
650                 len.hash_stable(hcx, hasher);
651             }
652             Slice(inner_ty) => {
653                 inner_ty.hash_stable(hcx, hasher);
654             }
655             RawPtr(pointee_ty) => {
656                 pointee_ty.hash_stable(hcx, hasher);
657             }
658             Ref(region, pointee_ty, mutbl) => {
659                 region.hash_stable(hcx, hasher);
660                 pointee_ty.hash_stable(hcx, hasher);
661                 mutbl.hash_stable(hcx, hasher);
662             }
663             FnDef(def_id, substs) => {
664                 def_id.hash_stable(hcx, hasher);
665                 substs.hash_stable(hcx, hasher);
666             }
667             FnPtr(ref sig) => {
668                 sig.hash_stable(hcx, hasher);
669             }
670             Dynamic(ref existential_predicates, region) => {
671                 existential_predicates.hash_stable(hcx, hasher);
672                 region.hash_stable(hcx, hasher);
673             }
674             Closure(def_id, closure_substs) => {
675                 def_id.hash_stable(hcx, hasher);
676                 closure_substs.hash_stable(hcx, hasher);
677             }
678             Generator(def_id, generator_substs, movability) => {
679                 def_id.hash_stable(hcx, hasher);
680                 generator_substs.hash_stable(hcx, hasher);
681                 movability.hash_stable(hcx, hasher);
682             }
683             GeneratorWitness(types) => {
684                 types.hash_stable(hcx, hasher)
685             }
686             Tuple(inner_tys) => {
687                 inner_tys.hash_stable(hcx, hasher);
688             }
689             Projection(ref data) | UnnormalizedProjection(ref data) => {
690                 data.hash_stable(hcx, hasher);
691             }
692             Opaque(def_id, substs) => {
693                 def_id.hash_stable(hcx, hasher);
694                 substs.hash_stable(hcx, hasher);
695             }
696             Param(param_ty) => {
697                 param_ty.hash_stable(hcx, hasher);
698             }
699             Bound(debruijn, bound_ty) => {
700                 debruijn.hash_stable(hcx, hasher);
701                 bound_ty.hash_stable(hcx, hasher);
702             }
703             ty::Placeholder(placeholder_ty) => {
704                 placeholder_ty.hash_stable(hcx, hasher);
705             }
706             Foreign(def_id) => {
707                 def_id.hash_stable(hcx, hasher);
708             }
709             Infer(infer_ty) => {
710                 infer_ty.hash_stable(hcx, hasher);
711             }
712         }
713     }
714 }
715
716 impl_stable_hash_for!(enum ty::InferTy {
717     TyVar(a),
718     IntVar(a),
719     FloatVar(a),
720     FreshTy(a),
721     FreshIntTy(a),
722     FreshFloatTy(a),
723 });
724
725 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
726 for ty::TyVid
727 {
728     fn hash_stable<W: StableHasherResult>(&self,
729                                           _hcx: &mut StableHashingContext<'a>,
730                                           _hasher: &mut StableHasher<W>) {
731         // TyVid values are confined to an inference context and hence
732         // should not be hashed.
733         bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
734     }
735 }
736
737 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
738 for ty::IntVid
739 {
740     fn hash_stable<W: StableHasherResult>(&self,
741                                           _hcx: &mut StableHashingContext<'a>,
742                                           _hasher: &mut StableHasher<W>) {
743         // IntVid values are confined to an inference context and hence
744         // should not be hashed.
745         bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
746     }
747 }
748
749 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
750 for ty::FloatVid
751 {
752     fn hash_stable<W: StableHasherResult>(&self,
753                                           _hcx: &mut StableHashingContext<'a>,
754                                           _hasher: &mut StableHasher<W>) {
755         // FloatVid values are confined to an inference context and hence
756         // should not be hashed.
757         bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
758     }
759 }
760
761 impl_stable_hash_for!(struct ty::ParamConst {
762     index,
763     name
764 });
765
766 impl_stable_hash_for!(struct ty::ParamTy {
767     idx,
768     name
769 });
770
771 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
772     ty,
773     mutbl
774 });
775
776 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
777 for ty::ExistentialPredicate<'gcx>
778 {
779     fn hash_stable<W: StableHasherResult>(&self,
780                                           hcx: &mut StableHashingContext<'a>,
781                                           hasher: &mut StableHasher<W>) {
782         mem::discriminant(self).hash_stable(hcx, hasher);
783         match *self {
784             ty::ExistentialPredicate::Trait(ref trait_ref) => {
785                 trait_ref.hash_stable(hcx, hasher);
786             }
787             ty::ExistentialPredicate::Projection(ref projection) => {
788                 projection.hash_stable(hcx, hasher);
789             }
790             ty::ExistentialPredicate::AutoTrait(def_id) => {
791                 def_id.hash_stable(hcx, hasher);
792             }
793         }
794     }
795 }
796
797 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
798     def_id,
799     substs
800 });
801
802 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
803     item_def_id,
804     substs,
805     ty
806 });
807
808 impl_stable_hash_for!(struct ty::Instance<'tcx> {
809     def,
810     substs
811 });
812
813 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
814     fn hash_stable<W: StableHasherResult>(&self,
815                                           hcx: &mut StableHashingContext<'a>,
816                                           hasher: &mut StableHasher<W>) {
817         mem::discriminant(self).hash_stable(hcx, hasher);
818
819         match *self {
820             ty::InstanceDef::Item(def_id) => {
821                 def_id.hash_stable(hcx, hasher);
822             }
823             ty::InstanceDef::VtableShim(def_id) => {
824                 def_id.hash_stable(hcx, hasher);
825             }
826             ty::InstanceDef::Intrinsic(def_id) => {
827                 def_id.hash_stable(hcx, hasher);
828             }
829             ty::InstanceDef::FnPtrShim(def_id, ty) => {
830                 def_id.hash_stable(hcx, hasher);
831                 ty.hash_stable(hcx, hasher);
832             }
833             ty::InstanceDef::Virtual(def_id, n) => {
834                 def_id.hash_stable(hcx, hasher);
835                 n.hash_stable(hcx, hasher);
836             }
837             ty::InstanceDef::ClosureOnceShim { call_once } => {
838                 call_once.hash_stable(hcx, hasher);
839             }
840             ty::InstanceDef::DropGlue(def_id, ty) => {
841                 def_id.hash_stable(hcx, hasher);
842                 ty.hash_stable(hcx, hasher);
843             }
844             ty::InstanceDef::CloneShim(def_id, ty) => {
845                 def_id.hash_stable(hcx, hasher);
846                 ty.hash_stable(hcx, hasher);
847             }
848         }
849     }
850 }
851
852 impl_stable_hash_for!(struct ty::TraitDef {
853     // We already have the def_path_hash below, no need to hash it twice
854     def_id -> _,
855     unsafety,
856     paren_sugar,
857     has_auto_impl,
858     is_marker,
859     def_path_hash,
860 });
861
862 impl_stable_hash_for!(struct ty::Destructor {
863     did
864 });
865
866 impl_stable_hash_for!(struct ty::CrateVariancesMap {
867     variances,
868     // This is just an irrelevant helper value.
869     empty_variance -> _,
870 });
871
872 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
873     predicates,
874     // This is just an irrelevant helper value.
875     empty_predicate -> _,
876 });
877
878 impl_stable_hash_for!(struct ty::AssociatedItem {
879     def_id,
880     ident -> (ident.name),
881     kind,
882     vis,
883     defaultness,
884     container,
885     method_has_self_argument
886 });
887
888 impl_stable_hash_for!(enum ty::AssociatedKind {
889     Const,
890     Method,
891     Existential,
892     Type
893 });
894
895 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
896     TraitContainer(def_id),
897     ImplContainer(def_id)
898 });
899
900
901 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
902 for ty::steal::Steal<T>
903     where T: HashStable<StableHashingContext<'a>>
904 {
905     fn hash_stable<W: StableHasherResult>(&self,
906                                           hcx: &mut StableHashingContext<'a>,
907                                           hasher: &mut StableHasher<W>) {
908         self.borrow().hash_stable(hcx, hasher);
909     }
910 }
911
912 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
913     caller_bounds,
914     reveal,
915     def_id
916 });
917
918 impl_stable_hash_for!(enum traits::Reveal {
919     UserFacing,
920     All
921 });
922
923 impl_stable_hash_for!(enum crate::middle::privacy::AccessLevel {
924     ReachableFromImplTrait,
925     Reachable,
926     Exported,
927     Public
928 });
929
930 impl<'a> HashStable<StableHashingContext<'a>>
931 for crate::middle::privacy::AccessLevels {
932     fn hash_stable<W: StableHasherResult>(&self,
933                                           hcx: &mut StableHashingContext<'a>,
934                                           hasher: &mut StableHasher<W>) {
935         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
936             let crate::middle::privacy::AccessLevels {
937                 ref map
938             } = *self;
939
940             map.hash_stable(hcx, hasher);
941         });
942     }
943 }
944
945 impl_stable_hash_for!(struct ty::CrateInherentImpls {
946     inherent_impls
947 });
948
949 impl_stable_hash_for!(enum crate::session::CompileIncomplete {
950     Stopped,
951     Errored(error_reported)
952 });
953
954 impl_stable_hash_for!(struct crate::util::common::ErrorReported {});
955
956 impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
957     reachable_set
958 });
959
960 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
961 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
962     fn hash_stable<W: StableHasherResult>(&self,
963                                           hcx: &mut StableHashingContext<'a>,
964                                           hasher: &mut StableHasher<W>) {
965         use crate::traits::Vtable::*;
966
967         mem::discriminant(self).hash_stable(hcx, hasher);
968
969         match self {
970             &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
971             &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
972             &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
973             &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
974             &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
975             &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
976             &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
977             &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
978             &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher),
979         }
980     }
981 }
982
983 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
984 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
985     fn hash_stable<W: StableHasherResult>(&self,
986                                           hcx: &mut StableHashingContext<'a>,
987                                           hasher: &mut StableHasher<W>) {
988         let traits::VtableImplData {
989             impl_def_id,
990             substs,
991             ref nested,
992         } = *self;
993         impl_def_id.hash_stable(hcx, hasher);
994         substs.hash_stable(hcx, hasher);
995         nested.hash_stable(hcx, hasher);
996     }
997 }
998
999 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1000 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1001     fn hash_stable<W: StableHasherResult>(&self,
1002                                           hcx: &mut StableHashingContext<'a>,
1003                                           hasher: &mut StableHasher<W>) {
1004         let traits::VtableAutoImplData {
1005             trait_def_id,
1006             ref nested,
1007         } = *self;
1008         trait_def_id.hash_stable(hcx, hasher);
1009         nested.hash_stable(hcx, hasher);
1010     }
1011 }
1012
1013 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1014 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1015     fn hash_stable<W: StableHasherResult>(&self,
1016                                           hcx: &mut StableHashingContext<'a>,
1017                                           hasher: &mut StableHasher<W>) {
1018         let traits::VtableObjectData {
1019             upcast_trait_ref,
1020             vtable_base,
1021             ref nested,
1022         } = *self;
1023         upcast_trait_ref.hash_stable(hcx, hasher);
1024         vtable_base.hash_stable(hcx, hasher);
1025         nested.hash_stable(hcx, hasher);
1026     }
1027 }
1028
1029 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1030 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1031     fn hash_stable<W: StableHasherResult>(&self,
1032                                           hcx: &mut StableHashingContext<'a>,
1033                                           hasher: &mut StableHasher<W>) {
1034         let traits::VtableBuiltinData {
1035             ref nested,
1036         } = *self;
1037         nested.hash_stable(hcx, hasher);
1038     }
1039 }
1040
1041 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1042 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1043     fn hash_stable<W: StableHasherResult>(&self,
1044                                           hcx: &mut StableHashingContext<'a>,
1045                                           hasher: &mut StableHasher<W>) {
1046         let traits::VtableClosureData {
1047             closure_def_id,
1048             substs,
1049             ref nested,
1050         } = *self;
1051         closure_def_id.hash_stable(hcx, hasher);
1052         substs.hash_stable(hcx, hasher);
1053         nested.hash_stable(hcx, hasher);
1054     }
1055 }
1056
1057 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1058 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1059     fn hash_stable<W: StableHasherResult>(&self,
1060                                           hcx: &mut StableHashingContext<'a>,
1061                                           hasher: &mut StableHasher<W>) {
1062         let traits::VtableFnPointerData {
1063             fn_ty,
1064             ref nested,
1065         } = *self;
1066         fn_ty.hash_stable(hcx, hasher);
1067         nested.hash_stable(hcx, hasher);
1068     }
1069 }
1070
1071 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1072 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1073     fn hash_stable<W: StableHasherResult>(&self,
1074                                           hcx: &mut StableHashingContext<'a>,
1075                                           hasher: &mut StableHasher<W>) {
1076         let traits::VtableGeneratorData {
1077             generator_def_id,
1078             substs,
1079             ref nested,
1080         } = *self;
1081         generator_def_id.hash_stable(hcx, hasher);
1082         substs.hash_stable(hcx, hasher);
1083         nested.hash_stable(hcx, hasher);
1084     }
1085 }
1086
1087 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1088 for traits::VtableTraitAliasData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1089     fn hash_stable<W: StableHasherResult>(&self,
1090                                           hcx: &mut StableHashingContext<'a>,
1091                                           hasher: &mut StableHasher<W>) {
1092         let traits::VtableTraitAliasData {
1093             alias_def_id,
1094             substs,
1095             ref nested,
1096         } = *self;
1097         alias_def_id.hash_stable(hcx, hasher);
1098         substs.hash_stable(hcx, hasher);
1099         nested.hash_stable(hcx, hasher);
1100     }
1101 }
1102
1103 impl_stable_hash_for!(
1104     impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1105         max_universe, variables, value
1106     }
1107 );
1108
1109 impl_stable_hash_for!(
1110     struct infer::canonical::CanonicalVarValues<'tcx> {
1111         var_values
1112     }
1113 );
1114
1115 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1116     kind
1117 });
1118
1119 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1120     Ty(k),
1121     PlaceholderTy(placeholder),
1122     Region(ui),
1123     PlaceholderRegion(placeholder),
1124 });
1125
1126 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1127     General(ui),
1128     Int,
1129     Float
1130 });
1131
1132 impl_stable_hash_for!(
1133     impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
1134         var_values, region_constraints, certainty, value
1135     }
1136 );
1137
1138 impl_stable_hash_for!(enum infer::canonical::Certainty {
1139     Proven, Ambiguous
1140 });
1141
1142 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1143     fn hash_stable<W: StableHasherResult>(&self,
1144                                           hcx: &mut StableHashingContext<'a>,
1145                                           hasher: &mut StableHasher<W>) {
1146         use crate::traits::WhereClause::*;
1147
1148         mem::discriminant(self).hash_stable(hcx, hasher);
1149         match self {
1150             Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1151             ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1152             TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1153             RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1154         }
1155     }
1156 }
1157
1158 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1159     fn hash_stable<W: StableHasherResult>(&self,
1160                                           hcx: &mut StableHashingContext<'a>,
1161                                           hasher: &mut StableHasher<W>) {
1162         use crate::traits::WellFormed::*;
1163
1164         mem::discriminant(self).hash_stable(hcx, hasher);
1165         match self {
1166             Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1167             Ty(ty) => ty.hash_stable(hcx, hasher),
1168         }
1169     }
1170 }
1171
1172 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1173     fn hash_stable<W: StableHasherResult>(&self,
1174                                           hcx: &mut StableHashingContext<'a>,
1175                                           hasher: &mut StableHasher<W>) {
1176         use crate::traits::FromEnv::*;
1177
1178         mem::discriminant(self).hash_stable(hcx, hasher);
1179         match self {
1180             Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1181             Ty(ty) => ty.hash_stable(hcx, hasher),
1182         }
1183     }
1184 }
1185
1186 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1187     fn hash_stable<W: StableHasherResult>(&self,
1188                                           hcx: &mut StableHashingContext<'a>,
1189                                           hasher: &mut StableHasher<W>) {
1190         use crate::traits::DomainGoal::*;
1191
1192         mem::discriminant(self).hash_stable(hcx, hasher);
1193         match self {
1194             Holds(wc) => wc.hash_stable(hcx, hasher),
1195             WellFormed(wf) => wf.hash_stable(hcx, hasher),
1196             FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1197             Normalize(projection) => projection.hash_stable(hcx, hasher),
1198         }
1199     }
1200 }
1201
1202 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1203     fn hash_stable<W: StableHasherResult>(&self,
1204                                           hcx: &mut StableHashingContext<'a>,
1205                                           hasher: &mut StableHasher<W>) {
1206         use crate::traits::GoalKind::*;
1207
1208         mem::discriminant(self).hash_stable(hcx, hasher);
1209         match self {
1210             Implies(hypotheses, goal) => {
1211                 hypotheses.hash_stable(hcx, hasher);
1212                 goal.hash_stable(hcx, hasher);
1213             },
1214             And(goal1, goal2) => {
1215                 goal1.hash_stable(hcx, hasher);
1216                 goal2.hash_stable(hcx, hasher);
1217             }
1218             Not(goal) => goal.hash_stable(hcx, hasher),
1219             DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1220             Quantified(quantifier, goal) => {
1221                 quantifier.hash_stable(hcx, hasher);
1222                 goal.hash_stable(hcx, hasher);
1223             },
1224             Subtype(a, b) => {
1225                 a.hash_stable(hcx, hasher);
1226                 b.hash_stable(hcx, hasher);
1227             }
1228             CannotProve => { },
1229         }
1230     }
1231 }
1232
1233 impl_stable_hash_for!(
1234     struct traits::ProgramClause<'tcx> {
1235         goal, hypotheses, category
1236     }
1237 );
1238
1239 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1240     ImpliedBound,
1241     WellFormed,
1242     Other,
1243 });
1244
1245 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1246     fn hash_stable<W: StableHasherResult>(&self,
1247                                           hcx: &mut StableHashingContext<'a>,
1248                                           hasher: &mut StableHasher<W>) {
1249         use crate::traits::Clause::*;
1250
1251         mem::discriminant(self).hash_stable(hcx, hasher);
1252         match self {
1253             Implies(clause) => clause.hash_stable(hcx, hasher),
1254             ForAll(clause) => clause.hash_stable(hcx, hasher),
1255         }
1256     }
1257 }
1258
1259 impl_stable_hash_for!(enum traits::QuantifierKind {
1260     Universal,
1261     Existential
1262 });
1263
1264 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1265
1266 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1267
1268 impl_stable_hash_for!(
1269     struct traits::Environment<'tcx> {
1270         clauses,
1271     }
1272 );
1273
1274 impl_stable_hash_for!(
1275     impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
1276         environment,
1277         goal,
1278     }
1279 );
1280
1281 impl_stable_hash_for!(
1282     struct ty::CanonicalUserTypeAnnotation<'tcx> {
1283         user_ty, span, inferred_ty
1284     }
1285 );
1286
1287 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::UserType<'gcx> {
1288     fn hash_stable<W: StableHasherResult>(&self,
1289                                           hcx: &mut StableHashingContext<'a>,
1290                                           hasher: &mut StableHasher<W>) {
1291         mem::discriminant(self).hash_stable(hcx, hasher);
1292         match *self {
1293             ty::UserType::Ty(ref ty) => {
1294                 ty.hash_stable(hcx, hasher);
1295             }
1296             ty::UserType::TypeOf(ref def_id, ref substs) => {
1297                 def_id.hash_stable(hcx, hasher);
1298                 substs.hash_stable(hcx, hasher);
1299             }
1300         }
1301     }
1302 }
1303
1304 impl<'a> HashStable<StableHashingContext<'a>> for ty::UserTypeAnnotationIndex {
1305     #[inline]
1306     fn hash_stable<W: StableHasherResult>(&self,
1307                                           hcx: &mut StableHashingContext<'a>,
1308                                           hasher: &mut StableHasher<W>) {
1309         self.index().hash_stable(hcx, hasher);
1310     }
1311 }