]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_ty.rs
Use ItemLocalId as key for TypeckTables::fru_field_types.
[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::{self, StableHashingContext, NodeIdHashingMode};
15 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
16                                            StableHasherResult};
17 use std::hash as std_hash;
18 use std::mem;
19 use syntax_pos::symbol::InternedString;
20 use ty;
21
22 impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
23 for &'gcx ty::Slice<T>
24     where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> {
25     fn hash_stable<W: StableHasherResult>(&self,
26                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
27                                           hasher: &mut StableHasher<W>) {
28         (&self[..]).hash_stable(hcx, hasher);
29     }
30 }
31
32 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
33 for ty::subst::Kind<'gcx> {
34     fn hash_stable<W: StableHasherResult>(&self,
35                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
36                                           hasher: &mut StableHasher<W>) {
37         self.as_type().hash_stable(hcx, hasher);
38         self.as_region().hash_stable(hcx, hasher);
39     }
40 }
41
42 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
43 for ty::RegionKind {
44     fn hash_stable<W: StableHasherResult>(&self,
45                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
46                                           hasher: &mut StableHasher<W>) {
47         mem::discriminant(self).hash_stable(hcx, hasher);
48         match *self {
49             ty::ReErased |
50             ty::ReStatic |
51             ty::ReEmpty => {
52                 // No variant fields to hash for these ...
53             }
54             ty::ReLateBound(db, ty::BrAnon(i)) => {
55                 db.depth.hash_stable(hcx, hasher);
56                 i.hash_stable(hcx, hasher);
57             }
58             ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
59                 db.depth.hash_stable(hcx, hasher);
60                 def_id.hash_stable(hcx, hasher);
61                 name.hash_stable(hcx, hasher);
62             }
63             ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
64                 def_id.hash_stable(hcx, hasher);
65                 index.hash_stable(hcx, hasher);
66                 name.hash_stable(hcx, hasher);
67             }
68             ty::ReScope(code_extent) => {
69                 code_extent.hash_stable(hcx, hasher);
70             }
71             ty::ReFree(ref free_region) => {
72                 free_region.hash_stable(hcx, hasher);
73             }
74             ty::ReLateBound(..) |
75             ty::ReVar(..) |
76             ty::ReSkolemized(..) => {
77                 bug!("TypeIdHasher: unexpected region {:?}", *self)
78             }
79         }
80     }
81 }
82
83 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
84 for ty::adjustment::AutoBorrow<'gcx> {
85     fn hash_stable<W: StableHasherResult>(&self,
86                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
87                                           hasher: &mut StableHasher<W>) {
88         mem::discriminant(self).hash_stable(hcx, hasher);
89         match *self {
90             ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
91                 region.hash_stable(hcx, hasher);
92                 mutability.hash_stable(hcx, hasher);
93             }
94             ty::adjustment::AutoBorrow::RawPtr(mutability) => {
95                 mutability.hash_stable(hcx, hasher);
96             }
97         }
98     }
99 }
100
101 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
102 for ty::adjustment::Adjust<'gcx> {
103     fn hash_stable<W: StableHasherResult>(&self,
104                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
105                                           hasher: &mut StableHasher<W>) {
106         mem::discriminant(self).hash_stable(hcx, hasher);
107         match *self {
108             ty::adjustment::Adjust::NeverToAny |
109             ty::adjustment::Adjust::ReifyFnPointer |
110             ty::adjustment::Adjust::UnsafeFnPointer |
111             ty::adjustment::Adjust::ClosureFnPointer |
112             ty::adjustment::Adjust::MutToConstPointer |
113             ty::adjustment::Adjust::Unsize => {}
114             ty::adjustment::Adjust::Deref(ref overloaded) => {
115                 overloaded.hash_stable(hcx, hasher);
116             }
117             ty::adjustment::Adjust::Borrow(ref autoref) => {
118                 autoref.hash_stable(hcx, hasher);
119             }
120         }
121     }
122 }
123
124 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
125 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
126 impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
127 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
128
129 impl_stable_hash_for!(enum ty::BorrowKind {
130     ImmBorrow,
131     UniqueImmBorrow,
132     MutBorrow
133 });
134
135 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
136 for ty::UpvarCapture<'gcx> {
137     fn hash_stable<W: StableHasherResult>(&self,
138                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
139                                           hasher: &mut StableHasher<W>) {
140         mem::discriminant(self).hash_stable(hcx, hasher);
141         match *self {
142             ty::UpvarCapture::ByValue => {}
143             ty::UpvarCapture::ByRef(ref up_var_borrow) => {
144                 up_var_borrow.hash_stable(hcx, hasher);
145             }
146         }
147     }
148 }
149
150 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
151     inputs_and_output,
152     variadic,
153     unsafety,
154     abi
155 });
156
157 impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::Binder<T>
158     where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
159 {
160     fn hash_stable<W: StableHasherResult>(&self,
161                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
162                                           hasher: &mut StableHasher<W>) {
163         let ty::Binder(ref inner) = *self;
164         inner.hash_stable(hcx, hasher);
165     }
166 }
167
168 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
169
170 impl_stable_hash_for!(enum ty::Visibility {
171     Public,
172     Restricted(def_id),
173     Invisible
174 });
175
176 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
177 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
178 impl_stable_hash_for!(tuple_struct ty::EquatePredicate<'tcx> { t1, t2 });
179 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
180
181 impl<'a, 'gcx, 'tcx, A, B> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
182 for ty::OutlivesPredicate<A, B>
183     where A: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
184           B: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
185 {
186     fn hash_stable<W: StableHasherResult>(&self,
187                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
188                                           hasher: &mut StableHasher<W>) {
189         let ty::OutlivesPredicate(ref a, ref b) = *self;
190         a.hash_stable(hcx, hasher);
191         b.hash_stable(hcx, hasher);
192     }
193 }
194
195 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
196 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
197
198
199 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::Predicate<'gcx> {
200     fn hash_stable<W: StableHasherResult>(&self,
201                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
202                                           hasher: &mut StableHasher<W>) {
203         mem::discriminant(self).hash_stable(hcx, hasher);
204         match *self {
205             ty::Predicate::Trait(ref pred) => {
206                 pred.hash_stable(hcx, hasher);
207             }
208             ty::Predicate::Equate(ref pred) => {
209                 pred.hash_stable(hcx, hasher);
210             }
211             ty::Predicate::Subtype(ref pred) => {
212                 pred.hash_stable(hcx, hasher);
213             }
214             ty::Predicate::RegionOutlives(ref pred) => {
215                 pred.hash_stable(hcx, hasher);
216             }
217             ty::Predicate::TypeOutlives(ref pred) => {
218                 pred.hash_stable(hcx, hasher);
219             }
220             ty::Predicate::Projection(ref pred) => {
221                 pred.hash_stable(hcx, hasher);
222             }
223             ty::Predicate::WellFormed(ty) => {
224                 ty.hash_stable(hcx, hasher);
225             }
226             ty::Predicate::ObjectSafe(def_id) => {
227                 def_id.hash_stable(hcx, hasher);
228             }
229             ty::Predicate::ClosureKind(def_id, closure_kind) => {
230                 def_id.hash_stable(hcx, hasher);
231                 closure_kind.hash_stable(hcx, hasher);
232             }
233         }
234     }
235 }
236
237 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::AdtFlags {
238     fn hash_stable<W: StableHasherResult>(&self,
239                                           _: &mut StableHashingContext<'a, 'gcx, 'tcx>,
240                                           hasher: &mut StableHasher<W>) {
241         std_hash::Hash::hash(self, hasher);
242     }
243 }
244
245 impl_stable_hash_for!(struct ty::VariantDef {
246     did,
247     name,
248     discr,
249     fields,
250     ctor_kind
251 });
252
253 impl_stable_hash_for!(enum ty::VariantDiscr {
254     Explicit(def_id),
255     Relative(distance)
256 });
257
258 impl_stable_hash_for!(struct ty::FieldDef {
259     did,
260     name,
261     vis
262 });
263
264 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
265 for ::middle::const_val::ConstVal<'gcx> {
266     fn hash_stable<W: StableHasherResult>(&self,
267                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
268                                           hasher: &mut StableHasher<W>) {
269         use middle::const_val::ConstVal;
270
271         mem::discriminant(self).hash_stable(hcx, hasher);
272
273         match *self {
274             ConstVal::Float(ref value) => {
275                 value.hash_stable(hcx, hasher);
276             }
277             ConstVal::Integral(ref value) => {
278                 value.hash_stable(hcx, hasher);
279             }
280             ConstVal::Str(ref value) => {
281                 value.hash_stable(hcx, hasher);
282             }
283             ConstVal::ByteStr(ref value) => {
284                 value.hash_stable(hcx, hasher);
285             }
286             ConstVal::Bool(value) => {
287                 value.hash_stable(hcx, hasher);
288             }
289             ConstVal::Char(value) => {
290                 value.hash_stable(hcx, hasher);
291             }
292             ConstVal::Variant(def_id) => {
293                 def_id.hash_stable(hcx, hasher);
294             }
295             ConstVal::Function(def_id, substs) => {
296                 def_id.hash_stable(hcx, hasher);
297                 substs.hash_stable(hcx, hasher);
298             }
299             ConstVal::Struct(ref name_value_map) => {
300                 let mut values: Vec<(InternedString, &ConstVal)> =
301                     name_value_map.iter()
302                                   .map(|(name, val)| (name.as_str(), val))
303                                   .collect();
304
305                 values.sort_unstable_by_key(|&(ref name, _)| name.clone());
306                 values.hash_stable(hcx, hasher);
307             }
308             ConstVal::Tuple(ref value) => {
309                 value.hash_stable(hcx, hasher);
310             }
311             ConstVal::Array(ref value) => {
312                 value.hash_stable(hcx, hasher);
313             }
314             ConstVal::Repeat(ref value, times) => {
315                 value.hash_stable(hcx, hasher);
316                 times.hash_stable(hcx, hasher);
317             }
318         }
319     }
320 }
321
322 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
323
324 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
325     parent,
326     predicates
327 });
328
329 impl_stable_hash_for!(enum ty::Variance {
330     Covariant,
331     Invariant,
332     Contravariant,
333     Bivariant
334 });
335
336 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
337     Struct(index)
338 });
339
340 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::Generics {
341     fn hash_stable<W: StableHasherResult>(&self,
342                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
343                                           hasher: &mut StableHasher<W>) {
344         let ty::Generics {
345             parent,
346             parent_regions,
347             parent_types,
348             ref regions,
349             ref types,
350
351             // Reverse map to each `TypeParameterDef`'s `index` field, from
352             // `def_id.index` (`def_id.krate` is the same as the item's).
353             type_param_to_index: _, // Don't hash this
354             has_self,
355             has_late_bound_regions,
356         } = *self;
357
358         parent.hash_stable(hcx, hasher);
359         parent_regions.hash_stable(hcx, hasher);
360         parent_types.hash_stable(hcx, hasher);
361         regions.hash_stable(hcx, hasher);
362         types.hash_stable(hcx, hasher);
363         has_self.hash_stable(hcx, hasher);
364         has_late_bound_regions.hash_stable(hcx, hasher);
365     }
366 }
367
368 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
369 for ty::RegionParameterDef {
370     fn hash_stable<W: StableHasherResult>(&self,
371                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
372                                           hasher: &mut StableHasher<W>) {
373         let ty::RegionParameterDef {
374             name,
375             def_id,
376             index,
377             pure_wrt_drop
378         } = *self;
379
380         name.hash_stable(hcx, hasher);
381         def_id.hash_stable(hcx, hasher);
382         index.hash_stable(hcx, hasher);
383         pure_wrt_drop.hash_stable(hcx, hasher);
384     }
385 }
386
387 impl_stable_hash_for!(struct ty::TypeParameterDef {
388     name,
389     def_id,
390     index,
391     has_default,
392     object_lifetime_default,
393     pure_wrt_drop
394 });
395
396
397 impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
398 for ::middle::resolve_lifetime::Set1<T>
399     where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
400 {
401     fn hash_stable<W: StableHasherResult>(&self,
402                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
403                                           hasher: &mut StableHasher<W>) {
404         use middle::resolve_lifetime::Set1;
405
406         mem::discriminant(self).hash_stable(hcx, hasher);
407         match *self {
408             Set1::Empty |
409             Set1::Many => {
410                 // Nothing to do.
411             }
412             Set1::One(ref value) => {
413                 value.hash_stable(hcx, hasher);
414             }
415         }
416     }
417 }
418
419 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
420     Static,
421     EarlyBound(index, decl),
422     LateBound(db_index, decl),
423     LateBoundAnon(db_index, anon_index),
424     Free(call_site_scope_data, decl)
425 });
426
427 impl_stable_hash_for!(struct ty::DebruijnIndex {
428     depth
429 });
430
431 impl_stable_hash_for!(enum ty::cast::CastKind {
432     CoercionCast,
433     PtrPtrCast,
434     PtrAddrCast,
435     AddrPtrCast,
436     NumericCast,
437     EnumCast,
438     PrimIntCast,
439     U8CharCast,
440     ArrayPtrCast,
441     FnPtrPtrCast,
442     FnPtrAddrCast
443 });
444
445 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
446 for ::middle::region::CodeExtent
447 {
448     fn hash_stable<W: StableHasherResult>(&self,
449                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
450                                           hasher: &mut StableHasher<W>) {
451         use middle::region::CodeExtent;
452
453         mem::discriminant(self).hash_stable(hcx, hasher);
454         match *self {
455             CodeExtent::Misc(node_id) |
456             CodeExtent::DestructionScope(node_id) => {
457                 node_id.hash_stable(hcx, hasher);
458             }
459             CodeExtent::CallSiteScope(body_id) |
460             CodeExtent::ParameterScope(body_id) => {
461                 body_id.hash_stable(hcx, hasher);
462             }
463             CodeExtent::Remainder(block_remainder) => {
464                 block_remainder.hash_stable(hcx, hasher);
465             }
466         }
467     }
468 }
469
470 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
471     block,
472     first_statement_index
473 });
474
475 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
476     custom_kind
477 });
478
479 impl_stable_hash_for!(struct ty::FreeRegion {
480     scope,
481     bound_region
482 });
483
484 impl_stable_hash_for!(enum ty::BoundRegion {
485     BrAnon(index),
486     BrNamed(def_id, name),
487     BrFresh(index),
488     BrEnv
489 });
490
491 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
492 for ty::TypeVariants<'gcx>
493 {
494     fn hash_stable<W: StableHasherResult>(&self,
495                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
496                                           hasher: &mut StableHasher<W>) {
497         use ty::TypeVariants::*;
498
499         mem::discriminant(self).hash_stable(hcx, hasher);
500         match *self {
501             TyBool  |
502             TyChar  |
503             TyStr   |
504             TyNever => {
505                 // Nothing more to hash.
506             }
507             TyInt(int_ty) => {
508                 int_ty.hash_stable(hcx, hasher);
509             }
510             TyUint(uint_ty) => {
511                 uint_ty.hash_stable(hcx, hasher);
512             }
513             TyFloat(float_ty)  => {
514                 float_ty.hash_stable(hcx, hasher);
515             }
516             TyAdt(adt_def, substs) => {
517                 adt_def.hash_stable(hcx, hasher);
518                 substs.hash_stable(hcx, hasher);
519             }
520             TyArray(inner_ty, len) => {
521                 inner_ty.hash_stable(hcx, hasher);
522                 len.hash_stable(hcx, hasher);
523             }
524             TySlice(inner_ty) => {
525                 inner_ty.hash_stable(hcx, hasher);
526             }
527             TyRawPtr(pointee_ty) => {
528                 pointee_ty.hash_stable(hcx, hasher);
529             }
530             TyRef(region, pointee_ty) => {
531                 region.hash_stable(hcx, hasher);
532                 pointee_ty.hash_stable(hcx, hasher);
533             }
534             TyFnDef(def_id, substs) => {
535                 def_id.hash_stable(hcx, hasher);
536                 substs.hash_stable(hcx, hasher);
537             }
538             TyFnPtr(ref sig) => {
539                 sig.hash_stable(hcx, hasher);
540             }
541             TyDynamic(ref existential_predicates, region) => {
542                 existential_predicates.hash_stable(hcx, hasher);
543                 region.hash_stable(hcx, hasher);
544             }
545             TyClosure(def_id, closure_substs) => {
546                 def_id.hash_stable(hcx, hasher);
547                 closure_substs.hash_stable(hcx, hasher);
548             }
549             TyTuple(inner_tys, from_diverging_type_var) => {
550                 inner_tys.hash_stable(hcx, hasher);
551                 from_diverging_type_var.hash_stable(hcx, hasher);
552             }
553             TyProjection(ref projection_ty) => {
554                 projection_ty.hash_stable(hcx, hasher);
555             }
556             TyAnon(def_id, substs) => {
557                 def_id.hash_stable(hcx, hasher);
558                 substs.hash_stable(hcx, hasher);
559             }
560             TyParam(param_ty) => {
561                 param_ty.hash_stable(hcx, hasher);
562             }
563
564             TyError     |
565             TyInfer(..) => {
566                 bug!("ty::TypeVariants::hash_stable() - Unexpected variant.")
567             }
568         }
569     }
570 }
571
572 impl_stable_hash_for!(struct ty::ParamTy {
573     idx,
574     name
575 });
576
577 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
578     ty,
579     mutbl
580 });
581
582 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
583 for ty::ExistentialPredicate<'gcx>
584 {
585     fn hash_stable<W: StableHasherResult>(&self,
586                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
587                                           hasher: &mut StableHasher<W>) {
588         mem::discriminant(self).hash_stable(hcx, hasher);
589         match *self {
590             ty::ExistentialPredicate::Trait(ref trait_ref) => {
591                 trait_ref.hash_stable(hcx, hasher);
592             }
593             ty::ExistentialPredicate::Projection(ref projection) => {
594                 projection.hash_stable(hcx, hasher);
595             }
596             ty::ExistentialPredicate::AutoTrait(def_id) => {
597                 def_id.hash_stable(hcx, hasher);
598             }
599         }
600     }
601 }
602
603 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
604     def_id,
605     substs
606 });
607
608 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
609     item_def_id,
610     substs,
611     ty
612 });
613
614
615 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
616 for ty::TypeckTables<'gcx> {
617     fn hash_stable<W: StableHasherResult>(&self,
618                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
619                                           hasher: &mut StableHasher<W>) {
620         let ty::TypeckTables {
621             local_id_root: _,
622             ref type_dependent_defs,
623             ref node_types,
624             ref node_substs,
625             ref adjustments,
626             ref pat_binding_modes,
627             ref upvar_capture_map,
628             ref closure_tys,
629             ref closure_kinds,
630             ref liberated_fn_sigs,
631             ref fru_field_types,
632
633             ref cast_kinds,
634
635             ref used_trait_imports,
636             tainted_by_errors,
637             ref free_region_map,
638         } = *self;
639
640         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
641             ich::hash_stable_itemlocalmap(hcx, hasher, type_dependent_defs);
642             ich::hash_stable_itemlocalmap(hcx, hasher, node_types);
643             ich::hash_stable_itemlocalmap(hcx, hasher, node_substs);
644             ich::hash_stable_itemlocalmap(hcx, hasher, adjustments);
645             ich::hash_stable_itemlocalmap(hcx, hasher, pat_binding_modes);
646             ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
647                 let ty::UpvarId {
648                     var_id,
649                     closure_expr_id
650                 } = *up_var_id;
651
652                 let var_def_id = hcx.tcx().hir.local_def_id(var_id);
653                 let closure_def_id = hcx.tcx().hir.local_def_id(closure_expr_id);
654                 (hcx.def_path_hash(var_def_id), hcx.def_path_hash(closure_def_id))
655             });
656
657             ich::hash_stable_itemlocalmap(hcx, hasher, closure_tys);
658             ich::hash_stable_itemlocalmap(hcx, hasher, closure_kinds);
659             ich::hash_stable_itemlocalmap(hcx, hasher, liberated_fn_sigs);
660             ich::hash_stable_itemlocalmap(hcx, hasher, fru_field_types);
661             ich::hash_stable_nodemap(hcx, hasher, cast_kinds);
662
663             ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| {
664                 hcx.def_path_hash(*def_id)
665             });
666
667             tainted_by_errors.hash_stable(hcx, hasher);
668             free_region_map.hash_stable(hcx, hasher);
669         })
670     }
671 }
672
673 impl_stable_hash_for!(enum ty::fast_reject::SimplifiedType {
674     BoolSimplifiedType,
675     CharSimplifiedType,
676     IntSimplifiedType(int_ty),
677     UintSimplifiedType(int_ty),
678     FloatSimplifiedType(float_ty),
679     AdtSimplifiedType(def_id),
680     StrSimplifiedType,
681     ArraySimplifiedType,
682     PtrSimplifiedType,
683     NeverSimplifiedType,
684     TupleSimplifiedType(size),
685     TraitSimplifiedType(def_id),
686     ClosureSimplifiedType(def_id),
687     AnonSimplifiedType(def_id),
688     FunctionSimplifiedType(params),
689     ParameterSimplifiedType
690 });
691
692 impl_stable_hash_for!(struct ty::Instance<'tcx> {
693     def,
694     substs
695 });
696
697 impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::InstanceDef<'gcx> {
698     fn hash_stable<W: StableHasherResult>(&self,
699                                           hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
700                                           hasher: &mut StableHasher<W>) {
701         mem::discriminant(self).hash_stable(hcx, hasher);
702
703         match *self {
704             ty::InstanceDef::Item(def_id) => {
705                 def_id.hash_stable(hcx, hasher);
706             }
707             ty::InstanceDef::Intrinsic(def_id) => {
708                 def_id.hash_stable(hcx, hasher);
709             }
710             ty::InstanceDef::FnPtrShim(def_id, ty) => {
711                 def_id.hash_stable(hcx, hasher);
712                 ty.hash_stable(hcx, hasher);
713             }
714             ty::InstanceDef::Virtual(def_id, n) => {
715                 def_id.hash_stable(hcx, hasher);
716                 n.hash_stable(hcx, hasher);
717             }
718             ty::InstanceDef::ClosureOnceShim { call_once } => {
719                 call_once.hash_stable(hcx, hasher);
720             }
721             ty::InstanceDef::DropGlue(def_id, t) => {
722                 def_id.hash_stable(hcx, hasher);
723                 t.hash_stable(hcx, hasher);
724             }
725         }
726     }
727 }
728