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 let ty::Binder(ref inner) = *self;
266 inner.hash_stable(hcx, hasher);
270 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
272 impl_stable_hash_for!(enum ty::Visibility {
278 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
279 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
280 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
282 impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
283 for ty::OutlivesPredicate<A, B>
284 where A: HashStable<StableHashingContext<'a>>,
285 B: HashStable<StableHashingContext<'a>>,
287 fn hash_stable<W: StableHasherResult>(&self,
288 hcx: &mut StableHashingContext<'a>,
289 hasher: &mut StableHasher<W>) {
290 let ty::OutlivesPredicate(ref a, ref b) = *self;
291 a.hash_stable(hcx, hasher);
292 b.hash_stable(hcx, hasher);
296 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
297 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
300 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
301 fn hash_stable<W: StableHasherResult>(&self,
302 hcx: &mut StableHashingContext<'a>,
303 hasher: &mut StableHasher<W>) {
304 mem::discriminant(self).hash_stable(hcx, hasher);
306 ty::Predicate::Trait(ref pred) => {
307 pred.hash_stable(hcx, hasher);
309 ty::Predicate::Subtype(ref pred) => {
310 pred.hash_stable(hcx, hasher);
312 ty::Predicate::RegionOutlives(ref pred) => {
313 pred.hash_stable(hcx, hasher);
315 ty::Predicate::TypeOutlives(ref pred) => {
316 pred.hash_stable(hcx, hasher);
318 ty::Predicate::Projection(ref pred) => {
319 pred.hash_stable(hcx, hasher);
321 ty::Predicate::WellFormed(ty) => {
322 ty.hash_stable(hcx, hasher);
324 ty::Predicate::ObjectSafe(def_id) => {
325 def_id.hash_stable(hcx, hasher);
327 ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
328 def_id.hash_stable(hcx, hasher);
329 closure_substs.hash_stable(hcx, hasher);
330 closure_kind.hash_stable(hcx, hasher);
332 ty::Predicate::ConstEvaluatable(def_id, substs) => {
333 def_id.hash_stable(hcx, hasher);
334 substs.hash_stable(hcx, hasher);
340 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
341 fn hash_stable<W: StableHasherResult>(&self,
342 _: &mut StableHashingContext<'a>,
343 hasher: &mut StableHasher<W>) {
344 std_hash::Hash::hash(self, hasher);
348 impl_stable_hash_for!(struct ty::VariantDef {
356 impl_stable_hash_for!(enum ty::VariantDiscr {
361 impl_stable_hash_for!(struct ty::FieldDef {
367 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
368 for ::middle::const_val::ConstVal<'gcx> {
369 fn hash_stable<W: StableHasherResult>(&self,
370 hcx: &mut StableHashingContext<'a>,
371 hasher: &mut StableHasher<W>) {
372 use middle::const_val::ConstVal::*;
374 mem::discriminant(self).hash_stable(hcx, hasher);
377 Unevaluated(def_id, substs) => {
378 def_id.hash_stable(hcx, hasher);
379 substs.hash_stable(hcx, hasher);
381 Value(ref value) => {
382 value.hash_stable(hcx, hasher);
388 impl_stable_hash_for!(enum mir::interpret::Value {
394 impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
399 enum AllocDiscriminant {
404 impl_stable_hash_for!(enum self::AllocDiscriminant {
410 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
411 fn hash_stable<W: StableHasherResult>(
413 hcx: &mut StableHashingContext<'a>,
414 hasher: &mut StableHasher<W>,
416 ty::tls::with_opt(|tcx| {
417 trace!("hashing {:?}", *self);
418 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
419 if let Some(def_id) = tcx.interpret_interner.get_static(*self) {
420 AllocDiscriminant::Static.hash_stable(hcx, hasher);
421 trace!("hashing {:?} as static {:?}", *self, def_id);
422 def_id.hash_stable(hcx, hasher);
423 } else if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
424 AllocDiscriminant::Alloc.hash_stable(hcx, hasher);
425 if hcx.alloc_id_recursion_tracker.insert(*self) {
426 trace!("hashing {:?} as alloc {:#?}", *self, alloc);
427 alloc.hash_stable(hcx, hasher);
428 assert!(hcx.alloc_id_recursion_tracker.remove(self));
430 trace!("skipping hashing of {:?} due to recursion", *self);
432 } else if let Some(inst) = tcx.interpret_interner.get_fn(*self) {
433 trace!("hashing {:?} as fn {:#?}", *self, inst);
434 AllocDiscriminant::Function.hash_stable(hcx, hasher);
435 inst.hash_stable(hcx, hasher);
437 bug!("no allocation for {}", self);
443 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
444 fn hash_stable<W: StableHasherResult>(
446 hcx: &mut StableHashingContext<'a>,
447 hasher: &mut StableHasher<W>,
449 self.bytes.hash_stable(hcx, hasher);
450 for reloc in self.relocations.iter() {
451 reloc.hash_stable(hcx, hasher);
453 self.undef_mask.hash_stable(hcx, hasher);
454 self.align.hash_stable(hcx, hasher);
455 self.runtime_mutability.hash_stable(hcx, hasher);
459 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
464 impl_stable_hash_for!(struct mir::interpret::Pointer{primval});
466 impl_stable_hash_for!(enum mir::interpret::PrimVal {
472 impl_stable_hash_for!(struct ty::Const<'tcx> {
477 impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
482 impl_stable_hash_for!(struct ::middle::const_val::FrameInfo {
487 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
488 for ::middle::const_val::ErrKind<'gcx> {
489 fn hash_stable<W: StableHasherResult>(&self,
490 hcx: &mut StableHashingContext<'a>,
491 hasher: &mut StableHasher<W>) {
492 use middle::const_val::ErrKind::*;
494 mem::discriminant(self).hash_stable(hcx, hasher);
502 UnimplementedConstVal(s) => {
503 s.hash_stable(hcx, hasher);
505 IndexOutOfBounds { len, index } => {
506 len.hash_stable(hcx, hasher);
507 index.hash_stable(hcx, hasher);
509 Math(ref const_math_err) => {
510 const_math_err.hash_stable(hcx, hasher);
512 LayoutError(ref layout_error) => {
513 layout_error.hash_stable(hcx, hasher);
515 Miri(ref err, ref trace) => {
516 err.hash_stable(hcx, hasher);
517 trace.hash_stable(hcx, hasher);
523 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
525 impl_stable_hash_for!(struct ty::GeneratorInterior<'tcx> { witness, movable });
527 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
532 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
533 for ::mir::interpret::EvalError<'gcx> {
534 fn hash_stable<W: StableHasherResult>(&self,
535 hcx: &mut StableHashingContext<'a>,
536 hasher: &mut StableHasher<W>) {
537 use mir::interpret::EvalErrorKind::*;
539 mem::discriminant(&self.kind).hash_stable(hcx, hasher);
542 DanglingPointerDeref |
544 InvalidMemoryAccess |
545 InvalidFunctionPointer |
547 InvalidDiscriminant |
548 InvalidNullPointerUsage |
554 StackFrameLimitReached |
557 CalledClosureAsFunction |
558 VtableForArgumentlessMethod |
559 ModifiedConstantMemory |
562 ReallocateNonBasePtr |
563 DeallocateNonBasePtr |
567 ReadFromReturnPointer |
568 UnimplementedTraitSelection |
570 DerefFunctionPointer |
573 OverflowingMath => {}
574 MachineError(ref err) => err.hash_stable(hcx, hasher),
575 FunctionPointerTyMismatch(a, b) => {
576 a.hash_stable(hcx, hasher);
577 b.hash_stable(hcx, hasher)
579 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
580 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
586 ptr.hash_stable(hcx, hasher);
587 access.hash_stable(hcx, hasher);
588 allocation_size.hash_stable(hcx, hasher)
590 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
591 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
592 ArrayIndexOutOfBounds(sp, a, b) => {
593 sp.hash_stable(hcx, hasher);
594 a.hash_stable(hcx, hasher);
595 b.hash_stable(hcx, hasher)
597 Math(sp, ref err) => {
598 sp.hash_stable(hcx, hasher);
599 err.hash_stable(hcx, hasher)
601 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
602 InvalidChar(c) => c.hash_stable(hcx, hasher),
603 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
604 AlignmentCheckFailed {
608 required.hash_stable(hcx, hasher);
609 has.hash_stable(hcx, hasher)
611 MemoryLockViolation {
618 ptr.hash_stable(hcx, hasher);
619 len.hash_stable(hcx, hasher);
620 frame.hash_stable(hcx, hasher);
621 access.hash_stable(hcx, hasher);
622 lock.hash_stable(hcx, hasher)
624 MemoryAcquireConflict {
630 ptr.hash_stable(hcx, hasher);
631 len.hash_stable(hcx, hasher);
632 kind.hash_stable(hcx, hasher);
633 lock.hash_stable(hcx, hasher)
635 InvalidMemoryLockRelease {
641 ptr.hash_stable(hcx, hasher);
642 len.hash_stable(hcx, hasher);
643 frame.hash_stable(hcx, hasher);
644 lock.hash_stable(hcx, hasher)
646 DeallocatedLockedMemory {
650 ptr.hash_stable(hcx, hasher);
651 lock.hash_stable(hcx, hasher)
653 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
654 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
655 ReallocatedWrongMemoryKind(ref a, ref b) => {
656 a.hash_stable(hcx, hasher);
657 b.hash_stable(hcx, hasher)
659 DeallocatedWrongMemoryKind(ref a, ref b) => {
660 a.hash_stable(hcx, hasher);
661 b.hash_stable(hcx, hasher)
663 IncorrectAllocationInformation(a, b, c, d) => {
664 a.hash_stable(hcx, hasher);
665 b.hash_stable(hcx, hasher);
666 c.hash_stable(hcx, hasher);
667 d.hash_stable(hcx, hasher)
669 Layout(lay) => lay.hash_stable(hcx, hasher),
670 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
671 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
676 impl_stable_hash_for!(enum mir::interpret::Lock {
682 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
687 impl_stable_hash_for!(enum mir::interpret::AccessKind {
692 impl_stable_hash_for!(enum ty::Variance {
699 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
703 impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
704 fn hash_stable<W: StableHasherResult>(&self,
705 hcx: &mut StableHashingContext<'a>,
706 hasher: &mut StableHasher<W>) {
714 // Reverse map to each `TypeParameterDef`'s `index` field, from
715 // `def_id.index` (`def_id.krate` is the same as the item's).
716 type_param_to_index: _, // Don't hash this
718 has_late_bound_regions,
721 parent.hash_stable(hcx, hasher);
722 parent_regions.hash_stable(hcx, hasher);
723 parent_types.hash_stable(hcx, hasher);
724 regions.hash_stable(hcx, hasher);
725 types.hash_stable(hcx, hasher);
726 has_self.hash_stable(hcx, hasher);
727 has_late_bound_regions.hash_stable(hcx, hasher);
731 impl<'a> HashStable<StableHashingContext<'a>>
732 for ty::RegionParameterDef {
733 fn hash_stable<W: StableHasherResult>(&self,
734 hcx: &mut StableHashingContext<'a>,
735 hasher: &mut StableHasher<W>) {
736 let ty::RegionParameterDef {
743 name.hash_stable(hcx, hasher);
744 def_id.hash_stable(hcx, hasher);
745 index.hash_stable(hcx, hasher);
746 pure_wrt_drop.hash_stable(hcx, hasher);
750 impl_stable_hash_for!(struct ty::TypeParameterDef {
755 object_lifetime_default,
760 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
761 for ::middle::resolve_lifetime::Set1<T>
762 where T: HashStable<StableHashingContext<'a>>
764 fn hash_stable<W: StableHasherResult>(&self,
765 hcx: &mut StableHashingContext<'a>,
766 hasher: &mut StableHasher<W>) {
767 use middle::resolve_lifetime::Set1;
769 mem::discriminant(self).hash_stable(hcx, hasher);
775 Set1::One(ref value) => {
776 value.hash_stable(hcx, hasher);
782 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
787 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
789 EarlyBound(index, decl, is_in_band),
790 LateBound(db_index, decl, is_in_band),
791 LateBoundAnon(db_index, anon_index),
792 Free(call_site_scope_data, decl)
795 impl_stable_hash_for!(struct ty::DebruijnIndex {
799 impl_stable_hash_for!(enum ty::cast::CastKind {
813 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
814 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
816 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
817 type KeyType = region::Scope;
820 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
825 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
827 first_statement_index
830 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
834 impl_stable_hash_for!(struct ty::FreeRegion {
839 impl_stable_hash_for!(enum ty::BoundRegion {
841 BrNamed(def_id, name),
846 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
847 for ty::TypeVariants<'gcx>
849 fn hash_stable<W: StableHasherResult>(&self,
850 hcx: &mut StableHashingContext<'a>,
851 hasher: &mut StableHasher<W>) {
852 use ty::TypeVariants::*;
854 mem::discriminant(self).hash_stable(hcx, hasher);
861 // Nothing more to hash.
864 int_ty.hash_stable(hcx, hasher);
867 uint_ty.hash_stable(hcx, hasher);
869 TyFloat(float_ty) => {
870 float_ty.hash_stable(hcx, hasher);
872 TyAdt(adt_def, substs) => {
873 adt_def.hash_stable(hcx, hasher);
874 substs.hash_stable(hcx, hasher);
876 TyArray(inner_ty, len) => {
877 inner_ty.hash_stable(hcx, hasher);
878 len.hash_stable(hcx, hasher);
880 TySlice(inner_ty) => {
881 inner_ty.hash_stable(hcx, hasher);
883 TyRawPtr(pointee_ty) => {
884 pointee_ty.hash_stable(hcx, hasher);
886 TyRef(region, pointee_ty) => {
887 region.hash_stable(hcx, hasher);
888 pointee_ty.hash_stable(hcx, hasher);
890 TyFnDef(def_id, substs) => {
891 def_id.hash_stable(hcx, hasher);
892 substs.hash_stable(hcx, hasher);
894 TyFnPtr(ref sig) => {
895 sig.hash_stable(hcx, hasher);
897 TyDynamic(ref existential_predicates, region) => {
898 existential_predicates.hash_stable(hcx, hasher);
899 region.hash_stable(hcx, hasher);
901 TyClosure(def_id, closure_substs) => {
902 def_id.hash_stable(hcx, hasher);
903 closure_substs.hash_stable(hcx, hasher);
905 TyGenerator(def_id, closure_substs, interior) => {
906 def_id.hash_stable(hcx, hasher);
907 closure_substs.hash_stable(hcx, hasher);
908 interior.hash_stable(hcx, hasher);
910 TyGeneratorWitness(types) => {
911 types.hash_stable(hcx, hasher)
913 TyTuple(inner_tys) => {
914 inner_tys.hash_stable(hcx, hasher);
916 TyProjection(ref projection_ty) => {
917 projection_ty.hash_stable(hcx, hasher);
919 TyAnon(def_id, substs) => {
920 def_id.hash_stable(hcx, hasher);
921 substs.hash_stable(hcx, hasher);
923 TyParam(param_ty) => {
924 param_ty.hash_stable(hcx, hasher);
926 TyForeign(def_id) => {
927 def_id.hash_stable(hcx, hasher);
929 TyInfer(infer_ty) => {
930 infer_ty.hash_stable(hcx, hasher);
936 impl_stable_hash_for!(enum ty::InferTy {
946 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
949 fn hash_stable<W: StableHasherResult>(&self,
950 _hcx: &mut StableHashingContext<'a>,
951 _hasher: &mut StableHasher<W>) {
952 // TyVid values are confined to an inference context and hence
953 // should not be hashed.
954 bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
958 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
961 fn hash_stable<W: StableHasherResult>(&self,
962 _hcx: &mut StableHashingContext<'a>,
963 _hasher: &mut StableHasher<W>) {
964 // IntVid values are confined to an inference context and hence
965 // should not be hashed.
966 bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
970 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
973 fn hash_stable<W: StableHasherResult>(&self,
974 _hcx: &mut StableHashingContext<'a>,
975 _hasher: &mut StableHasher<W>) {
976 // FloatVid values are confined to an inference context and hence
977 // should not be hashed.
978 bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
982 impl_stable_hash_for!(struct ty::ParamTy {
987 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
992 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
993 for ty::ExistentialPredicate<'gcx>
995 fn hash_stable<W: StableHasherResult>(&self,
996 hcx: &mut StableHashingContext<'a>,
997 hasher: &mut StableHasher<W>) {
998 mem::discriminant(self).hash_stable(hcx, hasher);
1000 ty::ExistentialPredicate::Trait(ref trait_ref) => {
1001 trait_ref.hash_stable(hcx, hasher);
1003 ty::ExistentialPredicate::Projection(ref projection) => {
1004 projection.hash_stable(hcx, hasher);
1006 ty::ExistentialPredicate::AutoTrait(def_id) => {
1007 def_id.hash_stable(hcx, hasher);
1013 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
1018 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
1024 impl_stable_hash_for!(struct ty::Instance<'tcx> {
1029 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
1030 fn hash_stable<W: StableHasherResult>(&self,
1031 hcx: &mut StableHashingContext<'a>,
1032 hasher: &mut StableHasher<W>) {
1033 mem::discriminant(self).hash_stable(hcx, hasher);
1036 ty::InstanceDef::Item(def_id) => {
1037 def_id.hash_stable(hcx, hasher);
1039 ty::InstanceDef::Intrinsic(def_id) => {
1040 def_id.hash_stable(hcx, hasher);
1042 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1043 def_id.hash_stable(hcx, hasher);
1044 ty.hash_stable(hcx, hasher);
1046 ty::InstanceDef::Virtual(def_id, n) => {
1047 def_id.hash_stable(hcx, hasher);
1048 n.hash_stable(hcx, hasher);
1050 ty::InstanceDef::ClosureOnceShim { call_once } => {
1051 call_once.hash_stable(hcx, hasher);
1053 ty::InstanceDef::DropGlue(def_id, ty) => {
1054 def_id.hash_stable(hcx, hasher);
1055 ty.hash_stable(hcx, hasher);
1057 ty::InstanceDef::CloneShim(def_id, ty) => {
1058 def_id.hash_stable(hcx, hasher);
1059 ty.hash_stable(hcx, hasher);
1065 impl<'a> HashStable<StableHashingContext<'a>> for ty::TraitDef {
1066 fn hash_stable<W: StableHasherResult>(&self,
1067 hcx: &mut StableHashingContext<'a>,
1068 hasher: &mut StableHasher<W>) {
1070 // We already have the def_path_hash below, no need to hash it twice
1078 unsafety.hash_stable(hcx, hasher);
1079 paren_sugar.hash_stable(hcx, hasher);
1080 has_auto_impl.hash_stable(hcx, hasher);
1081 def_path_hash.hash_stable(hcx, hasher);
1085 impl_stable_hash_for!(struct ty::Destructor {
1089 impl<'a> HashStable<StableHashingContext<'a>> for ty::CrateVariancesMap {
1090 fn hash_stable<W: StableHasherResult>(&self,
1091 hcx: &mut StableHashingContext<'a>,
1092 hasher: &mut StableHasher<W>) {
1093 let ty::CrateVariancesMap {
1095 // This is just an irrelevant helper value.
1099 variances.hash_stable(hcx, hasher);
1103 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'gcx> {
1104 fn hash_stable<W: StableHasherResult>(&self,
1105 hcx: &mut StableHashingContext<'a>,
1106 hasher: &mut StableHasher<W>) {
1107 let ty::CratePredicatesMap {
1109 // This is just an irrelevant helper value.
1113 predicates.hash_stable(hcx, hasher);
1117 impl_stable_hash_for!(struct ty::AssociatedItem {
1124 method_has_self_argument
1127 impl_stable_hash_for!(enum ty::AssociatedKind {
1133 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1134 TraitContainer(def_id),
1135 ImplContainer(def_id)
1139 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1140 for ty::steal::Steal<T>
1141 where T: HashStable<StableHashingContext<'a>>
1143 fn hash_stable<W: StableHasherResult>(&self,
1144 hcx: &mut StableHashingContext<'a>,
1145 hasher: &mut StableHasher<W>) {
1146 self.borrow().hash_stable(hcx, hasher);
1150 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1155 impl_stable_hash_for!(enum traits::Reveal {
1160 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1166 impl<'a> HashStable<StableHashingContext<'a>>
1167 for ::middle::privacy::AccessLevels {
1168 fn hash_stable<W: StableHasherResult>(&self,
1169 hcx: &mut StableHashingContext<'a>,
1170 hasher: &mut StableHasher<W>) {
1171 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1172 let ::middle::privacy::AccessLevels {
1176 map.hash_stable(hcx, hasher);
1181 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1185 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1187 Errored(error_reported)
1190 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1192 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1196 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1197 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1198 fn hash_stable<W: StableHasherResult>(&self,
1199 hcx: &mut StableHashingContext<'a>,
1200 hasher: &mut StableHasher<W>) {
1201 use traits::Vtable::*;
1203 mem::discriminant(self).hash_stable(hcx, hasher);
1206 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1207 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1208 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1209 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1210 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1211 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1212 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1213 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1218 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1219 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1220 fn hash_stable<W: StableHasherResult>(&self,
1221 hcx: &mut StableHashingContext<'a>,
1222 hasher: &mut StableHasher<W>) {
1223 let traits::VtableImplData {
1228 impl_def_id.hash_stable(hcx, hasher);
1229 substs.hash_stable(hcx, hasher);
1230 nested.hash_stable(hcx, hasher);
1234 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1235 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1236 fn hash_stable<W: StableHasherResult>(&self,
1237 hcx: &mut StableHashingContext<'a>,
1238 hasher: &mut StableHasher<W>) {
1239 let traits::VtableAutoImplData {
1243 trait_def_id.hash_stable(hcx, hasher);
1244 nested.hash_stable(hcx, hasher);
1248 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1249 for traits::VtableObjectData<'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::VtableObjectData {
1258 upcast_trait_ref.hash_stable(hcx, hasher);
1259 vtable_base.hash_stable(hcx, hasher);
1260 nested.hash_stable(hcx, hasher);
1264 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1265 for traits::VtableBuiltinData<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::VtableBuiltinData {
1272 nested.hash_stable(hcx, hasher);
1276 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1277 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1278 fn hash_stable<W: StableHasherResult>(&self,
1279 hcx: &mut StableHashingContext<'a>,
1280 hasher: &mut StableHasher<W>) {
1281 let traits::VtableClosureData {
1286 closure_def_id.hash_stable(hcx, hasher);
1287 substs.hash_stable(hcx, hasher);
1288 nested.hash_stable(hcx, hasher);
1292 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1293 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1294 fn hash_stable<W: StableHasherResult>(&self,
1295 hcx: &mut StableHashingContext<'a>,
1296 hasher: &mut StableHasher<W>) {
1297 let traits::VtableFnPointerData {
1301 fn_ty.hash_stable(hcx, hasher);
1302 nested.hash_stable(hcx, hasher);
1306 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1307 for traits::VtableGeneratorData<'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::VtableGeneratorData {
1316 closure_def_id.hash_stable(hcx, hasher);
1317 substs.hash_stable(hcx, hasher);
1318 nested.hash_stable(hcx, hasher);
1322 impl_stable_hash_for!(
1323 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1328 impl_stable_hash_for!(
1329 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1334 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1338 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1343 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1349 impl_stable_hash_for!(
1350 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1351 var_values, region_constraints, certainty, value
1355 impl_stable_hash_for!(struct infer::canonical::QueryRegionConstraints<'tcx> {
1356 region_outlives, ty_outlives
1359 impl_stable_hash_for!(enum infer::canonical::Certainty {
1363 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClauseAtom<'tcx> {
1364 fn hash_stable<W: StableHasherResult>(&self,
1365 hcx: &mut StableHashingContext<'a>,
1366 hasher: &mut StableHasher<W>) {
1367 use traits::WhereClauseAtom::*;
1369 mem::discriminant(self).hash_stable(hcx, hasher);
1371 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1372 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1377 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1378 fn hash_stable<W: StableHasherResult>(&self,
1379 hcx: &mut StableHashingContext<'a>,
1380 hasher: &mut StableHasher<W>) {
1381 use traits::DomainGoal::*;
1383 mem::discriminant(self).hash_stable(hcx, hasher);
1385 Holds(where_clause) |
1386 WellFormed(where_clause) |
1387 FromEnv(where_clause) => where_clause.hash_stable(hcx, hasher),
1389 WellFormedTy(ty) => ty.hash_stable(hcx, hasher),
1390 Normalize(projection) => projection.hash_stable(hcx, hasher),
1391 FromEnvTy(ty) => ty.hash_stable(hcx, hasher),
1392 RegionOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1393 TypeOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1398 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1399 fn hash_stable<W: StableHasherResult>(&self,
1400 hcx: &mut StableHashingContext<'a>,
1401 hasher: &mut StableHasher<W>) {
1402 use traits::Goal::*;
1404 mem::discriminant(self).hash_stable(hcx, hasher);
1406 Implies(hypotheses, goal) => {
1407 hypotheses.hash_stable(hcx, hasher);
1408 goal.hash_stable(hcx, hasher);
1410 And(goal1, goal2) => {
1411 goal1.hash_stable(hcx, hasher);
1412 goal2.hash_stable(hcx, hasher);
1414 Not(goal) => goal.hash_stable(hcx, hasher),
1415 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1416 Quantified(quantifier, goal) => {
1417 quantifier.hash_stable(hcx, hasher);
1418 goal.hash_stable(hcx, hasher);
1424 impl_stable_hash_for!(
1425 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1430 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1431 fn hash_stable<W: StableHasherResult>(&self,
1432 hcx: &mut StableHashingContext<'a>,
1433 hasher: &mut StableHasher<W>) {
1434 use traits::Clause::*;
1436 mem::discriminant(self).hash_stable(hcx, hasher);
1438 Implies(clause) => clause.hash_stable(hcx, hasher),
1439 ForAll(clause) => clause.hash_stable(hcx, hasher),
1444 impl_stable_hash_for!(enum traits::QuantifierKind {