]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_ty.rs
Refactor away `inferred_obligations` from the trait selector
[rust.git] / src / librustc / ich / impls_ty.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This module contains `HashStable` implementations for various data types
12 //! from rustc::ty in no particular order.
13
14 use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
15 use rustc_data_structures::fx::FxHashMap;
16 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
17                                            StableHasher, StableHasherResult};
18 use std::cell::RefCell;
19 use std::hash as std_hash;
20 use std::mem;
21 use middle::region;
22 use traits;
23 use ty;
24
25 impl<'gcx, T> HashStable<StableHashingContext<'gcx>>
26 for &'gcx ty::Slice<T>
27     where T: HashStable<StableHashingContext<'gcx>> {
28     fn hash_stable<W: StableHasherResult>(&self,
29                                           hcx: &mut StableHashingContext<'gcx>,
30                                           hasher: &mut StableHasher<W>) {
31         thread_local! {
32             static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
33                 RefCell::new(FxHashMap());
34         }
35
36         let hash = CACHE.with(|cache| {
37             let key = (self.as_ptr() as usize, self.len());
38             if let Some(&hash) = cache.borrow().get(&key) {
39                 return hash;
40             }
41
42             let mut hasher = StableHasher::new();
43             (&self[..]).hash_stable(hcx, &mut hasher);
44
45             let hash: Fingerprint = hasher.finish();
46             cache.borrow_mut().insert(key, hash);
47             hash
48         });
49
50         hash.hash_stable(hcx, hasher);
51     }
52 }
53
54 impl<'gcx> HashStable<StableHashingContext<'gcx>>
55 for ty::subst::Kind<'gcx> {
56     fn hash_stable<W: StableHasherResult>(&self,
57                                           hcx: &mut StableHashingContext<'gcx>,
58                                           hasher: &mut StableHasher<W>) {
59         self.unpack().hash_stable(hcx, hasher);
60     }
61 }
62
63 impl<'gcx> HashStable<StableHashingContext<'gcx>>
64 for ty::subst::UnpackedKind<'gcx> {
65     fn hash_stable<W: StableHasherResult>(&self,
66                                           hcx: &mut StableHashingContext<'gcx>,
67                                           hasher: &mut StableHasher<W>) {
68         match self {
69             ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
70             ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
71         }
72     }
73 }
74
75 impl<'gcx> HashStable<StableHashingContext<'gcx>>
76 for ty::RegionKind {
77     fn hash_stable<W: StableHasherResult>(&self,
78                                           hcx: &mut StableHashingContext<'gcx>,
79                                           hasher: &mut StableHasher<W>) {
80         mem::discriminant(self).hash_stable(hcx, hasher);
81         match *self {
82             ty::ReErased |
83             ty::ReStatic |
84             ty::ReEmpty => {
85                 // No variant fields to hash for these ...
86             }
87             ty::ReLateBound(db, ty::BrAnon(i)) => {
88                 db.depth.hash_stable(hcx, hasher);
89                 i.hash_stable(hcx, hasher);
90             }
91             ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
92                 db.depth.hash_stable(hcx, hasher);
93                 def_id.hash_stable(hcx, hasher);
94                 name.hash_stable(hcx, hasher);
95             }
96             ty::ReLateBound(db, ty::BrEnv) => {
97                 db.depth.hash_stable(hcx, hasher);
98             }
99             ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
100                 def_id.hash_stable(hcx, hasher);
101                 index.hash_stable(hcx, hasher);
102                 name.hash_stable(hcx, hasher);
103             }
104             ty::ReScope(scope) => {
105                 scope.hash_stable(hcx, hasher);
106             }
107             ty::ReFree(ref free_region) => {
108                 free_region.hash_stable(hcx, hasher);
109             }
110             ty::ReClosureBound(vid) => {
111                 vid.hash_stable(hcx, hasher);
112             }
113             ty::ReLateBound(..) |
114             ty::ReVar(..) |
115             ty::ReSkolemized(..) => {
116                 bug!("TypeIdHasher: unexpected region {:?}", *self)
117             }
118         }
119     }
120 }
121
122 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::RegionVid {
123     #[inline]
124     fn hash_stable<W: StableHasherResult>(&self,
125                                           hcx: &mut StableHashingContext<'gcx>,
126                                           hasher: &mut StableHasher<W>) {
127         use rustc_data_structures::indexed_vec::Idx;
128         self.index().hash_stable(hcx, hasher);
129     }
130 }
131
132 impl<'gcx> HashStable<StableHashingContext<'gcx>>
133 for ty::adjustment::AutoBorrow<'gcx> {
134     fn hash_stable<W: StableHasherResult>(&self,
135                                           hcx: &mut StableHashingContext<'gcx>,
136                                           hasher: &mut StableHasher<W>) {
137         mem::discriminant(self).hash_stable(hcx, hasher);
138         match *self {
139             ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
140                 region.hash_stable(hcx, hasher);
141                 mutability.hash_stable(hcx, hasher);
142             }
143             ty::adjustment::AutoBorrow::RawPtr(mutability) => {
144                 mutability.hash_stable(hcx, hasher);
145             }
146         }
147     }
148 }
149
150 impl<'gcx> HashStable<StableHashingContext<'gcx>>
151 for ty::adjustment::Adjust<'gcx> {
152     fn hash_stable<W: StableHasherResult>(&self,
153                                           hcx: &mut StableHashingContext<'gcx>,
154                                           hasher: &mut StableHasher<W>) {
155         mem::discriminant(self).hash_stable(hcx, hasher);
156         match *self {
157             ty::adjustment::Adjust::NeverToAny |
158             ty::adjustment::Adjust::ReifyFnPointer |
159             ty::adjustment::Adjust::UnsafeFnPointer |
160             ty::adjustment::Adjust::ClosureFnPointer |
161             ty::adjustment::Adjust::MutToConstPointer |
162             ty::adjustment::Adjust::Unsize => {}
163             ty::adjustment::Adjust::Deref(ref overloaded) => {
164                 overloaded.hash_stable(hcx, hasher);
165             }
166             ty::adjustment::Adjust::Borrow(ref autoref) => {
167                 autoref.hash_stable(hcx, hasher);
168             }
169         }
170     }
171 }
172
173 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
174 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
175 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
176
177 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
178     fn hash_stable<W: StableHasherResult>(&self,
179                                           hcx: &mut StableHashingContext<'gcx>,
180                                           hasher: &mut StableHasher<W>) {
181         mem::discriminant(self).hash_stable(hcx, hasher);
182         match *self {
183             ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
184                 allow_two_phase_borrow.hash_stable(hcx, hasher);
185             }
186             ty::adjustment::AutoBorrowMutability::Immutable => {}
187         }
188     }
189 }
190
191 impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
192
193 impl_stable_hash_for!(enum ty::BorrowKind {
194     ImmBorrow,
195     UniqueImmBorrow,
196     MutBorrow
197 });
198
199 impl<'gcx> HashStable<StableHashingContext<'gcx>>
200 for ty::UpvarCapture<'gcx> {
201     fn hash_stable<W: StableHasherResult>(&self,
202                                           hcx: &mut StableHashingContext<'gcx>,
203                                           hasher: &mut StableHasher<W>) {
204         mem::discriminant(self).hash_stable(hcx, hasher);
205         match *self {
206             ty::UpvarCapture::ByValue => {}
207             ty::UpvarCapture::ByRef(ref up_var_borrow) => {
208                 up_var_borrow.hash_stable(hcx, hasher);
209             }
210         }
211     }
212 }
213
214 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
215     yield_ty,
216     return_ty
217 });
218
219 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
220     inputs_and_output,
221     variadic,
222     unsafety,
223     abi
224 });
225
226 impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for ty::Binder<T>
227     where T: HashStable<StableHashingContext<'gcx>>
228 {
229     fn hash_stable<W: StableHasherResult>(&self,
230                                           hcx: &mut StableHashingContext<'gcx>,
231                                           hasher: &mut StableHasher<W>) {
232         let ty::Binder(ref inner) = *self;
233         inner.hash_stable(hcx, hasher);
234     }
235 }
236
237 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
238
239 impl_stable_hash_for!(enum ty::Visibility {
240     Public,
241     Restricted(def_id),
242     Invisible
243 });
244
245 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
246 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
247 impl_stable_hash_for!(tuple_struct ty::EquatePredicate<'tcx> { t1, t2 });
248 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
249
250 impl<'gcx, A, B> HashStable<StableHashingContext<'gcx>>
251 for ty::OutlivesPredicate<A, B>
252     where A: HashStable<StableHashingContext<'gcx>>,
253           B: HashStable<StableHashingContext<'gcx>>,
254 {
255     fn hash_stable<W: StableHasherResult>(&self,
256                                           hcx: &mut StableHashingContext<'gcx>,
257                                           hasher: &mut StableHasher<W>) {
258         let ty::OutlivesPredicate(ref a, ref b) = *self;
259         a.hash_stable(hcx, hasher);
260         b.hash_stable(hcx, hasher);
261     }
262 }
263
264 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
265 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
266
267
268 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::Predicate<'gcx> {
269     fn hash_stable<W: StableHasherResult>(&self,
270                                           hcx: &mut StableHashingContext<'gcx>,
271                                           hasher: &mut StableHasher<W>) {
272         mem::discriminant(self).hash_stable(hcx, hasher);
273         match *self {
274             ty::Predicate::Trait(ref pred) => {
275                 pred.hash_stable(hcx, hasher);
276             }
277             ty::Predicate::Equate(ref pred) => {
278                 pred.hash_stable(hcx, hasher);
279             }
280             ty::Predicate::Subtype(ref pred) => {
281                 pred.hash_stable(hcx, hasher);
282             }
283             ty::Predicate::RegionOutlives(ref pred) => {
284                 pred.hash_stable(hcx, hasher);
285             }
286             ty::Predicate::TypeOutlives(ref pred) => {
287                 pred.hash_stable(hcx, hasher);
288             }
289             ty::Predicate::Projection(ref pred) => {
290                 pred.hash_stable(hcx, hasher);
291             }
292             ty::Predicate::WellFormed(ty) => {
293                 ty.hash_stable(hcx, hasher);
294             }
295             ty::Predicate::ObjectSafe(def_id) => {
296                 def_id.hash_stable(hcx, hasher);
297             }
298             ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
299                 def_id.hash_stable(hcx, hasher);
300                 closure_substs.hash_stable(hcx, hasher);
301                 closure_kind.hash_stable(hcx, hasher);
302             }
303             ty::Predicate::ConstEvaluatable(def_id, substs) => {
304                 def_id.hash_stable(hcx, hasher);
305                 substs.hash_stable(hcx, hasher);
306             }
307         }
308     }
309 }
310
311 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::AdtFlags {
312     fn hash_stable<W: StableHasherResult>(&self,
313                                           _: &mut StableHashingContext<'gcx>,
314                                           hasher: &mut StableHasher<W>) {
315         std_hash::Hash::hash(self, hasher);
316     }
317 }
318
319 impl_stable_hash_for!(struct ty::VariantDef {
320     did,
321     name,
322     discr,
323     fields,
324     ctor_kind
325 });
326
327 impl_stable_hash_for!(enum ty::VariantDiscr {
328     Explicit(def_id),
329     Relative(distance)
330 });
331
332 impl_stable_hash_for!(struct ty::FieldDef {
333     did,
334     name,
335     vis
336 });
337
338 impl<'gcx> HashStable<StableHashingContext<'gcx>>
339 for ::middle::const_val::ConstVal<'gcx> {
340     fn hash_stable<W: StableHasherResult>(&self,
341                                           hcx: &mut StableHashingContext<'gcx>,
342                                           hasher: &mut StableHasher<W>) {
343         use middle::const_val::ConstVal::*;
344         use middle::const_val::ConstAggregate::*;
345
346         mem::discriminant(self).hash_stable(hcx, hasher);
347
348         match *self {
349             Integral(ref value) => {
350                 value.hash_stable(hcx, hasher);
351             }
352             Float(ref value) => {
353                 value.hash_stable(hcx, hasher);
354             }
355             Str(ref value) => {
356                 value.hash_stable(hcx, hasher);
357             }
358             ByteStr(ref value) => {
359                 value.hash_stable(hcx, hasher);
360             }
361             Bool(value) => {
362                 value.hash_stable(hcx, hasher);
363             }
364             Char(value) => {
365                 value.hash_stable(hcx, hasher);
366             }
367             Variant(def_id) => {
368                 def_id.hash_stable(hcx, hasher);
369             }
370             Function(def_id, substs) => {
371                 def_id.hash_stable(hcx, hasher);
372                 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
373                     substs.hash_stable(hcx, hasher);
374                 });
375             }
376             Aggregate(Struct(ref name_values)) => {
377                 let mut values = name_values.to_vec();
378                 values.sort_unstable_by_key(|&(ref name, _)| name.clone());
379                 values.hash_stable(hcx, hasher);
380             }
381             Aggregate(Tuple(ref value)) => {
382                 value.hash_stable(hcx, hasher);
383             }
384             Aggregate(Array(ref value)) => {
385                 value.hash_stable(hcx, hasher);
386             }
387             Aggregate(Repeat(ref value, times)) => {
388                 value.hash_stable(hcx, hasher);
389                 times.hash_stable(hcx, hasher);
390             }
391             Unevaluated(def_id, substs) => {
392                 def_id.hash_stable(hcx, hasher);
393                 substs.hash_stable(hcx, hasher);
394             }
395         }
396     }
397 }
398
399 impl_stable_hash_for!(struct ::middle::const_val::ByteArray<'tcx> {
400     data
401 });
402
403 impl_stable_hash_for!(struct ty::Const<'tcx> {
404     ty,
405     val
406 });
407
408 impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
409     span,
410     kind
411 });
412
413 impl<'gcx> HashStable<StableHashingContext<'gcx>>
414 for ::middle::const_val::ErrKind<'gcx> {
415     fn hash_stable<W: StableHasherResult>(&self,
416                                           hcx: &mut StableHashingContext<'gcx>,
417                                           hasher: &mut StableHasher<W>) {
418         use middle::const_val::ErrKind::*;
419
420         mem::discriminant(self).hash_stable(hcx, hasher);
421
422         match *self {
423             CannotCast |
424             MissingStructField |
425             NonConstPath |
426             ExpectedConstTuple |
427             ExpectedConstStruct |
428             IndexedNonVec |
429             IndexNotUsize |
430             MiscBinaryOp |
431             MiscCatchAll |
432             IndexOpFeatureGated |
433             TypeckError |
434             CheckMatchError => {
435                 // nothing to do
436             }
437             UnimplementedConstVal(s) => {
438                 s.hash_stable(hcx, hasher);
439             }
440             IndexOutOfBounds { len, index } => {
441                 len.hash_stable(hcx, hasher);
442                 index.hash_stable(hcx, hasher);
443             }
444             Math(ref const_math_err) => {
445                 const_math_err.hash_stable(hcx, hasher);
446             }
447             LayoutError(ref layout_error) => {
448                 layout_error.hash_stable(hcx, hasher);
449             }
450             ErroneousReferencedConstant(ref const_val) => {
451                 const_val.hash_stable(hcx, hasher);
452             }
453         }
454     }
455 }
456
457 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
458
459 impl_stable_hash_for!(struct ty::GeneratorInterior<'tcx> { witness, movable });
460
461 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
462     parent,
463     predicates
464 });
465
466 impl_stable_hash_for!(enum ty::Variance {
467     Covariant,
468     Invariant,
469     Contravariant,
470     Bivariant
471 });
472
473 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
474     Struct(index)
475 });
476
477 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::Generics {
478     fn hash_stable<W: StableHasherResult>(&self,
479                                           hcx: &mut StableHashingContext<'gcx>,
480                                           hasher: &mut StableHasher<W>) {
481         let ty::Generics {
482             parent,
483             parent_regions,
484             parent_types,
485             ref regions,
486             ref types,
487
488             // Reverse map to each `TypeParameterDef`'s `index` field, from
489             // `def_id.index` (`def_id.krate` is the same as the item's).
490             type_param_to_index: _, // Don't hash this
491             has_self,
492             has_late_bound_regions,
493         } = *self;
494
495         parent.hash_stable(hcx, hasher);
496         parent_regions.hash_stable(hcx, hasher);
497         parent_types.hash_stable(hcx, hasher);
498         regions.hash_stable(hcx, hasher);
499         types.hash_stable(hcx, hasher);
500         has_self.hash_stable(hcx, hasher);
501         has_late_bound_regions.hash_stable(hcx, hasher);
502     }
503 }
504
505 impl<'gcx> HashStable<StableHashingContext<'gcx>>
506 for ty::RegionParameterDef {
507     fn hash_stable<W: StableHasherResult>(&self,
508                                           hcx: &mut StableHashingContext<'gcx>,
509                                           hasher: &mut StableHasher<W>) {
510         let ty::RegionParameterDef {
511             name,
512             def_id,
513             index,
514             pure_wrt_drop
515         } = *self;
516
517         name.hash_stable(hcx, hasher);
518         def_id.hash_stable(hcx, hasher);
519         index.hash_stable(hcx, hasher);
520         pure_wrt_drop.hash_stable(hcx, hasher);
521     }
522 }
523
524 impl_stable_hash_for!(struct ty::TypeParameterDef {
525     name,
526     def_id,
527     index,
528     has_default,
529     object_lifetime_default,
530     pure_wrt_drop,
531     synthetic
532 });
533
534 impl<'gcx, T> HashStable<StableHashingContext<'gcx>>
535 for ::middle::resolve_lifetime::Set1<T>
536     where T: HashStable<StableHashingContext<'gcx>>
537 {
538     fn hash_stable<W: StableHasherResult>(&self,
539                                           hcx: &mut StableHashingContext<'gcx>,
540                                           hasher: &mut StableHasher<W>) {
541         use middle::resolve_lifetime::Set1;
542
543         mem::discriminant(self).hash_stable(hcx, hasher);
544         match *self {
545             Set1::Empty |
546             Set1::Many => {
547                 // Nothing to do.
548             }
549             Set1::One(ref value) => {
550                 value.hash_stable(hcx, hasher);
551             }
552         }
553     }
554 }
555
556 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
557     Explicit,
558     InBand
559 });
560
561 impl_stable_hash_for!(enum ::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!(struct ty::DebruijnIndex {
570     depth
571 });
572
573 impl_stable_hash_for!(enum ty::cast::CastKind {
574     CoercionCast,
575     PtrPtrCast,
576     PtrAddrCast,
577     AddrPtrCast,
578     NumericCast,
579     EnumCast,
580     PrimIntCast,
581     U8CharCast,
582     ArrayPtrCast,
583     FnPtrPtrCast,
584     FnPtrAddrCast
585 });
586
587 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
588 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
589
590 impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for region::Scope {
591     type KeyType = region::Scope;
592
593     #[inline]
594     fn to_stable_hash_key(&self, _: &StableHashingContext<'gcx>) -> region::Scope {
595         *self
596     }
597 }
598
599 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
600     block,
601     first_statement_index
602 });
603
604 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
605     custom_kind
606 });
607
608 impl_stable_hash_for!(struct ty::FreeRegion {
609     scope,
610     bound_region
611 });
612
613 impl_stable_hash_for!(enum ty::BoundRegion {
614     BrAnon(index),
615     BrNamed(def_id, name),
616     BrFresh(index),
617     BrEnv
618 });
619
620 impl<'gcx> HashStable<StableHashingContext<'gcx>>
621 for ty::TypeVariants<'gcx>
622 {
623     fn hash_stable<W: StableHasherResult>(&self,
624                                           hcx: &mut StableHashingContext<'gcx>,
625                                           hasher: &mut StableHasher<W>) {
626         use ty::TypeVariants::*;
627
628         mem::discriminant(self).hash_stable(hcx, hasher);
629         match *self {
630             TyBool  |
631             TyChar  |
632             TyStr   |
633             TyError |
634             TyNever => {
635                 // Nothing more to hash.
636             }
637             TyInt(int_ty) => {
638                 int_ty.hash_stable(hcx, hasher);
639             }
640             TyUint(uint_ty) => {
641                 uint_ty.hash_stable(hcx, hasher);
642             }
643             TyFloat(float_ty)  => {
644                 float_ty.hash_stable(hcx, hasher);
645             }
646             TyAdt(adt_def, substs) => {
647                 adt_def.hash_stable(hcx, hasher);
648                 substs.hash_stable(hcx, hasher);
649             }
650             TyArray(inner_ty, len) => {
651                 inner_ty.hash_stable(hcx, hasher);
652                 len.hash_stable(hcx, hasher);
653             }
654             TySlice(inner_ty) => {
655                 inner_ty.hash_stable(hcx, hasher);
656             }
657             TyRawPtr(pointee_ty) => {
658                 pointee_ty.hash_stable(hcx, hasher);
659             }
660             TyRef(region, pointee_ty) => {
661                 region.hash_stable(hcx, hasher);
662                 pointee_ty.hash_stable(hcx, hasher);
663             }
664             TyFnDef(def_id, substs) => {
665                 def_id.hash_stable(hcx, hasher);
666                 substs.hash_stable(hcx, hasher);
667             }
668             TyFnPtr(ref sig) => {
669                 sig.hash_stable(hcx, hasher);
670             }
671             TyDynamic(ref existential_predicates, region) => {
672                 existential_predicates.hash_stable(hcx, hasher);
673                 region.hash_stable(hcx, hasher);
674             }
675             TyClosure(def_id, closure_substs) => {
676                 def_id.hash_stable(hcx, hasher);
677                 closure_substs.hash_stable(hcx, hasher);
678             }
679             TyGenerator(def_id, closure_substs, interior) => {
680                 def_id.hash_stable(hcx, hasher);
681                 closure_substs.hash_stable(hcx, hasher);
682                 interior.hash_stable(hcx, hasher);
683             }
684             TyGeneratorWitness(types) => {
685                 types.hash_stable(hcx, hasher)
686             }
687             TyTuple(inner_tys, from_diverging_type_var) => {
688                 inner_tys.hash_stable(hcx, hasher);
689                 from_diverging_type_var.hash_stable(hcx, hasher);
690             }
691             TyProjection(ref projection_ty) => {
692                 projection_ty.hash_stable(hcx, hasher);
693             }
694             TyAnon(def_id, substs) => {
695                 def_id.hash_stable(hcx, hasher);
696                 substs.hash_stable(hcx, hasher);
697             }
698             TyParam(param_ty) => {
699                 param_ty.hash_stable(hcx, hasher);
700             }
701             TyForeign(def_id) => {
702                 def_id.hash_stable(hcx, hasher);
703             }
704             TyInfer(..) => {
705                 bug!("ty::TypeVariants::hash_stable() - Unexpected variant {:?}.", *self)
706             }
707         }
708     }
709 }
710
711 impl_stable_hash_for!(struct ty::ParamTy {
712     idx,
713     name
714 });
715
716 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
717     ty,
718     mutbl
719 });
720
721 impl<'gcx> HashStable<StableHashingContext<'gcx>>
722 for ty::ExistentialPredicate<'gcx>
723 {
724     fn hash_stable<W: StableHasherResult>(&self,
725                                           hcx: &mut StableHashingContext<'gcx>,
726                                           hasher: &mut StableHasher<W>) {
727         mem::discriminant(self).hash_stable(hcx, hasher);
728         match *self {
729             ty::ExistentialPredicate::Trait(ref trait_ref) => {
730                 trait_ref.hash_stable(hcx, hasher);
731             }
732             ty::ExistentialPredicate::Projection(ref projection) => {
733                 projection.hash_stable(hcx, hasher);
734             }
735             ty::ExistentialPredicate::AutoTrait(def_id) => {
736                 def_id.hash_stable(hcx, hasher);
737             }
738         }
739     }
740 }
741
742 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
743     def_id,
744     substs
745 });
746
747 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
748     item_def_id,
749     substs,
750     ty
751 });
752
753 impl_stable_hash_for!(struct ty::Instance<'tcx> {
754     def,
755     substs
756 });
757
758 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::InstanceDef<'gcx> {
759     fn hash_stable<W: StableHasherResult>(&self,
760                                           hcx: &mut StableHashingContext<'gcx>,
761                                           hasher: &mut StableHasher<W>) {
762         mem::discriminant(self).hash_stable(hcx, hasher);
763
764         match *self {
765             ty::InstanceDef::Item(def_id) => {
766                 def_id.hash_stable(hcx, hasher);
767             }
768             ty::InstanceDef::Intrinsic(def_id) => {
769                 def_id.hash_stable(hcx, hasher);
770             }
771             ty::InstanceDef::FnPtrShim(def_id, ty) => {
772                 def_id.hash_stable(hcx, hasher);
773                 ty.hash_stable(hcx, hasher);
774             }
775             ty::InstanceDef::Virtual(def_id, n) => {
776                 def_id.hash_stable(hcx, hasher);
777                 n.hash_stable(hcx, hasher);
778             }
779             ty::InstanceDef::ClosureOnceShim { call_once } => {
780                 call_once.hash_stable(hcx, hasher);
781             }
782             ty::InstanceDef::DropGlue(def_id, t) => {
783                 def_id.hash_stable(hcx, hasher);
784                 t.hash_stable(hcx, hasher);
785             }
786             ty::InstanceDef::CloneShim(def_id, t) => {
787                 def_id.hash_stable(hcx, hasher);
788                 t.hash_stable(hcx, hasher);
789             }
790         }
791     }
792 }
793
794 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::TraitDef {
795     fn hash_stable<W: StableHasherResult>(&self,
796                                           hcx: &mut StableHashingContext<'gcx>,
797                                           hasher: &mut StableHasher<W>) {
798         let ty::TraitDef {
799             // We already have the def_path_hash below, no need to hash it twice
800             def_id: _,
801             unsafety,
802             paren_sugar,
803             has_auto_impl,
804             def_path_hash,
805         } = *self;
806
807         unsafety.hash_stable(hcx, hasher);
808         paren_sugar.hash_stable(hcx, hasher);
809         has_auto_impl.hash_stable(hcx, hasher);
810         def_path_hash.hash_stable(hcx, hasher);
811     }
812 }
813
814 impl_stable_hash_for!(struct ty::Destructor {
815     did
816 });
817
818 impl_stable_hash_for!(struct ty::DtorckConstraint<'tcx> {
819     outlives,
820     dtorck_types
821 });
822
823
824 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::CrateVariancesMap {
825     fn hash_stable<W: StableHasherResult>(&self,
826                                           hcx: &mut StableHashingContext<'gcx>,
827                                           hasher: &mut StableHasher<W>) {
828         let ty::CrateVariancesMap {
829             ref variances,
830             // This is just an irrelevant helper value.
831             empty_variance: _,
832         } = *self;
833
834         variances.hash_stable(hcx, hasher);
835     }
836 }
837
838 impl_stable_hash_for!(struct ty::AssociatedItem {
839     def_id,
840     name,
841     kind,
842     vis,
843     defaultness,
844     container,
845     method_has_self_argument
846 });
847
848 impl_stable_hash_for!(enum ty::AssociatedKind {
849     Const,
850     Method,
851     Type
852 });
853
854 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
855     TraitContainer(def_id),
856     ImplContainer(def_id)
857 });
858
859
860 impl<'gcx, T> HashStable<StableHashingContext<'gcx>>
861 for ty::steal::Steal<T>
862     where T: HashStable<StableHashingContext<'gcx>>
863 {
864     fn hash_stable<W: StableHasherResult>(&self,
865                                           hcx: &mut StableHashingContext<'gcx>,
866                                           hasher: &mut StableHasher<W>) {
867         self.borrow().hash_stable(hcx, hasher);
868     }
869 }
870
871 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
872     caller_bounds,
873     universe,
874     reveal
875 });
876
877 impl_stable_hash_for!(enum traits::Reveal {
878     UserFacing,
879     All
880 });
881
882 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
883     Reachable,
884     Exported,
885     Public
886 });
887
888 impl<'gcx> HashStable<StableHashingContext<'gcx>>
889 for ::middle::privacy::AccessLevels {
890     fn hash_stable<W: StableHasherResult>(&self,
891                                           hcx: &mut StableHashingContext<'gcx>,
892                                           hasher: &mut StableHasher<W>) {
893         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
894             let ::middle::privacy::AccessLevels {
895                 ref map
896             } = *self;
897
898             map.hash_stable(hcx, hasher);
899         });
900     }
901 }
902
903 impl_stable_hash_for!(struct ty::CrateInherentImpls {
904     inherent_impls
905 });
906
907 impl_stable_hash_for!(enum ::session::CompileIncomplete {
908     Stopped,
909     Errored(error_reported)
910 });
911
912 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
913
914 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
915     reachable_set
916 });
917
918 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
919 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
920     fn hash_stable<W: StableHasherResult>(&self,
921                                           hcx: &mut StableHashingContext<'gcx>,
922                                           hasher: &mut StableHasher<W>) {
923         use traits::Vtable::*;
924
925         mem::discriminant(self).hash_stable(hcx, hasher);
926
927         match self {
928             &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
929             &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
930             &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
931             &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
932             &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
933             &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
934             &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
935             &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
936         }
937     }
938 }
939
940 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
941 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
942     fn hash_stable<W: StableHasherResult>(&self,
943                                           hcx: &mut StableHashingContext<'gcx>,
944                                           hasher: &mut StableHasher<W>) {
945         let traits::VtableImplData {
946             impl_def_id,
947             substs,
948             ref nested,
949         } = *self;
950         impl_def_id.hash_stable(hcx, hasher);
951         substs.hash_stable(hcx, hasher);
952         nested.hash_stable(hcx, hasher);
953     }
954 }
955
956 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
957 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'gcx>> {
958     fn hash_stable<W: StableHasherResult>(&self,
959                                           hcx: &mut StableHashingContext<'gcx>,
960                                           hasher: &mut StableHasher<W>) {
961         let traits::VtableAutoImplData {
962             trait_def_id,
963             ref nested,
964         } = *self;
965         trait_def_id.hash_stable(hcx, hasher);
966         nested.hash_stable(hcx, hasher);
967     }
968 }
969
970 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
971 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
972     fn hash_stable<W: StableHasherResult>(&self,
973                                           hcx: &mut StableHashingContext<'gcx>,
974                                           hasher: &mut StableHasher<W>) {
975         let traits::VtableObjectData {
976             upcast_trait_ref,
977             vtable_base,
978             ref nested,
979         } = *self;
980         upcast_trait_ref.hash_stable(hcx, hasher);
981         vtable_base.hash_stable(hcx, hasher);
982         nested.hash_stable(hcx, hasher);
983     }
984 }
985
986 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
987 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'gcx>> {
988     fn hash_stable<W: StableHasherResult>(&self,
989                                           hcx: &mut StableHashingContext<'gcx>,
990                                           hasher: &mut StableHasher<W>) {
991         let traits::VtableBuiltinData {
992             ref nested,
993         } = *self;
994         nested.hash_stable(hcx, hasher);
995     }
996 }
997
998 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
999 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
1000     fn hash_stable<W: StableHasherResult>(&self,
1001                                           hcx: &mut StableHashingContext<'gcx>,
1002                                           hasher: &mut StableHasher<W>) {
1003         let traits::VtableClosureData {
1004             closure_def_id,
1005             substs,
1006             ref nested,
1007         } = *self;
1008         closure_def_id.hash_stable(hcx, hasher);
1009         substs.hash_stable(hcx, hasher);
1010         nested.hash_stable(hcx, hasher);
1011     }
1012 }
1013
1014 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
1015 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
1016     fn hash_stable<W: StableHasherResult>(&self,
1017                                           hcx: &mut StableHashingContext<'gcx>,
1018                                           hasher: &mut StableHasher<W>) {
1019         let traits::VtableFnPointerData {
1020             fn_ty,
1021             ref nested,
1022         } = *self;
1023         fn_ty.hash_stable(hcx, hasher);
1024         nested.hash_stable(hcx, hasher);
1025     }
1026 }
1027
1028 impl<'gcx, N> HashStable<StableHashingContext<'gcx>>
1029 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'gcx>> {
1030     fn hash_stable<W: StableHasherResult>(&self,
1031                                           hcx: &mut StableHashingContext<'gcx>,
1032                                           hasher: &mut StableHasher<W>) {
1033         let traits::VtableGeneratorData {
1034             closure_def_id,
1035             substs,
1036             ref nested,
1037         } = *self;
1038         closure_def_id.hash_stable(hcx, hasher);
1039         substs.hash_stable(hcx, hasher);
1040         nested.hash_stable(hcx, hasher);
1041     }
1042 }
1043
1044 impl<'gcx> HashStable<StableHashingContext<'gcx>>
1045 for ty::UniverseIndex {
1046     fn hash_stable<W: StableHasherResult>(&self,
1047                                           hcx: &mut StableHashingContext<'gcx>,
1048                                           hasher: &mut StableHasher<W>) {
1049         self.depth().hash_stable(hcx, hasher);
1050     }
1051 }