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.depth.hash_stable(hcx, hasher);
108 i.hash_stable(hcx, hasher);
110 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
111 db.depth.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.depth.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!("TypeIdHasher: 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_stable_hash_for!(struct ty::FieldDef {
366 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
367 for ::middle::const_val::ConstVal<'gcx> {
368 fn hash_stable<W: StableHasherResult>(&self,
369 hcx: &mut StableHashingContext<'a>,
370 hasher: &mut StableHasher<W>) {
371 use middle::const_val::ConstVal::*;
373 mem::discriminant(self).hash_stable(hcx, hasher);
376 Unevaluated(def_id, substs) => {
377 def_id.hash_stable(hcx, hasher);
378 substs.hash_stable(hcx, hasher);
380 Value(ref value) => {
381 value.hash_stable(hcx, hasher);
387 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
388 for ::mir::interpret::ConstValue<'gcx> {
389 fn hash_stable<W: StableHasherResult>(&self,
390 hcx: &mut StableHashingContext<'a>,
391 hasher: &mut StableHasher<W>) {
392 use mir::interpret::ConstValue::*;
394 mem::discriminant(self).hash_stable(hcx, hasher);
398 val.hash_stable(hcx, hasher);
401 a.hash_stable(hcx, hasher);
402 b.hash_stable(hcx, hasher);
405 alloc.hash_stable(hcx, hasher);
411 impl_stable_hash_for!(enum mir::interpret::Value {
417 impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
422 enum AllocDiscriminant {
427 impl_stable_hash_for!(enum self::AllocDiscriminant {
433 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
434 fn hash_stable<W: StableHasherResult>(
436 hcx: &mut StableHashingContext<'a>,
437 hasher: &mut StableHasher<W>,
439 ty::tls::with_opt(|tcx| {
440 trace!("hashing {:?}", *self);
441 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
442 if let Some(def_id) = tcx.interpret_interner.get_static(*self) {
443 AllocDiscriminant::Static.hash_stable(hcx, hasher);
444 trace!("hashing {:?} as static {:?}", *self, def_id);
445 def_id.hash_stable(hcx, hasher);
446 } else if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
447 AllocDiscriminant::Alloc.hash_stable(hcx, hasher);
448 if hcx.alloc_id_recursion_tracker.insert(*self) {
449 trace!("hashing {:?} as alloc {:#?}", *self, alloc);
450 alloc.hash_stable(hcx, hasher);
451 assert!(hcx.alloc_id_recursion_tracker.remove(self));
453 trace!("skipping hashing of {:?} due to recursion", *self);
455 } else if let Some(inst) = tcx.interpret_interner.get_fn(*self) {
456 trace!("hashing {:?} as fn {:#?}", *self, inst);
457 AllocDiscriminant::Function.hash_stable(hcx, hasher);
458 inst.hash_stable(hcx, hasher);
460 bug!("no allocation for {}", self);
466 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
467 fn hash_stable<W: StableHasherResult>(
469 hcx: &mut StableHashingContext<'a>,
470 hasher: &mut StableHasher<W>,
472 self.bytes.hash_stable(hcx, hasher);
473 for reloc in self.relocations.iter() {
474 reloc.hash_stable(hcx, hasher);
476 self.undef_mask.hash_stable(hcx, hasher);
477 self.align.hash_stable(hcx, hasher);
478 self.runtime_mutability.hash_stable(hcx, hasher);
482 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
487 impl_stable_hash_for!(struct mir::interpret::Pointer{primval});
489 impl_stable_hash_for!(enum mir::interpret::PrimVal {
495 impl_stable_hash_for!(struct ty::Const<'tcx> {
500 impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
505 impl_stable_hash_for!(struct ::middle::const_val::FrameInfo {
510 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
511 for ::middle::const_val::ErrKind<'gcx> {
512 fn hash_stable<W: StableHasherResult>(&self,
513 hcx: &mut StableHashingContext<'a>,
514 hasher: &mut StableHasher<W>) {
515 use middle::const_val::ErrKind::*;
517 mem::discriminant(self).hash_stable(hcx, hasher);
525 UnimplementedConstVal(s) => {
526 s.hash_stable(hcx, hasher);
528 IndexOutOfBounds { len, index } => {
529 len.hash_stable(hcx, hasher);
530 index.hash_stable(hcx, hasher);
532 LayoutError(ref layout_error) => {
533 layout_error.hash_stable(hcx, hasher);
535 Miri(ref err, ref trace) => {
536 err.hash_stable(hcx, hasher);
537 trace.hash_stable(hcx, hasher);
543 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
544 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
546 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
552 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
553 for ::mir::interpret::EvalError<'gcx> {
554 fn hash_stable<W: StableHasherResult>(&self,
555 hcx: &mut StableHashingContext<'a>,
556 hasher: &mut StableHasher<W>) {
557 self.kind.hash_stable(hcx, hasher)
561 impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
562 for ::mir::interpret::EvalErrorKind<'gcx, O> {
563 fn hash_stable<W: StableHasherResult>(&self,
564 hcx: &mut StableHashingContext<'a>,
565 hasher: &mut StableHasher<W>) {
566 use mir::interpret::EvalErrorKind::*;
568 mem::discriminant(&self).hash_stable(hcx, hasher);
571 DanglingPointerDeref |
573 InvalidMemoryAccess |
574 InvalidFunctionPointer |
576 InvalidDiscriminant |
577 InvalidNullPointerUsage |
583 StackFrameLimitReached |
586 CalledClosureAsFunction |
587 VtableForArgumentlessMethod |
588 ModifiedConstantMemory |
591 ReallocateNonBasePtr |
592 DeallocateNonBasePtr |
596 ReadFromReturnPointer |
597 UnimplementedTraitSelection |
599 DerefFunctionPointer |
604 GeneratorResumedAfterReturn |
605 GeneratorResumedAfterPanic |
606 ReferencedConstant => {}
607 MachineError(ref err) => err.hash_stable(hcx, hasher),
608 FunctionPointerTyMismatch(a, b) => {
609 a.hash_stable(hcx, hasher);
610 b.hash_stable(hcx, hasher)
612 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
613 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
619 ptr.hash_stable(hcx, hasher);
620 access.hash_stable(hcx, hasher);
621 allocation_size.hash_stable(hcx, hasher)
623 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
624 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
625 BoundsCheck { ref len, ref index } => {
626 len.hash_stable(hcx, hasher);
627 index.hash_stable(hcx, hasher)
629 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
630 InvalidChar(c) => c.hash_stable(hcx, hasher),
631 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
632 AlignmentCheckFailed {
636 required.hash_stable(hcx, hasher);
637 has.hash_stable(hcx, hasher)
639 MemoryLockViolation {
646 ptr.hash_stable(hcx, hasher);
647 len.hash_stable(hcx, hasher);
648 frame.hash_stable(hcx, hasher);
649 access.hash_stable(hcx, hasher);
650 lock.hash_stable(hcx, hasher)
652 MemoryAcquireConflict {
658 ptr.hash_stable(hcx, hasher);
659 len.hash_stable(hcx, hasher);
660 kind.hash_stable(hcx, hasher);
661 lock.hash_stable(hcx, hasher)
663 InvalidMemoryLockRelease {
669 ptr.hash_stable(hcx, hasher);
670 len.hash_stable(hcx, hasher);
671 frame.hash_stable(hcx, hasher);
672 lock.hash_stable(hcx, hasher)
674 DeallocatedLockedMemory {
678 ptr.hash_stable(hcx, hasher);
679 lock.hash_stable(hcx, hasher)
681 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
682 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
683 ReallocatedWrongMemoryKind(ref a, ref b) => {
684 a.hash_stable(hcx, hasher);
685 b.hash_stable(hcx, hasher)
687 DeallocatedWrongMemoryKind(ref a, ref b) => {
688 a.hash_stable(hcx, hasher);
689 b.hash_stable(hcx, hasher)
691 IncorrectAllocationInformation(a, b, c, d) => {
692 a.hash_stable(hcx, hasher);
693 b.hash_stable(hcx, hasher);
694 c.hash_stable(hcx, hasher);
695 d.hash_stable(hcx, hasher)
697 Layout(lay) => lay.hash_stable(hcx, hasher),
698 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
699 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
700 Overflow(op) => op.hash_stable(hcx, hasher),
705 impl_stable_hash_for!(enum mir::interpret::Lock {
711 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
716 impl_stable_hash_for!(enum mir::interpret::AccessKind {
721 impl_stable_hash_for!(enum ty::Variance {
728 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
732 impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
733 fn hash_stable<W: StableHasherResult>(&self,
734 hcx: &mut StableHashingContext<'a>,
735 hasher: &mut StableHasher<W>) {
743 // Reverse map to each `TypeParameterDef`'s `index` field, from
744 // `def_id.index` (`def_id.krate` is the same as the item's).
745 type_param_to_index: _, // Don't hash this
747 has_late_bound_regions,
750 parent.hash_stable(hcx, hasher);
751 parent_regions.hash_stable(hcx, hasher);
752 parent_types.hash_stable(hcx, hasher);
753 regions.hash_stable(hcx, hasher);
754 types.hash_stable(hcx, hasher);
755 has_self.hash_stable(hcx, hasher);
756 has_late_bound_regions.hash_stable(hcx, hasher);
760 impl<'a> HashStable<StableHashingContext<'a>>
761 for ty::RegionParameterDef {
762 fn hash_stable<W: StableHasherResult>(&self,
763 hcx: &mut StableHashingContext<'a>,
764 hasher: &mut StableHasher<W>) {
765 let ty::RegionParameterDef {
772 name.hash_stable(hcx, hasher);
773 def_id.hash_stable(hcx, hasher);
774 index.hash_stable(hcx, hasher);
775 pure_wrt_drop.hash_stable(hcx, hasher);
779 impl_stable_hash_for!(struct ty::TypeParameterDef {
784 object_lifetime_default,
789 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
790 for ::middle::resolve_lifetime::Set1<T>
791 where T: HashStable<StableHashingContext<'a>>
793 fn hash_stable<W: StableHasherResult>(&self,
794 hcx: &mut StableHashingContext<'a>,
795 hasher: &mut StableHasher<W>) {
796 use middle::resolve_lifetime::Set1;
798 mem::discriminant(self).hash_stable(hcx, hasher);
804 Set1::One(ref value) => {
805 value.hash_stable(hcx, hasher);
811 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
816 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
818 EarlyBound(index, decl, is_in_band),
819 LateBound(db_index, decl, is_in_band),
820 LateBoundAnon(db_index, anon_index),
821 Free(call_site_scope_data, decl)
824 impl_stable_hash_for!(struct ty::DebruijnIndex {
828 impl_stable_hash_for!(enum ty::cast::CastKind {
842 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
843 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
845 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
846 type KeyType = region::Scope;
849 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
854 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
856 first_statement_index
859 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
863 impl_stable_hash_for!(struct ty::FreeRegion {
868 impl_stable_hash_for!(enum ty::BoundRegion {
870 BrNamed(def_id, name),
875 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
876 for ty::TypeVariants<'gcx>
878 fn hash_stable<W: StableHasherResult>(&self,
879 hcx: &mut StableHashingContext<'a>,
880 hasher: &mut StableHasher<W>) {
881 use ty::TypeVariants::*;
883 mem::discriminant(self).hash_stable(hcx, hasher);
890 // Nothing more to hash.
893 int_ty.hash_stable(hcx, hasher);
896 uint_ty.hash_stable(hcx, hasher);
898 TyFloat(float_ty) => {
899 float_ty.hash_stable(hcx, hasher);
901 TyAdt(adt_def, substs) => {
902 adt_def.hash_stable(hcx, hasher);
903 substs.hash_stable(hcx, hasher);
905 TyArray(inner_ty, len) => {
906 inner_ty.hash_stable(hcx, hasher);
907 len.hash_stable(hcx, hasher);
909 TySlice(inner_ty) => {
910 inner_ty.hash_stable(hcx, hasher);
912 TyRawPtr(pointee_ty) => {
913 pointee_ty.hash_stable(hcx, hasher);
915 TyRef(region, pointee_ty, mutbl) => {
916 region.hash_stable(hcx, hasher);
917 pointee_ty.hash_stable(hcx, hasher);
918 mutbl.hash_stable(hcx, hasher);
920 TyFnDef(def_id, substs) => {
921 def_id.hash_stable(hcx, hasher);
922 substs.hash_stable(hcx, hasher);
924 TyFnPtr(ref sig) => {
925 sig.hash_stable(hcx, hasher);
927 TyDynamic(ref existential_predicates, region) => {
928 existential_predicates.hash_stable(hcx, hasher);
929 region.hash_stable(hcx, hasher);
931 TyClosure(def_id, closure_substs) => {
932 def_id.hash_stable(hcx, hasher);
933 closure_substs.hash_stable(hcx, hasher);
935 TyGenerator(def_id, generator_substs, movability) => {
936 def_id.hash_stable(hcx, hasher);
937 generator_substs.hash_stable(hcx, hasher);
938 movability.hash_stable(hcx, hasher);
940 TyGeneratorWitness(types) => {
941 types.hash_stable(hcx, hasher)
943 TyTuple(inner_tys) => {
944 inner_tys.hash_stable(hcx, hasher);
946 TyProjection(ref projection_ty) => {
947 projection_ty.hash_stable(hcx, hasher);
949 TyAnon(def_id, substs) => {
950 def_id.hash_stable(hcx, hasher);
951 substs.hash_stable(hcx, hasher);
953 TyParam(param_ty) => {
954 param_ty.hash_stable(hcx, hasher);
956 TyForeign(def_id) => {
957 def_id.hash_stable(hcx, hasher);
959 TyInfer(infer_ty) => {
960 infer_ty.hash_stable(hcx, hasher);
966 impl_stable_hash_for!(enum ty::InferTy {
976 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
979 fn hash_stable<W: StableHasherResult>(&self,
980 _hcx: &mut StableHashingContext<'a>,
981 _hasher: &mut StableHasher<W>) {
982 // TyVid values are confined to an inference context and hence
983 // should not be hashed.
984 bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
988 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
991 fn hash_stable<W: StableHasherResult>(&self,
992 _hcx: &mut StableHashingContext<'a>,
993 _hasher: &mut StableHasher<W>) {
994 // IntVid values are confined to an inference context and hence
995 // should not be hashed.
996 bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
1000 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
1003 fn hash_stable<W: StableHasherResult>(&self,
1004 _hcx: &mut StableHashingContext<'a>,
1005 _hasher: &mut StableHasher<W>) {
1006 // FloatVid values are confined to an inference context and hence
1007 // should not be hashed.
1008 bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
1012 impl_stable_hash_for!(struct ty::ParamTy {
1017 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
1022 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
1023 for ty::ExistentialPredicate<'gcx>
1025 fn hash_stable<W: StableHasherResult>(&self,
1026 hcx: &mut StableHashingContext<'a>,
1027 hasher: &mut StableHasher<W>) {
1028 mem::discriminant(self).hash_stable(hcx, hasher);
1030 ty::ExistentialPredicate::Trait(ref trait_ref) => {
1031 trait_ref.hash_stable(hcx, hasher);
1033 ty::ExistentialPredicate::Projection(ref projection) => {
1034 projection.hash_stable(hcx, hasher);
1036 ty::ExistentialPredicate::AutoTrait(def_id) => {
1037 def_id.hash_stable(hcx, hasher);
1043 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
1048 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
1054 impl_stable_hash_for!(struct ty::Instance<'tcx> {
1059 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
1060 fn hash_stable<W: StableHasherResult>(&self,
1061 hcx: &mut StableHashingContext<'a>,
1062 hasher: &mut StableHasher<W>) {
1063 mem::discriminant(self).hash_stable(hcx, hasher);
1066 ty::InstanceDef::Item(def_id) => {
1067 def_id.hash_stable(hcx, hasher);
1069 ty::InstanceDef::Intrinsic(def_id) => {
1070 def_id.hash_stable(hcx, hasher);
1072 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1073 def_id.hash_stable(hcx, hasher);
1074 ty.hash_stable(hcx, hasher);
1076 ty::InstanceDef::Virtual(def_id, n) => {
1077 def_id.hash_stable(hcx, hasher);
1078 n.hash_stable(hcx, hasher);
1080 ty::InstanceDef::ClosureOnceShim { call_once } => {
1081 call_once.hash_stable(hcx, hasher);
1083 ty::InstanceDef::DropGlue(def_id, ty) => {
1084 def_id.hash_stable(hcx, hasher);
1085 ty.hash_stable(hcx, hasher);
1087 ty::InstanceDef::CloneShim(def_id, ty) => {
1088 def_id.hash_stable(hcx, hasher);
1089 ty.hash_stable(hcx, hasher);
1095 impl<'a> HashStable<StableHashingContext<'a>> for ty::TraitDef {
1096 fn hash_stable<W: StableHasherResult>(&self,
1097 hcx: &mut StableHashingContext<'a>,
1098 hasher: &mut StableHasher<W>) {
1100 // We already have the def_path_hash below, no need to hash it twice
1108 unsafety.hash_stable(hcx, hasher);
1109 paren_sugar.hash_stable(hcx, hasher);
1110 has_auto_impl.hash_stable(hcx, hasher);
1111 def_path_hash.hash_stable(hcx, hasher);
1115 impl_stable_hash_for!(struct ty::Destructor {
1119 impl<'a> HashStable<StableHashingContext<'a>> for ty::CrateVariancesMap {
1120 fn hash_stable<W: StableHasherResult>(&self,
1121 hcx: &mut StableHashingContext<'a>,
1122 hasher: &mut StableHasher<W>) {
1123 let ty::CrateVariancesMap {
1125 // This is just an irrelevant helper value.
1129 variances.hash_stable(hcx, hasher);
1133 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'gcx> {
1134 fn hash_stable<W: StableHasherResult>(&self,
1135 hcx: &mut StableHashingContext<'a>,
1136 hasher: &mut StableHasher<W>) {
1137 let ty::CratePredicatesMap {
1139 // This is just an irrelevant helper value.
1143 predicates.hash_stable(hcx, hasher);
1147 impl_stable_hash_for!(struct ty::AssociatedItem {
1154 method_has_self_argument
1157 impl_stable_hash_for!(enum ty::AssociatedKind {
1163 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1164 TraitContainer(def_id),
1165 ImplContainer(def_id)
1169 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1170 for ty::steal::Steal<T>
1171 where T: HashStable<StableHashingContext<'a>>
1173 fn hash_stable<W: StableHasherResult>(&self,
1174 hcx: &mut StableHashingContext<'a>,
1175 hasher: &mut StableHasher<W>) {
1176 self.borrow().hash_stable(hcx, hasher);
1180 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1185 impl_stable_hash_for!(enum traits::Reveal {
1190 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1196 impl<'a> HashStable<StableHashingContext<'a>>
1197 for ::middle::privacy::AccessLevels {
1198 fn hash_stable<W: StableHasherResult>(&self,
1199 hcx: &mut StableHashingContext<'a>,
1200 hasher: &mut StableHasher<W>) {
1201 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1202 let ::middle::privacy::AccessLevels {
1206 map.hash_stable(hcx, hasher);
1211 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1215 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1217 Errored(error_reported)
1220 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1222 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1226 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1227 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1228 fn hash_stable<W: StableHasherResult>(&self,
1229 hcx: &mut StableHashingContext<'a>,
1230 hasher: &mut StableHasher<W>) {
1231 use traits::Vtable::*;
1233 mem::discriminant(self).hash_stable(hcx, hasher);
1236 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1237 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1238 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1239 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1240 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1241 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1242 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1243 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1248 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1249 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1250 fn hash_stable<W: StableHasherResult>(&self,
1251 hcx: &mut StableHashingContext<'a>,
1252 hasher: &mut StableHasher<W>) {
1253 let traits::VtableImplData {
1258 impl_def_id.hash_stable(hcx, hasher);
1259 substs.hash_stable(hcx, hasher);
1260 nested.hash_stable(hcx, hasher);
1264 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1265 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1266 fn hash_stable<W: StableHasherResult>(&self,
1267 hcx: &mut StableHashingContext<'a>,
1268 hasher: &mut StableHasher<W>) {
1269 let traits::VtableAutoImplData {
1273 trait_def_id.hash_stable(hcx, hasher);
1274 nested.hash_stable(hcx, hasher);
1278 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1279 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1280 fn hash_stable<W: StableHasherResult>(&self,
1281 hcx: &mut StableHashingContext<'a>,
1282 hasher: &mut StableHasher<W>) {
1283 let traits::VtableObjectData {
1288 upcast_trait_ref.hash_stable(hcx, hasher);
1289 vtable_base.hash_stable(hcx, hasher);
1290 nested.hash_stable(hcx, hasher);
1294 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1295 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1296 fn hash_stable<W: StableHasherResult>(&self,
1297 hcx: &mut StableHashingContext<'a>,
1298 hasher: &mut StableHasher<W>) {
1299 let traits::VtableBuiltinData {
1302 nested.hash_stable(hcx, hasher);
1306 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1307 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1308 fn hash_stable<W: StableHasherResult>(&self,
1309 hcx: &mut StableHashingContext<'a>,
1310 hasher: &mut StableHasher<W>) {
1311 let traits::VtableClosureData {
1316 closure_def_id.hash_stable(hcx, hasher);
1317 substs.hash_stable(hcx, hasher);
1318 nested.hash_stable(hcx, hasher);
1322 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1323 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1324 fn hash_stable<W: StableHasherResult>(&self,
1325 hcx: &mut StableHashingContext<'a>,
1326 hasher: &mut StableHasher<W>) {
1327 let traits::VtableFnPointerData {
1331 fn_ty.hash_stable(hcx, hasher);
1332 nested.hash_stable(hcx, hasher);
1336 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1337 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1338 fn hash_stable<W: StableHasherResult>(&self,
1339 hcx: &mut StableHashingContext<'a>,
1340 hasher: &mut StableHasher<W>) {
1341 let traits::VtableGeneratorData {
1346 generator_def_id.hash_stable(hcx, hasher);
1347 substs.hash_stable(hcx, hasher);
1348 nested.hash_stable(hcx, hasher);
1352 impl_stable_hash_for!(
1353 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1358 impl_stable_hash_for!(
1359 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1364 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1368 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1373 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1379 impl_stable_hash_for!(
1380 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1381 var_values, region_constraints, certainty, value
1385 impl_stable_hash_for!(enum infer::canonical::Certainty {
1389 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClauseAtom<'tcx> {
1390 fn hash_stable<W: StableHasherResult>(&self,
1391 hcx: &mut StableHashingContext<'a>,
1392 hasher: &mut StableHasher<W>) {
1393 use traits::WhereClauseAtom::*;
1395 mem::discriminant(self).hash_stable(hcx, hasher);
1397 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1398 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1403 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1404 fn hash_stable<W: StableHasherResult>(&self,
1405 hcx: &mut StableHashingContext<'a>,
1406 hasher: &mut StableHasher<W>) {
1407 use traits::DomainGoal::*;
1409 mem::discriminant(self).hash_stable(hcx, hasher);
1411 Holds(where_clause) |
1412 WellFormed(where_clause) |
1413 FromEnv(where_clause) => where_clause.hash_stable(hcx, hasher),
1415 WellFormedTy(ty) => ty.hash_stable(hcx, hasher),
1416 Normalize(projection) => projection.hash_stable(hcx, hasher),
1417 FromEnvTy(ty) => ty.hash_stable(hcx, hasher),
1418 RegionOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1419 TypeOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1424 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1425 fn hash_stable<W: StableHasherResult>(&self,
1426 hcx: &mut StableHashingContext<'a>,
1427 hasher: &mut StableHasher<W>) {
1428 use traits::Goal::*;
1430 mem::discriminant(self).hash_stable(hcx, hasher);
1432 Implies(hypotheses, goal) => {
1433 hypotheses.hash_stable(hcx, hasher);
1434 goal.hash_stable(hcx, hasher);
1436 And(goal1, goal2) => {
1437 goal1.hash_stable(hcx, hasher);
1438 goal2.hash_stable(hcx, hasher);
1440 Not(goal) => goal.hash_stable(hcx, hasher),
1441 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1442 Quantified(quantifier, goal) => {
1443 quantifier.hash_stable(hcx, hasher);
1444 goal.hash_stable(hcx, hasher);
1451 impl_stable_hash_for!(
1452 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1457 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1458 fn hash_stable<W: StableHasherResult>(&self,
1459 hcx: &mut StableHashingContext<'a>,
1460 hasher: &mut StableHasher<W>) {
1461 use traits::Clause::*;
1463 mem::discriminant(self).hash_stable(hcx, hasher);
1465 Implies(clause) => clause.hash_stable(hcx, hasher),
1466 ForAll(clause) => clause.hash_stable(hcx, hasher),
1471 impl_stable_hash_for!(enum traits::QuantifierKind {