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>>
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::List<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::RePlaceholder(..) => {
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 self.index().hash_stable(hcx, hasher);
150 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::CanonicalVar {
152 fn hash_stable<W: StableHasherResult>(&self,
153 hcx: &mut StableHashingContext<'gcx>,
154 hasher: &mut StableHasher<W>) {
155 self.index().hash_stable(hcx, hasher);
159 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
160 for ty::adjustment::AutoBorrow<'gcx> {
161 fn hash_stable<W: StableHasherResult>(&self,
162 hcx: &mut StableHashingContext<'a>,
163 hasher: &mut StableHasher<W>) {
164 mem::discriminant(self).hash_stable(hcx, hasher);
166 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
167 region.hash_stable(hcx, hasher);
168 mutability.hash_stable(hcx, hasher);
170 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
171 mutability.hash_stable(hcx, hasher);
177 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
178 for ty::adjustment::Adjust<'gcx> {
179 fn hash_stable<W: StableHasherResult>(&self,
180 hcx: &mut StableHashingContext<'a>,
181 hasher: &mut StableHasher<W>) {
182 mem::discriminant(self).hash_stable(hcx, hasher);
184 ty::adjustment::Adjust::NeverToAny |
185 ty::adjustment::Adjust::ReifyFnPointer |
186 ty::adjustment::Adjust::UnsafeFnPointer |
187 ty::adjustment::Adjust::ClosureFnPointer |
188 ty::adjustment::Adjust::MutToConstPointer |
189 ty::adjustment::Adjust::Unsize => {}
190 ty::adjustment::Adjust::Deref(ref overloaded) => {
191 overloaded.hash_stable(hcx, hasher);
193 ty::adjustment::Adjust::Borrow(ref autoref) => {
194 autoref.hash_stable(hcx, hasher);
200 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
201 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
202 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
203 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
208 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
209 fn hash_stable<W: StableHasherResult>(&self,
210 hcx: &mut StableHashingContext<'gcx>,
211 hasher: &mut StableHasher<W>) {
212 mem::discriminant(self).hash_stable(hcx, hasher);
214 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
215 allow_two_phase_borrow.hash_stable(hcx, hasher);
217 ty::adjustment::AutoBorrowMutability::Immutable => {}
222 impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
224 impl_stable_hash_for!(enum ty::BorrowKind {
230 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
231 for ty::UpvarCapture<'gcx> {
232 fn hash_stable<W: StableHasherResult>(&self,
233 hcx: &mut StableHashingContext<'a>,
234 hasher: &mut StableHasher<W>) {
235 mem::discriminant(self).hash_stable(hcx, hasher);
237 ty::UpvarCapture::ByValue => {}
238 ty::UpvarCapture::ByRef(ref up_var_borrow) => {
239 up_var_borrow.hash_stable(hcx, hasher);
245 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
250 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
257 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
258 where T: HashStable<StableHashingContext<'a>>
260 fn hash_stable<W: StableHasherResult>(&self,
261 hcx: &mut StableHashingContext<'a>,
262 hasher: &mut StableHasher<W>) {
263 self.skip_binder().hash_stable(hcx, hasher);
267 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
269 impl_stable_hash_for!(enum ty::Visibility {
275 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
276 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
277 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
279 impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
280 for ty::OutlivesPredicate<A, B>
281 where A: HashStable<StableHashingContext<'a>>,
282 B: HashStable<StableHashingContext<'a>>,
284 fn hash_stable<W: StableHasherResult>(&self,
285 hcx: &mut StableHashingContext<'a>,
286 hasher: &mut StableHasher<W>) {
287 let ty::OutlivesPredicate(ref a, ref b) = *self;
288 a.hash_stable(hcx, hasher);
289 b.hash_stable(hcx, hasher);
293 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
294 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
297 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
298 fn hash_stable<W: StableHasherResult>(&self,
299 hcx: &mut StableHashingContext<'a>,
300 hasher: &mut StableHasher<W>) {
301 mem::discriminant(self).hash_stable(hcx, hasher);
303 ty::Predicate::Trait(ref pred) => {
304 pred.hash_stable(hcx, hasher);
306 ty::Predicate::Subtype(ref pred) => {
307 pred.hash_stable(hcx, hasher);
309 ty::Predicate::RegionOutlives(ref pred) => {
310 pred.hash_stable(hcx, hasher);
312 ty::Predicate::TypeOutlives(ref pred) => {
313 pred.hash_stable(hcx, hasher);
315 ty::Predicate::Projection(ref pred) => {
316 pred.hash_stable(hcx, hasher);
318 ty::Predicate::WellFormed(ty) => {
319 ty.hash_stable(hcx, hasher);
321 ty::Predicate::ObjectSafe(def_id) => {
322 def_id.hash_stable(hcx, hasher);
324 ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
325 def_id.hash_stable(hcx, hasher);
326 closure_substs.hash_stable(hcx, hasher);
327 closure_kind.hash_stable(hcx, hasher);
329 ty::Predicate::ConstEvaluatable(def_id, substs) => {
330 def_id.hash_stable(hcx, hasher);
331 substs.hash_stable(hcx, hasher);
337 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
338 fn hash_stable<W: StableHasherResult>(&self,
339 _: &mut StableHashingContext<'a>,
340 hasher: &mut StableHasher<W>) {
341 std_hash::Hash::hash(self, hasher);
345 impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
346 fn hash_stable<W: StableHasherResult>(&self,
347 _: &mut StableHashingContext<'a>,
348 hasher: &mut StableHasher<W>) {
349 std_hash::Hash::hash(self, hasher);
353 impl_stable_hash_for!(enum ty::VariantDiscr {
358 impl_stable_hash_for!(struct ty::FieldDef {
360 ident -> (ident.name),
364 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
365 for ::mir::interpret::ConstValue<'gcx> {
366 fn hash_stable<W: StableHasherResult>(&self,
367 hcx: &mut StableHashingContext<'a>,
368 hasher: &mut StableHasher<W>) {
369 use mir::interpret::ConstValue::*;
371 mem::discriminant(self).hash_stable(hcx, hasher);
374 Unevaluated(def_id, substs) => {
375 def_id.hash_stable(hcx, hasher);
376 substs.hash_stable(hcx, hasher);
379 val.hash_stable(hcx, hasher);
381 ScalarPair(a, b) => {
382 a.hash_stable(hcx, hasher);
383 b.hash_stable(hcx, hasher);
385 ByRef(id, alloc, offset) => {
386 id.hash_stable(hcx, hasher);
387 alloc.hash_stable(hcx, hasher);
388 offset.hash_stable(hcx, hasher);
394 impl<'a, Tag> HashStable<StableHashingContext<'a>>
395 for ::mir::interpret::Pointer<Tag>
396 where Tag: HashStable<StableHashingContext<'a>>
398 fn hash_stable<W: StableHasherResult>(&self,
399 hcx: &mut StableHashingContext<'a>,
400 hasher: &mut StableHasher<W>) {
401 let ::mir::interpret::Pointer { alloc_id, offset, tag } = self;
402 alloc_id.hash_stable(hcx, hasher);
403 offset.hash_stable(hcx, hasher);
404 tag.hash_stable(hcx, hasher);
408 impl<'a, Tag> HashStable<StableHashingContext<'a>>
409 for ::mir::interpret::Scalar<Tag>
410 where Tag: HashStable<StableHashingContext<'a>>
412 fn hash_stable<W: StableHasherResult>(&self,
413 hcx: &mut StableHashingContext<'a>,
414 hasher: &mut StableHasher<W>) {
415 use mir::interpret::Scalar::*;
417 mem::discriminant(self).hash_stable(hcx, hasher);
419 Bits { bits, size } => {
420 bits.hash_stable(hcx, hasher);
421 size.hash_stable(hcx, hasher);
423 Ptr(ptr) => ptr.hash_stable(hcx, hasher),
428 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
429 fn hash_stable<W: StableHasherResult>(
431 hcx: &mut StableHashingContext<'a>,
432 hasher: &mut StableHasher<W>,
434 ty::tls::with_opt(|tcx| {
435 trace!("hashing {:?}", *self);
436 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
437 let alloc_kind = tcx.alloc_map.lock().get(*self);
438 alloc_kind.hash_stable(hcx, hasher);
443 impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
444 for mir::interpret::AllocType<'gcx, M> {
445 fn hash_stable<W: StableHasherResult>(&self,
446 hcx: &mut StableHashingContext<'a>,
447 hasher: &mut StableHasher<W>) {
448 use mir::interpret::AllocType::*;
450 mem::discriminant(self).hash_stable(hcx, hasher);
453 Function(instance) => instance.hash_stable(hcx, hasher),
454 Static(def_id) => def_id.hash_stable(hcx, hasher),
455 Memory(ref mem) => mem.hash_stable(hcx, hasher),
460 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
461 fn hash_stable<W: StableHasherResult>(
463 hcx: &mut StableHashingContext<'a>,
464 hasher: &mut StableHasher<W>,
466 self.bytes.hash_stable(hcx, hasher);
467 for reloc in self.relocations.iter() {
468 reloc.hash_stable(hcx, hasher);
470 self.undef_mask.hash_stable(hcx, hasher);
471 self.align.hash_stable(hcx, hasher);
472 self.mutability.hash_stable(hcx, hasher);
476 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
481 impl_stable_hash_for!(struct ty::Const<'tcx> {
486 impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> {
492 impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
498 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
499 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
501 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
506 impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
508 impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
509 for ::mir::interpret::EvalErrorKind<'gcx, O> {
510 fn hash_stable<W: StableHasherResult>(&self,
511 hcx: &mut StableHashingContext<'a>,
512 hasher: &mut StableHasher<W>) {
513 use mir::interpret::EvalErrorKind::*;
515 mem::discriminant(&self).hash_stable(hcx, hasher);
518 FunctionArgCountMismatch |
519 DanglingPointerDeref |
521 InvalidMemoryAccess |
522 InvalidFunctionPointer |
524 InvalidNullPointerUsage |
530 StackFrameLimitReached |
533 CalledClosureAsFunction |
534 VtableForArgumentlessMethod |
535 ModifiedConstantMemory |
538 ReallocateNonBasePtr |
539 DeallocateNonBasePtr |
542 ReadFromReturnPointer |
543 UnimplementedTraitSelection |
547 DerefFunctionPointer |
552 GeneratorResumedAfterReturn |
553 GeneratorResumedAfterPanic |
555 ReadUndefBytes(offset) => offset.hash_stable(hcx, hasher),
556 InvalidDiscriminant(val) => val.hash_stable(hcx, hasher),
557 Panic { ref msg, ref file, line, col } => {
558 msg.hash_stable(hcx, hasher);
559 file.hash_stable(hcx, hasher);
560 line.hash_stable(hcx, hasher);
561 col.hash_stable(hcx, hasher);
563 ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
564 MachineError(ref err) => err.hash_stable(hcx, hasher),
565 FunctionAbiMismatch(a, b) => {
566 a.hash_stable(hcx, hasher);
567 b.hash_stable(hcx, hasher)
569 FunctionArgMismatch(a, b) => {
570 a.hash_stable(hcx, hasher);
571 b.hash_stable(hcx, hasher)
573 FunctionRetMismatch(a, b) => {
574 a.hash_stable(hcx, hasher);
575 b.hash_stable(hcx, hasher)
577 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
578 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
584 ptr.hash_stable(hcx, hasher);
585 access.hash_stable(hcx, hasher);
586 allocation_size.hash_stable(hcx, hasher)
588 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
589 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
590 BoundsCheck { ref len, ref index } => {
591 len.hash_stable(hcx, hasher);
592 index.hash_stable(hcx, hasher)
594 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
595 InvalidChar(c) => c.hash_stable(hcx, hasher),
596 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
597 AlignmentCheckFailed {
601 required.hash_stable(hcx, hasher);
602 has.hash_stable(hcx, hasher)
604 MemoryLockViolation {
611 ptr.hash_stable(hcx, hasher);
612 len.hash_stable(hcx, hasher);
613 frame.hash_stable(hcx, hasher);
614 access.hash_stable(hcx, hasher);
615 lock.hash_stable(hcx, hasher)
617 MemoryAcquireConflict {
623 ptr.hash_stable(hcx, hasher);
624 len.hash_stable(hcx, hasher);
625 kind.hash_stable(hcx, hasher);
626 lock.hash_stable(hcx, hasher)
628 InvalidMemoryLockRelease {
634 ptr.hash_stable(hcx, hasher);
635 len.hash_stable(hcx, hasher);
636 frame.hash_stable(hcx, hasher);
637 lock.hash_stable(hcx, hasher)
639 DeallocatedLockedMemory {
643 ptr.hash_stable(hcx, hasher);
644 lock.hash_stable(hcx, hasher)
646 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
647 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
648 ReallocatedWrongMemoryKind(ref a, ref b) => {
649 a.hash_stable(hcx, hasher);
650 b.hash_stable(hcx, hasher)
652 DeallocatedWrongMemoryKind(ref a, ref b) => {
653 a.hash_stable(hcx, hasher);
654 b.hash_stable(hcx, hasher)
656 IncorrectAllocationInformation(a, b, c, d) => {
657 a.hash_stable(hcx, hasher);
658 b.hash_stable(hcx, hasher);
659 c.hash_stable(hcx, hasher);
660 d.hash_stable(hcx, hasher)
662 Layout(lay) => lay.hash_stable(hcx, hasher),
663 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
664 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
665 Overflow(op) => op.hash_stable(hcx, hasher),
670 impl_stable_hash_for!(enum mir::interpret::Lock {
676 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
681 impl_stable_hash_for!(enum mir::interpret::AccessKind {
686 impl_stable_hash_for!(enum ty::Variance {
693 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
697 impl_stable_hash_for!(struct ty::Generics {
701 // Reverse map to each param's `index` field, from its `def_id`.
702 param_def_id_to_index -> _, // Don't hash this
704 has_late_bound_regions,
707 impl_stable_hash_for!(struct ty::GenericParamDef {
715 impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
716 fn hash_stable<W: StableHasherResult>(&self,
717 hcx: &mut StableHashingContext<'a>,
718 hasher: &mut StableHasher<W>) {
719 mem::discriminant(self).hash_stable(hcx, hasher);
721 ty::GenericParamDefKind::Lifetime => {}
722 ty::GenericParamDefKind::Type {
724 ref object_lifetime_default,
727 has_default.hash_stable(hcx, hasher);
728 object_lifetime_default.hash_stable(hcx, hasher);
729 synthetic.hash_stable(hcx, hasher);
735 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
736 for ::middle::resolve_lifetime::Set1<T>
737 where T: HashStable<StableHashingContext<'a>>
739 fn hash_stable<W: StableHasherResult>(&self,
740 hcx: &mut StableHashingContext<'a>,
741 hasher: &mut StableHasher<W>) {
742 use middle::resolve_lifetime::Set1;
744 mem::discriminant(self).hash_stable(hcx, hasher);
750 Set1::One(ref value) => {
751 value.hash_stable(hcx, hasher);
757 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
762 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
764 EarlyBound(index, decl, is_in_band),
765 LateBound(db_index, decl, is_in_band),
766 LateBoundAnon(db_index, anon_index),
767 Free(call_site_scope_data, decl)
770 impl_stable_hash_for!(enum ty::cast::CastKind {
784 impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
786 impl_stable_hash_for!(enum ::middle::region::ScopeData {
791 Remainder(first_statement_index)
794 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
795 type KeyType = region::Scope;
798 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
803 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
807 impl_stable_hash_for!(struct ty::FreeRegion {
812 impl_stable_hash_for!(enum ty::BoundRegion {
814 BrNamed(def_id, name),
819 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
822 fn hash_stable<W: StableHasherResult>(&self,
823 hcx: &mut StableHashingContext<'a>,
824 hasher: &mut StableHasher<W>) {
827 mem::discriminant(self).hash_stable(hcx, hasher);
834 // Nothing more to hash.
837 int_ty.hash_stable(hcx, hasher);
840 uint_ty.hash_stable(hcx, hasher);
843 float_ty.hash_stable(hcx, hasher);
845 Adt(adt_def, substs) => {
846 adt_def.hash_stable(hcx, hasher);
847 substs.hash_stable(hcx, hasher);
849 Array(inner_ty, len) => {
850 inner_ty.hash_stable(hcx, hasher);
851 len.hash_stable(hcx, hasher);
854 inner_ty.hash_stable(hcx, hasher);
856 RawPtr(pointee_ty) => {
857 pointee_ty.hash_stable(hcx, hasher);
859 Ref(region, pointee_ty, mutbl) => {
860 region.hash_stable(hcx, hasher);
861 pointee_ty.hash_stable(hcx, hasher);
862 mutbl.hash_stable(hcx, hasher);
864 FnDef(def_id, substs) => {
865 def_id.hash_stable(hcx, hasher);
866 substs.hash_stable(hcx, hasher);
869 sig.hash_stable(hcx, hasher);
871 Dynamic(ref existential_predicates, region) => {
872 existential_predicates.hash_stable(hcx, hasher);
873 region.hash_stable(hcx, hasher);
875 Closure(def_id, closure_substs) => {
876 def_id.hash_stable(hcx, hasher);
877 closure_substs.hash_stable(hcx, hasher);
879 Generator(def_id, generator_substs, movability) => {
880 def_id.hash_stable(hcx, hasher);
881 generator_substs.hash_stable(hcx, hasher);
882 movability.hash_stable(hcx, hasher);
884 GeneratorWitness(types) => {
885 types.hash_stable(hcx, hasher)
887 Tuple(inner_tys) => {
888 inner_tys.hash_stable(hcx, hasher);
890 Projection(ref data) | UnnormalizedProjection(ref data) => {
891 data.hash_stable(hcx, hasher);
893 Opaque(def_id, substs) => {
894 def_id.hash_stable(hcx, hasher);
895 substs.hash_stable(hcx, hasher);
898 param_ty.hash_stable(hcx, hasher);
901 def_id.hash_stable(hcx, hasher);
904 infer_ty.hash_stable(hcx, hasher);
910 impl_stable_hash_for!(enum ty::InferTy {
920 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
923 fn hash_stable<W: StableHasherResult>(&self,
924 _hcx: &mut StableHashingContext<'a>,
925 _hasher: &mut StableHasher<W>) {
926 // TyVid values are confined to an inference context and hence
927 // should not be hashed.
928 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
932 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
935 fn hash_stable<W: StableHasherResult>(&self,
936 _hcx: &mut StableHashingContext<'a>,
937 _hasher: &mut StableHasher<W>) {
938 // IntVid values are confined to an inference context and hence
939 // should not be hashed.
940 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
944 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
947 fn hash_stable<W: StableHasherResult>(&self,
948 _hcx: &mut StableHashingContext<'a>,
949 _hasher: &mut StableHasher<W>) {
950 // FloatVid values are confined to an inference context and hence
951 // should not be hashed.
952 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
956 impl_stable_hash_for!(struct ty::ParamTy {
961 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
966 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
967 for ty::ExistentialPredicate<'gcx>
969 fn hash_stable<W: StableHasherResult>(&self,
970 hcx: &mut StableHashingContext<'a>,
971 hasher: &mut StableHasher<W>) {
972 mem::discriminant(self).hash_stable(hcx, hasher);
974 ty::ExistentialPredicate::Trait(ref trait_ref) => {
975 trait_ref.hash_stable(hcx, hasher);
977 ty::ExistentialPredicate::Projection(ref projection) => {
978 projection.hash_stable(hcx, hasher);
980 ty::ExistentialPredicate::AutoTrait(def_id) => {
981 def_id.hash_stable(hcx, hasher);
987 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
992 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
998 impl_stable_hash_for!(struct ty::Instance<'tcx> {
1003 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
1004 fn hash_stable<W: StableHasherResult>(&self,
1005 hcx: &mut StableHashingContext<'a>,
1006 hasher: &mut StableHasher<W>) {
1007 mem::discriminant(self).hash_stable(hcx, hasher);
1010 ty::InstanceDef::Item(def_id) => {
1011 def_id.hash_stable(hcx, hasher);
1013 ty::InstanceDef::Intrinsic(def_id) => {
1014 def_id.hash_stable(hcx, hasher);
1016 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1017 def_id.hash_stable(hcx, hasher);
1018 ty.hash_stable(hcx, hasher);
1020 ty::InstanceDef::Virtual(def_id, n) => {
1021 def_id.hash_stable(hcx, hasher);
1022 n.hash_stable(hcx, hasher);
1024 ty::InstanceDef::ClosureOnceShim { call_once } => {
1025 call_once.hash_stable(hcx, hasher);
1027 ty::InstanceDef::DropGlue(def_id, ty) => {
1028 def_id.hash_stable(hcx, hasher);
1029 ty.hash_stable(hcx, hasher);
1031 ty::InstanceDef::CloneShim(def_id, ty) => {
1032 def_id.hash_stable(hcx, hasher);
1033 ty.hash_stable(hcx, hasher);
1039 impl_stable_hash_for!(struct ty::TraitDef {
1040 // We already have the def_path_hash below, no need to hash it twice
1049 impl_stable_hash_for!(struct ty::Destructor {
1053 impl_stable_hash_for!(struct ty::CrateVariancesMap {
1055 // This is just an irrelevant helper value.
1056 empty_variance -> _,
1059 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
1061 // This is just an irrelevant helper value.
1062 empty_predicate -> _,
1065 impl_stable_hash_for!(struct ty::AssociatedItem {
1067 ident -> (ident.name),
1072 method_has_self_argument
1075 impl_stable_hash_for!(enum ty::AssociatedKind {
1082 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1083 TraitContainer(def_id),
1084 ImplContainer(def_id)
1088 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1089 for ty::steal::Steal<T>
1090 where T: HashStable<StableHashingContext<'a>>
1092 fn hash_stable<W: StableHasherResult>(&self,
1093 hcx: &mut StableHashingContext<'a>,
1094 hasher: &mut StableHasher<W>) {
1095 self.borrow().hash_stable(hcx, hasher);
1099 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1104 impl_stable_hash_for!(enum traits::Reveal {
1109 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1110 ReachableFromImplTrait,
1116 impl<'a> HashStable<StableHashingContext<'a>>
1117 for ::middle::privacy::AccessLevels {
1118 fn hash_stable<W: StableHasherResult>(&self,
1119 hcx: &mut StableHashingContext<'a>,
1120 hasher: &mut StableHasher<W>) {
1121 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1122 let ::middle::privacy::AccessLevels {
1126 map.hash_stable(hcx, hasher);
1131 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1135 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1137 Errored(error_reported)
1140 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1142 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1146 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1147 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1148 fn hash_stable<W: StableHasherResult>(&self,
1149 hcx: &mut StableHashingContext<'a>,
1150 hasher: &mut StableHasher<W>) {
1151 use traits::Vtable::*;
1153 mem::discriminant(self).hash_stable(hcx, hasher);
1156 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1157 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1158 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1159 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1160 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1161 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1162 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1163 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1168 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1169 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1170 fn hash_stable<W: StableHasherResult>(&self,
1171 hcx: &mut StableHashingContext<'a>,
1172 hasher: &mut StableHasher<W>) {
1173 let traits::VtableImplData {
1178 impl_def_id.hash_stable(hcx, hasher);
1179 substs.hash_stable(hcx, hasher);
1180 nested.hash_stable(hcx, hasher);
1184 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1185 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1186 fn hash_stable<W: StableHasherResult>(&self,
1187 hcx: &mut StableHashingContext<'a>,
1188 hasher: &mut StableHasher<W>) {
1189 let traits::VtableAutoImplData {
1193 trait_def_id.hash_stable(hcx, hasher);
1194 nested.hash_stable(hcx, hasher);
1198 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1199 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1200 fn hash_stable<W: StableHasherResult>(&self,
1201 hcx: &mut StableHashingContext<'a>,
1202 hasher: &mut StableHasher<W>) {
1203 let traits::VtableObjectData {
1208 upcast_trait_ref.hash_stable(hcx, hasher);
1209 vtable_base.hash_stable(hcx, hasher);
1210 nested.hash_stable(hcx, hasher);
1214 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1215 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1216 fn hash_stable<W: StableHasherResult>(&self,
1217 hcx: &mut StableHashingContext<'a>,
1218 hasher: &mut StableHasher<W>) {
1219 let traits::VtableBuiltinData {
1222 nested.hash_stable(hcx, hasher);
1226 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1227 for traits::VtableClosureData<'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 let traits::VtableClosureData {
1236 closure_def_id.hash_stable(hcx, hasher);
1237 substs.hash_stable(hcx, hasher);
1238 nested.hash_stable(hcx, hasher);
1242 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1243 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1244 fn hash_stable<W: StableHasherResult>(&self,
1245 hcx: &mut StableHashingContext<'a>,
1246 hasher: &mut StableHasher<W>) {
1247 let traits::VtableFnPointerData {
1251 fn_ty.hash_stable(hcx, hasher);
1252 nested.hash_stable(hcx, hasher);
1256 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1257 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1258 fn hash_stable<W: StableHasherResult>(&self,
1259 hcx: &mut StableHashingContext<'a>,
1260 hasher: &mut StableHasher<W>) {
1261 let traits::VtableGeneratorData {
1266 generator_def_id.hash_stable(hcx, hasher);
1267 substs.hash_stable(hcx, hasher);
1268 nested.hash_stable(hcx, hasher);
1272 impl_stable_hash_for!(
1273 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1278 impl_stable_hash_for!(
1279 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1284 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1288 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1293 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1299 impl_stable_hash_for!(
1300 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1301 var_values, region_constraints, certainty, value
1305 impl_stable_hash_for!(enum infer::canonical::Certainty {
1309 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1310 fn hash_stable<W: StableHasherResult>(&self,
1311 hcx: &mut StableHashingContext<'a>,
1312 hasher: &mut StableHasher<W>) {
1313 use traits::WhereClause::*;
1315 mem::discriminant(self).hash_stable(hcx, hasher);
1317 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1318 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1319 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1320 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1325 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1326 fn hash_stable<W: StableHasherResult>(&self,
1327 hcx: &mut StableHashingContext<'a>,
1328 hasher: &mut StableHasher<W>) {
1329 use traits::WellFormed::*;
1331 mem::discriminant(self).hash_stable(hcx, hasher);
1333 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1334 Ty(ty) => ty.hash_stable(hcx, hasher),
1339 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1340 fn hash_stable<W: StableHasherResult>(&self,
1341 hcx: &mut StableHashingContext<'a>,
1342 hasher: &mut StableHasher<W>) {
1343 use traits::FromEnv::*;
1345 mem::discriminant(self).hash_stable(hcx, hasher);
1347 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1348 Ty(ty) => ty.hash_stable(hcx, hasher),
1353 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1354 fn hash_stable<W: StableHasherResult>(&self,
1355 hcx: &mut StableHashingContext<'a>,
1356 hasher: &mut StableHasher<W>) {
1357 use traits::DomainGoal::*;
1359 mem::discriminant(self).hash_stable(hcx, hasher);
1361 Holds(wc) => wc.hash_stable(hcx, hasher),
1362 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1363 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1364 Normalize(projection) => projection.hash_stable(hcx, hasher),
1369 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1370 fn hash_stable<W: StableHasherResult>(&self,
1371 hcx: &mut StableHashingContext<'a>,
1372 hasher: &mut StableHasher<W>) {
1373 use traits::GoalKind::*;
1375 mem::discriminant(self).hash_stable(hcx, hasher);
1377 Implies(hypotheses, goal) => {
1378 hypotheses.hash_stable(hcx, hasher);
1379 goal.hash_stable(hcx, hasher);
1381 And(goal1, goal2) => {
1382 goal1.hash_stable(hcx, hasher);
1383 goal2.hash_stable(hcx, hasher);
1385 Not(goal) => goal.hash_stable(hcx, hasher),
1386 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1387 Quantified(quantifier, goal) => {
1388 quantifier.hash_stable(hcx, hasher);
1389 goal.hash_stable(hcx, hasher);
1396 impl_stable_hash_for!(
1397 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1402 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1403 fn hash_stable<W: StableHasherResult>(&self,
1404 hcx: &mut StableHashingContext<'a>,
1405 hasher: &mut StableHasher<W>) {
1406 use traits::Clause::*;
1408 mem::discriminant(self).hash_stable(hcx, hasher);
1410 Implies(clause) => clause.hash_stable(hcx, hasher),
1411 ForAll(clause) => clause.hash_stable(hcx, hasher),
1416 impl_stable_hash_for!(enum traits::QuantifierKind {