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