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(Default::default());
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::BoundTyIndex {
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 {
763 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
765 EarlyBound(index, decl, is_in_band),
766 LateBound(db_index, decl, is_in_band),
767 LateBoundAnon(db_index, anon_index),
768 Free(call_site_scope_data, decl)
771 impl_stable_hash_for!(enum ty::cast::CastKind {
785 impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
787 impl_stable_hash_for!(enum ::middle::region::ScopeData {
792 Remainder(first_statement_index)
795 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
796 type KeyType = region::Scope;
799 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
804 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
808 impl_stable_hash_for!(struct ty::FreeRegion {
813 impl_stable_hash_for!(enum ty::BoundRegion {
815 BrNamed(def_id, name),
820 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
823 fn hash_stable<W: StableHasherResult>(&self,
824 hcx: &mut StableHashingContext<'a>,
825 hasher: &mut StableHasher<W>) {
828 mem::discriminant(self).hash_stable(hcx, hasher);
835 // Nothing more to hash.
838 int_ty.hash_stable(hcx, hasher);
841 uint_ty.hash_stable(hcx, hasher);
844 float_ty.hash_stable(hcx, hasher);
846 Adt(adt_def, substs) => {
847 adt_def.hash_stable(hcx, hasher);
848 substs.hash_stable(hcx, hasher);
850 Array(inner_ty, len) => {
851 inner_ty.hash_stable(hcx, hasher);
852 len.hash_stable(hcx, hasher);
855 inner_ty.hash_stable(hcx, hasher);
857 RawPtr(pointee_ty) => {
858 pointee_ty.hash_stable(hcx, hasher);
860 Ref(region, pointee_ty, mutbl) => {
861 region.hash_stable(hcx, hasher);
862 pointee_ty.hash_stable(hcx, hasher);
863 mutbl.hash_stable(hcx, hasher);
865 FnDef(def_id, substs) => {
866 def_id.hash_stable(hcx, hasher);
867 substs.hash_stable(hcx, hasher);
870 sig.hash_stable(hcx, hasher);
872 Dynamic(ref existential_predicates, region) => {
873 existential_predicates.hash_stable(hcx, hasher);
874 region.hash_stable(hcx, hasher);
876 Closure(def_id, closure_substs) => {
877 def_id.hash_stable(hcx, hasher);
878 closure_substs.hash_stable(hcx, hasher);
880 Generator(def_id, generator_substs, movability) => {
881 def_id.hash_stable(hcx, hasher);
882 generator_substs.hash_stable(hcx, hasher);
883 movability.hash_stable(hcx, hasher);
885 GeneratorWitness(types) => {
886 types.hash_stable(hcx, hasher)
888 Tuple(inner_tys) => {
889 inner_tys.hash_stable(hcx, hasher);
891 Projection(ref data) | UnnormalizedProjection(ref data) => {
892 data.hash_stable(hcx, hasher);
894 Opaque(def_id, substs) => {
895 def_id.hash_stable(hcx, hasher);
896 substs.hash_stable(hcx, hasher);
899 param_ty.hash_stable(hcx, hasher);
902 def_id.hash_stable(hcx, hasher);
905 infer_ty.hash_stable(hcx, hasher);
911 impl_stable_hash_for!(enum ty::InferTy {
921 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
924 fn hash_stable<W: StableHasherResult>(&self,
925 _hcx: &mut StableHashingContext<'a>,
926 _hasher: &mut StableHasher<W>) {
927 // TyVid values are confined to an inference context and hence
928 // should not be hashed.
929 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
933 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
936 fn hash_stable<W: StableHasherResult>(&self,
937 _hcx: &mut StableHashingContext<'a>,
938 _hasher: &mut StableHasher<W>) {
939 // IntVid values are confined to an inference context and hence
940 // should not be hashed.
941 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
945 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
948 fn hash_stable<W: StableHasherResult>(&self,
949 _hcx: &mut StableHashingContext<'a>,
950 _hasher: &mut StableHasher<W>) {
951 // FloatVid values are confined to an inference context and hence
952 // should not be hashed.
953 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
957 impl_stable_hash_for!(struct ty::ParamTy {
962 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
967 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
968 for ty::ExistentialPredicate<'gcx>
970 fn hash_stable<W: StableHasherResult>(&self,
971 hcx: &mut StableHashingContext<'a>,
972 hasher: &mut StableHasher<W>) {
973 mem::discriminant(self).hash_stable(hcx, hasher);
975 ty::ExistentialPredicate::Trait(ref trait_ref) => {
976 trait_ref.hash_stable(hcx, hasher);
978 ty::ExistentialPredicate::Projection(ref projection) => {
979 projection.hash_stable(hcx, hasher);
981 ty::ExistentialPredicate::AutoTrait(def_id) => {
982 def_id.hash_stable(hcx, hasher);
988 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
993 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
999 impl_stable_hash_for!(struct ty::Instance<'tcx> {
1004 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
1005 fn hash_stable<W: StableHasherResult>(&self,
1006 hcx: &mut StableHashingContext<'a>,
1007 hasher: &mut StableHasher<W>) {
1008 mem::discriminant(self).hash_stable(hcx, hasher);
1011 ty::InstanceDef::Item(def_id) => {
1012 def_id.hash_stable(hcx, hasher);
1014 ty::InstanceDef::Intrinsic(def_id) => {
1015 def_id.hash_stable(hcx, hasher);
1017 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1018 def_id.hash_stable(hcx, hasher);
1019 ty.hash_stable(hcx, hasher);
1021 ty::InstanceDef::Virtual(def_id, n) => {
1022 def_id.hash_stable(hcx, hasher);
1023 n.hash_stable(hcx, hasher);
1025 ty::InstanceDef::ClosureOnceShim { call_once } => {
1026 call_once.hash_stable(hcx, hasher);
1028 ty::InstanceDef::DropGlue(def_id, ty) => {
1029 def_id.hash_stable(hcx, hasher);
1030 ty.hash_stable(hcx, hasher);
1032 ty::InstanceDef::CloneShim(def_id, ty) => {
1033 def_id.hash_stable(hcx, hasher);
1034 ty.hash_stable(hcx, hasher);
1040 impl_stable_hash_for!(struct ty::TraitDef {
1041 // We already have the def_path_hash below, no need to hash it twice
1050 impl_stable_hash_for!(struct ty::Destructor {
1054 impl_stable_hash_for!(struct ty::CrateVariancesMap {
1056 // This is just an irrelevant helper value.
1057 empty_variance -> _,
1060 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
1062 // This is just an irrelevant helper value.
1063 empty_predicate -> _,
1066 impl_stable_hash_for!(struct ty::AssociatedItem {
1068 ident -> (ident.name),
1073 method_has_self_argument
1076 impl_stable_hash_for!(enum ty::AssociatedKind {
1083 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1084 TraitContainer(def_id),
1085 ImplContainer(def_id)
1089 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1090 for ty::steal::Steal<T>
1091 where T: HashStable<StableHashingContext<'a>>
1093 fn hash_stable<W: StableHasherResult>(&self,
1094 hcx: &mut StableHashingContext<'a>,
1095 hasher: &mut StableHasher<W>) {
1096 self.borrow().hash_stable(hcx, hasher);
1100 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1105 impl_stable_hash_for!(enum traits::Reveal {
1110 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1111 ReachableFromImplTrait,
1117 impl<'a> HashStable<StableHashingContext<'a>>
1118 for ::middle::privacy::AccessLevels {
1119 fn hash_stable<W: StableHasherResult>(&self,
1120 hcx: &mut StableHashingContext<'a>,
1121 hasher: &mut StableHasher<W>) {
1122 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1123 let ::middle::privacy::AccessLevels {
1127 map.hash_stable(hcx, hasher);
1132 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1136 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1138 Errored(error_reported)
1141 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1143 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1147 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1148 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1149 fn hash_stable<W: StableHasherResult>(&self,
1150 hcx: &mut StableHashingContext<'a>,
1151 hasher: &mut StableHasher<W>) {
1152 use traits::Vtable::*;
1154 mem::discriminant(self).hash_stable(hcx, hasher);
1157 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1158 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1159 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1160 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1161 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1162 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1163 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1164 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1169 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1170 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1171 fn hash_stable<W: StableHasherResult>(&self,
1172 hcx: &mut StableHashingContext<'a>,
1173 hasher: &mut StableHasher<W>) {
1174 let traits::VtableImplData {
1179 impl_def_id.hash_stable(hcx, hasher);
1180 substs.hash_stable(hcx, hasher);
1181 nested.hash_stable(hcx, hasher);
1185 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1186 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1187 fn hash_stable<W: StableHasherResult>(&self,
1188 hcx: &mut StableHashingContext<'a>,
1189 hasher: &mut StableHasher<W>) {
1190 let traits::VtableAutoImplData {
1194 trait_def_id.hash_stable(hcx, hasher);
1195 nested.hash_stable(hcx, hasher);
1199 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1200 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1201 fn hash_stable<W: StableHasherResult>(&self,
1202 hcx: &mut StableHashingContext<'a>,
1203 hasher: &mut StableHasher<W>) {
1204 let traits::VtableObjectData {
1209 upcast_trait_ref.hash_stable(hcx, hasher);
1210 vtable_base.hash_stable(hcx, hasher);
1211 nested.hash_stable(hcx, hasher);
1215 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1216 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1217 fn hash_stable<W: StableHasherResult>(&self,
1218 hcx: &mut StableHashingContext<'a>,
1219 hasher: &mut StableHasher<W>) {
1220 let traits::VtableBuiltinData {
1223 nested.hash_stable(hcx, hasher);
1227 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1228 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1229 fn hash_stable<W: StableHasherResult>(&self,
1230 hcx: &mut StableHashingContext<'a>,
1231 hasher: &mut StableHasher<W>) {
1232 let traits::VtableClosureData {
1237 closure_def_id.hash_stable(hcx, hasher);
1238 substs.hash_stable(hcx, hasher);
1239 nested.hash_stable(hcx, hasher);
1243 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1244 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1245 fn hash_stable<W: StableHasherResult>(&self,
1246 hcx: &mut StableHashingContext<'a>,
1247 hasher: &mut StableHasher<W>) {
1248 let traits::VtableFnPointerData {
1252 fn_ty.hash_stable(hcx, hasher);
1253 nested.hash_stable(hcx, hasher);
1257 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1258 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1259 fn hash_stable<W: StableHasherResult>(&self,
1260 hcx: &mut StableHashingContext<'a>,
1261 hasher: &mut StableHasher<W>) {
1262 let traits::VtableGeneratorData {
1267 generator_def_id.hash_stable(hcx, hasher);
1268 substs.hash_stable(hcx, hasher);
1269 nested.hash_stable(hcx, hasher);
1273 impl_stable_hash_for!(
1274 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1279 impl_stable_hash_for!(
1280 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1285 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1289 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1294 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1300 impl_stable_hash_for!(
1301 impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
1302 var_values, region_constraints, certainty, value
1306 impl_stable_hash_for!(enum infer::canonical::Certainty {
1310 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1311 fn hash_stable<W: StableHasherResult>(&self,
1312 hcx: &mut StableHashingContext<'a>,
1313 hasher: &mut StableHasher<W>) {
1314 use traits::WhereClause::*;
1316 mem::discriminant(self).hash_stable(hcx, hasher);
1318 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1319 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1320 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1321 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1326 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1327 fn hash_stable<W: StableHasherResult>(&self,
1328 hcx: &mut StableHashingContext<'a>,
1329 hasher: &mut StableHasher<W>) {
1330 use traits::WellFormed::*;
1332 mem::discriminant(self).hash_stable(hcx, hasher);
1334 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1335 Ty(ty) => ty.hash_stable(hcx, hasher),
1340 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1341 fn hash_stable<W: StableHasherResult>(&self,
1342 hcx: &mut StableHashingContext<'a>,
1343 hasher: &mut StableHasher<W>) {
1344 use traits::FromEnv::*;
1346 mem::discriminant(self).hash_stable(hcx, hasher);
1348 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1349 Ty(ty) => ty.hash_stable(hcx, hasher),
1354 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1355 fn hash_stable<W: StableHasherResult>(&self,
1356 hcx: &mut StableHashingContext<'a>,
1357 hasher: &mut StableHasher<W>) {
1358 use traits::DomainGoal::*;
1360 mem::discriminant(self).hash_stable(hcx, hasher);
1362 Holds(wc) => wc.hash_stable(hcx, hasher),
1363 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1364 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1365 Normalize(projection) => projection.hash_stable(hcx, hasher),
1370 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1371 fn hash_stable<W: StableHasherResult>(&self,
1372 hcx: &mut StableHashingContext<'a>,
1373 hasher: &mut StableHasher<W>) {
1374 use traits::GoalKind::*;
1376 mem::discriminant(self).hash_stable(hcx, hasher);
1378 Implies(hypotheses, goal) => {
1379 hypotheses.hash_stable(hcx, hasher);
1380 goal.hash_stable(hcx, hasher);
1382 And(goal1, goal2) => {
1383 goal1.hash_stable(hcx, hasher);
1384 goal2.hash_stable(hcx, hasher);
1386 Not(goal) => goal.hash_stable(hcx, hasher),
1387 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1388 Quantified(quantifier, goal) => {
1389 quantifier.hash_stable(hcx, hasher);
1390 goal.hash_stable(hcx, hasher);
1397 impl_stable_hash_for!(
1398 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1399 goal, hypotheses, category
1403 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1409 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1410 fn hash_stable<W: StableHasherResult>(&self,
1411 hcx: &mut StableHashingContext<'a>,
1412 hasher: &mut StableHasher<W>) {
1413 use traits::Clause::*;
1415 mem::discriminant(self).hash_stable(hcx, hasher);
1417 Implies(clause) => clause.hash_stable(hcx, hasher),
1418 ForAll(clause) => clause.hash_stable(hcx, hasher),
1423 impl_stable_hash_for!(enum traits::QuantifierKind {
1428 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1430 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1432 impl_stable_hash_for!(
1433 impl<'tcx> for struct traits::Environment<'tcx> {