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