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.
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.
11 //! This module contains `HashStable` implementations for various data types
12 //! from rustc::ty in no particular order.
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;
27 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
28 for &'gcx ty::Slice<T>
29 where T: HashStable<StableHashingContext<'a>> {
30 fn hash_stable<W: StableHasherResult>(&self,
31 hcx: &mut StableHashingContext<'a>,
32 hasher: &mut StableHasher<W>) {
34 static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
35 RefCell::new(FxHashMap());
38 let hash = CACHE.with(|cache| {
39 let key = (self.as_ptr() as usize, self.len());
40 if let Some(&hash) = cache.borrow().get(&key) {
44 let mut hasher = StableHasher::new();
45 (&self[..]).hash_stable(hcx, &mut hasher);
47 let hash: Fingerprint = hasher.finish();
48 cache.borrow_mut().insert(key, hash);
52 hash.hash_stable(hcx, hasher);
56 impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::Slice<T>
57 where T: HashStable<StableHashingContext<'a>>
59 type KeyType = Fingerprint;
62 fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
63 let mut hasher = StableHasher::new();
64 let mut hcx: StableHashingContext<'a> = hcx.clone();
65 self.hash_stable(&mut hcx, &mut hasher);
70 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
71 fn hash_stable<W: StableHasherResult>(&self,
72 hcx: &mut StableHashingContext<'a>,
73 hasher: &mut StableHasher<W>) {
74 self.unpack().hash_stable(hcx, hasher);
78 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
79 for ty::subst::UnpackedKind<'gcx> {
80 fn hash_stable<W: StableHasherResult>(&self,
81 hcx: &mut StableHashingContext<'a>,
82 hasher: &mut StableHasher<W>) {
83 mem::discriminant(self).hash_stable(hcx, hasher);
85 ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
86 ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
91 impl<'a> HashStable<StableHashingContext<'a>>
93 fn hash_stable<W: StableHasherResult>(&self,
94 hcx: &mut StableHashingContext<'a>,
95 hasher: &mut StableHasher<W>) {
96 mem::discriminant(self).hash_stable(hcx, hasher);
101 // No variant fields to hash for these ...
103 ty::ReCanonical(c) => {
104 c.hash_stable(hcx, hasher);
106 ty::ReLateBound(db, ty::BrAnon(i)) => {
107 db.hash_stable(hcx, hasher);
108 i.hash_stable(hcx, hasher);
110 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
111 db.hash_stable(hcx, hasher);
112 def_id.hash_stable(hcx, hasher);
113 name.hash_stable(hcx, hasher);
115 ty::ReLateBound(db, ty::BrEnv) => {
116 db.hash_stable(hcx, hasher);
118 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
119 def_id.hash_stable(hcx, hasher);
120 index.hash_stable(hcx, hasher);
121 name.hash_stable(hcx, hasher);
123 ty::ReScope(scope) => {
124 scope.hash_stable(hcx, hasher);
126 ty::ReFree(ref free_region) => {
127 free_region.hash_stable(hcx, hasher);
129 ty::ReClosureBound(vid) => {
130 vid.hash_stable(hcx, hasher);
132 ty::ReLateBound(..) |
134 ty::ReSkolemized(..) => {
135 bug!("StableHasher: unexpected region {:?}", *self)
141 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
143 fn hash_stable<W: StableHasherResult>(&self,
144 hcx: &mut StableHashingContext<'a>,
145 hasher: &mut StableHasher<W>) {
146 use rustc_data_structures::indexed_vec::Idx;
147 self.index().hash_stable(hcx, hasher);
151 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::CanonicalVar {
153 fn hash_stable<W: StableHasherResult>(&self,
154 hcx: &mut StableHashingContext<'gcx>,
155 hasher: &mut StableHasher<W>) {
156 use rustc_data_structures::indexed_vec::Idx;
157 self.index().hash_stable(hcx, hasher);
161 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
162 for ty::adjustment::AutoBorrow<'gcx> {
163 fn hash_stable<W: StableHasherResult>(&self,
164 hcx: &mut StableHashingContext<'a>,
165 hasher: &mut StableHasher<W>) {
166 mem::discriminant(self).hash_stable(hcx, hasher);
168 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
169 region.hash_stable(hcx, hasher);
170 mutability.hash_stable(hcx, hasher);
172 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
173 mutability.hash_stable(hcx, hasher);
179 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
180 for ty::adjustment::Adjust<'gcx> {
181 fn hash_stable<W: StableHasherResult>(&self,
182 hcx: &mut StableHashingContext<'a>,
183 hasher: &mut StableHasher<W>) {
184 mem::discriminant(self).hash_stable(hcx, hasher);
186 ty::adjustment::Adjust::NeverToAny |
187 ty::adjustment::Adjust::ReifyFnPointer |
188 ty::adjustment::Adjust::UnsafeFnPointer |
189 ty::adjustment::Adjust::ClosureFnPointer |
190 ty::adjustment::Adjust::MutToConstPointer |
191 ty::adjustment::Adjust::Unsize => {}
192 ty::adjustment::Adjust::Deref(ref overloaded) => {
193 overloaded.hash_stable(hcx, hasher);
195 ty::adjustment::Adjust::Borrow(ref autoref) => {
196 autoref.hash_stable(hcx, hasher);
202 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
203 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
204 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
205 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
210 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
211 fn hash_stable<W: StableHasherResult>(&self,
212 hcx: &mut StableHashingContext<'gcx>,
213 hasher: &mut StableHasher<W>) {
214 mem::discriminant(self).hash_stable(hcx, hasher);
216 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
217 allow_two_phase_borrow.hash_stable(hcx, hasher);
219 ty::adjustment::AutoBorrowMutability::Immutable => {}
224 impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
226 impl_stable_hash_for!(enum ty::BorrowKind {
232 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
233 for ty::UpvarCapture<'gcx> {
234 fn hash_stable<W: StableHasherResult>(&self,
235 hcx: &mut StableHashingContext<'a>,
236 hasher: &mut StableHasher<W>) {
237 mem::discriminant(self).hash_stable(hcx, hasher);
239 ty::UpvarCapture::ByValue => {}
240 ty::UpvarCapture::ByRef(ref up_var_borrow) => {
241 up_var_borrow.hash_stable(hcx, hasher);
247 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
252 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
259 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
260 where T: HashStable<StableHashingContext<'a>>
262 fn hash_stable<W: StableHasherResult>(&self,
263 hcx: &mut StableHashingContext<'a>,
264 hasher: &mut StableHasher<W>) {
265 self.skip_binder().hash_stable(hcx, hasher);
269 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
271 impl_stable_hash_for!(enum ty::Visibility {
277 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
278 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
279 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
281 impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
282 for ty::OutlivesPredicate<A, B>
283 where A: HashStable<StableHashingContext<'a>>,
284 B: HashStable<StableHashingContext<'a>>,
286 fn hash_stable<W: StableHasherResult>(&self,
287 hcx: &mut StableHashingContext<'a>,
288 hasher: &mut StableHasher<W>) {
289 let ty::OutlivesPredicate(ref a, ref b) = *self;
290 a.hash_stable(hcx, hasher);
291 b.hash_stable(hcx, hasher);
295 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
296 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
299 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
300 fn hash_stable<W: StableHasherResult>(&self,
301 hcx: &mut StableHashingContext<'a>,
302 hasher: &mut StableHasher<W>) {
303 mem::discriminant(self).hash_stable(hcx, hasher);
305 ty::Predicate::Trait(ref pred) => {
306 pred.hash_stable(hcx, hasher);
308 ty::Predicate::Subtype(ref pred) => {
309 pred.hash_stable(hcx, hasher);
311 ty::Predicate::RegionOutlives(ref pred) => {
312 pred.hash_stable(hcx, hasher);
314 ty::Predicate::TypeOutlives(ref pred) => {
315 pred.hash_stable(hcx, hasher);
317 ty::Predicate::Projection(ref pred) => {
318 pred.hash_stable(hcx, hasher);
320 ty::Predicate::WellFormed(ty) => {
321 ty.hash_stable(hcx, hasher);
323 ty::Predicate::ObjectSafe(def_id) => {
324 def_id.hash_stable(hcx, hasher);
326 ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
327 def_id.hash_stable(hcx, hasher);
328 closure_substs.hash_stable(hcx, hasher);
329 closure_kind.hash_stable(hcx, hasher);
331 ty::Predicate::ConstEvaluatable(def_id, substs) => {
332 def_id.hash_stable(hcx, hasher);
333 substs.hash_stable(hcx, hasher);
339 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
340 fn hash_stable<W: StableHasherResult>(&self,
341 _: &mut StableHashingContext<'a>,
342 hasher: &mut StableHasher<W>) {
343 std_hash::Hash::hash(self, hasher);
347 impl_stable_hash_for!(struct ty::VariantDef {
355 impl_stable_hash_for!(enum ty::VariantDiscr {
360 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
361 fn hash_stable<W: StableHasherResult>(&self,
362 hcx: &mut StableHashingContext<'a>,
363 hasher: &mut StableHasher<W>) {
364 let ty::FieldDef { did, ident, vis } = *self;
366 did.hash_stable(hcx, hasher);
367 ident.name.hash_stable(hcx, hasher);
368 vis.hash_stable(hcx, hasher);
372 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
373 for ::middle::const_val::ConstVal<'gcx> {
374 fn hash_stable<W: StableHasherResult>(&self,
375 hcx: &mut StableHashingContext<'a>,
376 hasher: &mut StableHasher<W>) {
377 use middle::const_val::ConstVal::*;
379 mem::discriminant(self).hash_stable(hcx, hasher);
382 Unevaluated(def_id, substs) => {
383 def_id.hash_stable(hcx, hasher);
384 substs.hash_stable(hcx, hasher);
386 Value(ref value) => {
387 value.hash_stable(hcx, hasher);
393 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
394 for ::mir::interpret::ConstValue<'gcx> {
395 fn hash_stable<W: StableHasherResult>(&self,
396 hcx: &mut StableHashingContext<'a>,
397 hasher: &mut StableHasher<W>) {
398 use mir::interpret::ConstValue::*;
400 mem::discriminant(self).hash_stable(hcx, hasher);
404 val.hash_stable(hcx, hasher);
406 ScalarPair(a, b) => {
407 a.hash_stable(hcx, hasher);
408 b.hash_stable(hcx, hasher);
410 ByRef(alloc, offset) => {
411 alloc.hash_stable(hcx, hasher);
412 offset.hash_stable(hcx, hasher);
418 impl_stable_hash_for!(enum mir::interpret::Value {
424 impl_stable_hash_for!(struct mir::interpret::Pointer {
429 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
430 fn hash_stable<W: StableHasherResult>(
432 hcx: &mut StableHashingContext<'a>,
433 hasher: &mut StableHasher<W>,
435 ty::tls::with_opt(|tcx| {
436 trace!("hashing {:?}", *self);
437 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
438 let alloc_kind = tcx.alloc_map.lock().get(*self).expect("no value for AllocId");
439 alloc_kind.hash_stable(hcx, hasher);
444 impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
445 for mir::interpret::AllocType<'gcx, M> {
446 fn hash_stable<W: StableHasherResult>(&self,
447 hcx: &mut StableHashingContext<'a>,
448 hasher: &mut StableHasher<W>) {
449 use mir::interpret::AllocType::*;
451 mem::discriminant(self).hash_stable(hcx, hasher);
454 Function(instance) => instance.hash_stable(hcx, hasher),
455 Static(def_id) => def_id.hash_stable(hcx, hasher),
456 Memory(ref mem) => mem.hash_stable(hcx, hasher),
461 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
462 fn hash_stable<W: StableHasherResult>(
464 hcx: &mut StableHashingContext<'a>,
465 hasher: &mut StableHasher<W>,
467 self.bytes.hash_stable(hcx, hasher);
468 for reloc in self.relocations.iter() {
469 reloc.hash_stable(hcx, hasher);
471 self.undef_mask.hash_stable(hcx, hasher);
472 self.align.hash_stable(hcx, hasher);
473 self.runtime_mutability.hash_stable(hcx, hasher);
477 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
483 impl<'a> HashStable<StableHashingContext<'a>>
484 for ::mir::interpret::Scalar {
485 fn hash_stable<W: StableHasherResult>(&self,
486 hcx: &mut StableHashingContext<'a>,
487 hasher: &mut StableHasher<W>) {
488 use mir::interpret::Scalar::*;
490 mem::discriminant(self).hash_stable(hcx, hasher);
492 Bits { bits, defined } => {
493 bits.hash_stable(hcx, hasher);
494 defined.hash_stable(hcx, hasher);
496 Ptr(ptr) => ptr.hash_stable(hcx, hasher),
501 impl_stable_hash_for!(struct ty::Const<'tcx> {
506 impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
511 impl_stable_hash_for!(struct ::middle::const_val::FrameInfo {
517 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
518 for ::middle::const_val::ErrKind<'gcx> {
519 fn hash_stable<W: StableHasherResult>(&self,
520 hcx: &mut StableHashingContext<'a>,
521 hasher: &mut StableHasher<W>) {
522 use middle::const_val::ErrKind::*;
524 mem::discriminant(self).hash_stable(hcx, hasher);
532 Miri(ref err, ref trace) => {
533 err.hash_stable(hcx, hasher);
534 trace.hash_stable(hcx, hasher);
540 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
541 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
543 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
549 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
550 for ::mir::interpret::EvalError<'gcx> {
551 fn hash_stable<W: StableHasherResult>(&self,
552 hcx: &mut StableHashingContext<'a>,
553 hasher: &mut StableHasher<W>) {
554 self.kind.hash_stable(hcx, hasher)
558 impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
559 for ::mir::interpret::EvalErrorKind<'gcx, O> {
560 fn hash_stable<W: StableHasherResult>(&self,
561 hcx: &mut StableHashingContext<'a>,
562 hasher: &mut StableHasher<W>) {
563 use mir::interpret::EvalErrorKind::*;
565 mem::discriminant(&self).hash_stable(hcx, hasher);
568 DanglingPointerDeref |
570 InvalidMemoryAccess |
571 InvalidFunctionPointer |
573 InvalidDiscriminant |
574 InvalidNullPointerUsage |
580 StackFrameLimitReached |
583 CalledClosureAsFunction |
584 VtableForArgumentlessMethod |
585 ModifiedConstantMemory |
588 ReallocateNonBasePtr |
589 DeallocateNonBasePtr |
593 ReadFromReturnPointer |
594 UnimplementedTraitSelection |
596 DerefFunctionPointer |
601 GeneratorResumedAfterReturn |
602 GeneratorResumedAfterPanic => {}
603 ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
604 MachineError(ref err) => err.hash_stable(hcx, hasher),
605 FunctionPointerTyMismatch(a, b) => {
606 a.hash_stable(hcx, hasher);
607 b.hash_stable(hcx, hasher)
609 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
610 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
616 ptr.hash_stable(hcx, hasher);
617 access.hash_stable(hcx, hasher);
618 allocation_size.hash_stable(hcx, hasher)
620 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
621 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
622 BoundsCheck { ref len, ref index } => {
623 len.hash_stable(hcx, hasher);
624 index.hash_stable(hcx, hasher)
626 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
627 InvalidChar(c) => c.hash_stable(hcx, hasher),
628 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
629 AlignmentCheckFailed {
633 required.hash_stable(hcx, hasher);
634 has.hash_stable(hcx, hasher)
636 MemoryLockViolation {
643 ptr.hash_stable(hcx, hasher);
644 len.hash_stable(hcx, hasher);
645 frame.hash_stable(hcx, hasher);
646 access.hash_stable(hcx, hasher);
647 lock.hash_stable(hcx, hasher)
649 MemoryAcquireConflict {
655 ptr.hash_stable(hcx, hasher);
656 len.hash_stable(hcx, hasher);
657 kind.hash_stable(hcx, hasher);
658 lock.hash_stable(hcx, hasher)
660 InvalidMemoryLockRelease {
666 ptr.hash_stable(hcx, hasher);
667 len.hash_stable(hcx, hasher);
668 frame.hash_stable(hcx, hasher);
669 lock.hash_stable(hcx, hasher)
671 DeallocatedLockedMemory {
675 ptr.hash_stable(hcx, hasher);
676 lock.hash_stable(hcx, hasher)
678 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
679 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
680 ReallocatedWrongMemoryKind(ref a, ref b) => {
681 a.hash_stable(hcx, hasher);
682 b.hash_stable(hcx, hasher)
684 DeallocatedWrongMemoryKind(ref a, ref b) => {
685 a.hash_stable(hcx, hasher);
686 b.hash_stable(hcx, hasher)
688 IncorrectAllocationInformation(a, b, c, d) => {
689 a.hash_stable(hcx, hasher);
690 b.hash_stable(hcx, hasher);
691 c.hash_stable(hcx, hasher);
692 d.hash_stable(hcx, hasher)
694 Layout(lay) => lay.hash_stable(hcx, hasher),
695 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
696 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
697 Overflow(op) => op.hash_stable(hcx, hasher),
702 impl_stable_hash_for!(enum mir::interpret::Lock {
708 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
713 impl_stable_hash_for!(enum mir::interpret::AccessKind {
718 impl_stable_hash_for!(enum ty::Variance {
725 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
729 impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
730 fn hash_stable<W: StableHasherResult>(&self,
731 hcx: &mut StableHashingContext<'a>,
732 hasher: &mut StableHasher<W>) {
738 // Reverse map to each param's `index` field, from its `def_id`.
739 param_def_id_to_index: _, // Don't hash this
741 has_late_bound_regions,
744 parent.hash_stable(hcx, hasher);
745 parent_count.hash_stable(hcx, hasher);
746 params.hash_stable(hcx, hasher);
747 has_self.hash_stable(hcx, hasher);
748 has_late_bound_regions.hash_stable(hcx, hasher);
752 impl_stable_hash_for!(struct ty::GenericParamDef {
760 impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
761 fn hash_stable<W: StableHasherResult>(&self,
762 hcx: &mut StableHashingContext<'a>,
763 hasher: &mut StableHasher<W>) {
764 mem::discriminant(self).hash_stable(hcx, hasher);
766 ty::GenericParamDefKind::Lifetime => {}
767 ty::GenericParamDefKind::Type {
769 ref object_lifetime_default,
772 has_default.hash_stable(hcx, hasher);
773 object_lifetime_default.hash_stable(hcx, hasher);
774 synthetic.hash_stable(hcx, hasher);
780 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
781 for ::middle::resolve_lifetime::Set1<T>
782 where T: HashStable<StableHashingContext<'a>>
784 fn hash_stable<W: StableHasherResult>(&self,
785 hcx: &mut StableHashingContext<'a>,
786 hasher: &mut StableHasher<W>) {
787 use middle::resolve_lifetime::Set1;
789 mem::discriminant(self).hash_stable(hcx, hasher);
795 Set1::One(ref value) => {
796 value.hash_stable(hcx, hasher);
802 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
807 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
809 EarlyBound(index, decl, is_in_band),
810 LateBound(db_index, decl, is_in_band),
811 LateBoundAnon(db_index, anon_index),
812 Free(call_site_scope_data, decl)
815 impl_stable_hash_for!(enum ty::cast::CastKind {
829 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
830 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
832 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
833 type KeyType = region::Scope;
836 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
841 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
843 first_statement_index
846 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
850 impl_stable_hash_for!(struct ty::FreeRegion {
855 impl_stable_hash_for!(enum ty::BoundRegion {
857 BrNamed(def_id, name),
862 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
863 for ty::TypeVariants<'gcx>
865 fn hash_stable<W: StableHasherResult>(&self,
866 hcx: &mut StableHashingContext<'a>,
867 hasher: &mut StableHasher<W>) {
868 use ty::TypeVariants::*;
870 mem::discriminant(self).hash_stable(hcx, hasher);
877 // Nothing more to hash.
880 int_ty.hash_stable(hcx, hasher);
883 uint_ty.hash_stable(hcx, hasher);
885 TyFloat(float_ty) => {
886 float_ty.hash_stable(hcx, hasher);
888 TyAdt(adt_def, substs) => {
889 adt_def.hash_stable(hcx, hasher);
890 substs.hash_stable(hcx, hasher);
892 TyArray(inner_ty, len) => {
893 inner_ty.hash_stable(hcx, hasher);
894 len.hash_stable(hcx, hasher);
896 TySlice(inner_ty) => {
897 inner_ty.hash_stable(hcx, hasher);
899 TyRawPtr(pointee_ty) => {
900 pointee_ty.hash_stable(hcx, hasher);
902 TyRef(region, pointee_ty, mutbl) => {
903 region.hash_stable(hcx, hasher);
904 pointee_ty.hash_stable(hcx, hasher);
905 mutbl.hash_stable(hcx, hasher);
907 TyFnDef(def_id, substs) => {
908 def_id.hash_stable(hcx, hasher);
909 substs.hash_stable(hcx, hasher);
911 TyFnPtr(ref sig) => {
912 sig.hash_stable(hcx, hasher);
914 TyDynamic(ref existential_predicates, region) => {
915 existential_predicates.hash_stable(hcx, hasher);
916 region.hash_stable(hcx, hasher);
918 TyClosure(def_id, closure_substs) => {
919 def_id.hash_stable(hcx, hasher);
920 closure_substs.hash_stable(hcx, hasher);
922 TyGenerator(def_id, generator_substs, movability) => {
923 def_id.hash_stable(hcx, hasher);
924 generator_substs.hash_stable(hcx, hasher);
925 movability.hash_stable(hcx, hasher);
927 TyGeneratorWitness(types) => {
928 types.hash_stable(hcx, hasher)
930 TyTuple(inner_tys) => {
931 inner_tys.hash_stable(hcx, hasher);
933 TyProjection(ref projection_ty) => {
934 projection_ty.hash_stable(hcx, hasher);
936 TyAnon(def_id, substs) => {
937 def_id.hash_stable(hcx, hasher);
938 substs.hash_stable(hcx, hasher);
940 TyParam(param_ty) => {
941 param_ty.hash_stable(hcx, hasher);
943 TyForeign(def_id) => {
944 def_id.hash_stable(hcx, hasher);
946 TyInfer(infer_ty) => {
947 infer_ty.hash_stable(hcx, hasher);
953 impl_stable_hash_for!(enum ty::InferTy {
963 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
966 fn hash_stable<W: StableHasherResult>(&self,
967 _hcx: &mut StableHashingContext<'a>,
968 _hasher: &mut StableHasher<W>) {
969 // TyVid values are confined to an inference context and hence
970 // should not be hashed.
971 bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
975 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
978 fn hash_stable<W: StableHasherResult>(&self,
979 _hcx: &mut StableHashingContext<'a>,
980 _hasher: &mut StableHasher<W>) {
981 // IntVid values are confined to an inference context and hence
982 // should not be hashed.
983 bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
987 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
990 fn hash_stable<W: StableHasherResult>(&self,
991 _hcx: &mut StableHashingContext<'a>,
992 _hasher: &mut StableHasher<W>) {
993 // FloatVid values are confined to an inference context and hence
994 // should not be hashed.
995 bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
999 impl_stable_hash_for!(struct ty::ParamTy {
1004 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
1009 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
1010 for ty::ExistentialPredicate<'gcx>
1012 fn hash_stable<W: StableHasherResult>(&self,
1013 hcx: &mut StableHashingContext<'a>,
1014 hasher: &mut StableHasher<W>) {
1015 mem::discriminant(self).hash_stable(hcx, hasher);
1017 ty::ExistentialPredicate::Trait(ref trait_ref) => {
1018 trait_ref.hash_stable(hcx, hasher);
1020 ty::ExistentialPredicate::Projection(ref projection) => {
1021 projection.hash_stable(hcx, hasher);
1023 ty::ExistentialPredicate::AutoTrait(def_id) => {
1024 def_id.hash_stable(hcx, hasher);
1030 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
1035 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
1041 impl_stable_hash_for!(struct ty::Instance<'tcx> {
1046 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
1047 fn hash_stable<W: StableHasherResult>(&self,
1048 hcx: &mut StableHashingContext<'a>,
1049 hasher: &mut StableHasher<W>) {
1050 mem::discriminant(self).hash_stable(hcx, hasher);
1053 ty::InstanceDef::Item(def_id) => {
1054 def_id.hash_stable(hcx, hasher);
1056 ty::InstanceDef::Intrinsic(def_id) => {
1057 def_id.hash_stable(hcx, hasher);
1059 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1060 def_id.hash_stable(hcx, hasher);
1061 ty.hash_stable(hcx, hasher);
1063 ty::InstanceDef::Virtual(def_id, n) => {
1064 def_id.hash_stable(hcx, hasher);
1065 n.hash_stable(hcx, hasher);
1067 ty::InstanceDef::ClosureOnceShim { call_once } => {
1068 call_once.hash_stable(hcx, hasher);
1070 ty::InstanceDef::DropGlue(def_id, ty) => {
1071 def_id.hash_stable(hcx, hasher);
1072 ty.hash_stable(hcx, hasher);
1074 ty::InstanceDef::CloneShim(def_id, ty) => {
1075 def_id.hash_stable(hcx, hasher);
1076 ty.hash_stable(hcx, hasher);
1082 impl<'a> HashStable<StableHashingContext<'a>> for ty::TraitDef {
1083 fn hash_stable<W: StableHasherResult>(&self,
1084 hcx: &mut StableHashingContext<'a>,
1085 hasher: &mut StableHasher<W>) {
1087 // We already have the def_path_hash below, no need to hash it twice
1095 unsafety.hash_stable(hcx, hasher);
1096 paren_sugar.hash_stable(hcx, hasher);
1097 has_auto_impl.hash_stable(hcx, hasher);
1098 def_path_hash.hash_stable(hcx, hasher);
1102 impl_stable_hash_for!(struct ty::Destructor {
1106 impl<'a> HashStable<StableHashingContext<'a>> for ty::CrateVariancesMap {
1107 fn hash_stable<W: StableHasherResult>(&self,
1108 hcx: &mut StableHashingContext<'a>,
1109 hasher: &mut StableHasher<W>) {
1110 let ty::CrateVariancesMap {
1112 // This is just an irrelevant helper value.
1116 variances.hash_stable(hcx, hasher);
1120 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'gcx> {
1121 fn hash_stable<W: StableHasherResult>(&self,
1122 hcx: &mut StableHashingContext<'a>,
1123 hasher: &mut StableHasher<W>) {
1124 let ty::CratePredicatesMap {
1126 // This is just an irrelevant helper value.
1130 predicates.hash_stable(hcx, hasher);
1134 impl_stable_hash_for!(struct ty::AssociatedItem {
1141 method_has_self_argument
1144 impl_stable_hash_for!(enum ty::AssociatedKind {
1150 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1151 TraitContainer(def_id),
1152 ImplContainer(def_id)
1156 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1157 for ty::steal::Steal<T>
1158 where T: HashStable<StableHashingContext<'a>>
1160 fn hash_stable<W: StableHasherResult>(&self,
1161 hcx: &mut StableHashingContext<'a>,
1162 hasher: &mut StableHasher<W>) {
1163 self.borrow().hash_stable(hcx, hasher);
1167 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1172 impl_stable_hash_for!(enum traits::Reveal {
1177 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1183 impl<'a> HashStable<StableHashingContext<'a>>
1184 for ::middle::privacy::AccessLevels {
1185 fn hash_stable<W: StableHasherResult>(&self,
1186 hcx: &mut StableHashingContext<'a>,
1187 hasher: &mut StableHasher<W>) {
1188 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1189 let ::middle::privacy::AccessLevels {
1193 map.hash_stable(hcx, hasher);
1198 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1202 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1204 Errored(error_reported)
1207 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1209 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1213 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1214 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1215 fn hash_stable<W: StableHasherResult>(&self,
1216 hcx: &mut StableHashingContext<'a>,
1217 hasher: &mut StableHasher<W>) {
1218 use traits::Vtable::*;
1220 mem::discriminant(self).hash_stable(hcx, hasher);
1223 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1224 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1225 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1226 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1227 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1228 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1229 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1230 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1235 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1236 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1237 fn hash_stable<W: StableHasherResult>(&self,
1238 hcx: &mut StableHashingContext<'a>,
1239 hasher: &mut StableHasher<W>) {
1240 let traits::VtableImplData {
1245 impl_def_id.hash_stable(hcx, hasher);
1246 substs.hash_stable(hcx, hasher);
1247 nested.hash_stable(hcx, hasher);
1251 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1252 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1253 fn hash_stable<W: StableHasherResult>(&self,
1254 hcx: &mut StableHashingContext<'a>,
1255 hasher: &mut StableHasher<W>) {
1256 let traits::VtableAutoImplData {
1260 trait_def_id.hash_stable(hcx, hasher);
1261 nested.hash_stable(hcx, hasher);
1265 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1266 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1267 fn hash_stable<W: StableHasherResult>(&self,
1268 hcx: &mut StableHashingContext<'a>,
1269 hasher: &mut StableHasher<W>) {
1270 let traits::VtableObjectData {
1275 upcast_trait_ref.hash_stable(hcx, hasher);
1276 vtable_base.hash_stable(hcx, hasher);
1277 nested.hash_stable(hcx, hasher);
1281 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1282 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1283 fn hash_stable<W: StableHasherResult>(&self,
1284 hcx: &mut StableHashingContext<'a>,
1285 hasher: &mut StableHasher<W>) {
1286 let traits::VtableBuiltinData {
1289 nested.hash_stable(hcx, hasher);
1293 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1294 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1295 fn hash_stable<W: StableHasherResult>(&self,
1296 hcx: &mut StableHashingContext<'a>,
1297 hasher: &mut StableHasher<W>) {
1298 let traits::VtableClosureData {
1303 closure_def_id.hash_stable(hcx, hasher);
1304 substs.hash_stable(hcx, hasher);
1305 nested.hash_stable(hcx, hasher);
1309 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1310 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1311 fn hash_stable<W: StableHasherResult>(&self,
1312 hcx: &mut StableHashingContext<'a>,
1313 hasher: &mut StableHasher<W>) {
1314 let traits::VtableFnPointerData {
1318 fn_ty.hash_stable(hcx, hasher);
1319 nested.hash_stable(hcx, hasher);
1323 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1324 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1325 fn hash_stable<W: StableHasherResult>(&self,
1326 hcx: &mut StableHashingContext<'a>,
1327 hasher: &mut StableHasher<W>) {
1328 let traits::VtableGeneratorData {
1333 generator_def_id.hash_stable(hcx, hasher);
1334 substs.hash_stable(hcx, hasher);
1335 nested.hash_stable(hcx, hasher);
1339 impl_stable_hash_for!(
1340 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1345 impl_stable_hash_for!(
1346 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1351 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1355 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1360 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1366 impl_stable_hash_for!(
1367 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1368 var_values, region_constraints, certainty, value
1372 impl_stable_hash_for!(enum infer::canonical::Certainty {
1376 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClauseAtom<'tcx> {
1377 fn hash_stable<W: StableHasherResult>(&self,
1378 hcx: &mut StableHashingContext<'a>,
1379 hasher: &mut StableHasher<W>) {
1380 use traits::WhereClauseAtom::*;
1382 mem::discriminant(self).hash_stable(hcx, hasher);
1384 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1385 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1390 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1391 fn hash_stable<W: StableHasherResult>(&self,
1392 hcx: &mut StableHashingContext<'a>,
1393 hasher: &mut StableHasher<W>) {
1394 use traits::DomainGoal::*;
1396 mem::discriminant(self).hash_stable(hcx, hasher);
1398 Holds(where_clause) |
1399 WellFormed(where_clause) |
1400 FromEnv(where_clause) => where_clause.hash_stable(hcx, hasher),
1402 WellFormedTy(ty) => ty.hash_stable(hcx, hasher),
1403 Normalize(projection) => projection.hash_stable(hcx, hasher),
1404 FromEnvTy(ty) => ty.hash_stable(hcx, hasher),
1405 RegionOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1406 TypeOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1411 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1412 fn hash_stable<W: StableHasherResult>(&self,
1413 hcx: &mut StableHashingContext<'a>,
1414 hasher: &mut StableHasher<W>) {
1415 use traits::Goal::*;
1417 mem::discriminant(self).hash_stable(hcx, hasher);
1419 Implies(hypotheses, goal) => {
1420 hypotheses.hash_stable(hcx, hasher);
1421 goal.hash_stable(hcx, hasher);
1423 And(goal1, goal2) => {
1424 goal1.hash_stable(hcx, hasher);
1425 goal2.hash_stable(hcx, hasher);
1427 Not(goal) => goal.hash_stable(hcx, hasher),
1428 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1429 Quantified(quantifier, goal) => {
1430 quantifier.hash_stable(hcx, hasher);
1431 goal.hash_stable(hcx, hasher);
1438 impl_stable_hash_for!(
1439 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1444 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1445 fn hash_stable<W: StableHasherResult>(&self,
1446 hcx: &mut StableHashingContext<'a>,
1447 hasher: &mut StableHasher<W>) {
1448 use traits::Clause::*;
1450 mem::discriminant(self).hash_stable(hcx, hasher);
1452 Implies(clause) => clause.hash_stable(hcx, hasher),
1453 ForAll(clause) => clause.hash_stable(hcx, hasher),
1458 impl_stable_hash_for!(enum traits::QuantifierKind {