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::ReLateBound(db, ty::BrAnon(i)) => {
104 db.hash_stable(hcx, hasher);
105 i.hash_stable(hcx, hasher);
107 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
108 db.hash_stable(hcx, hasher);
109 def_id.hash_stable(hcx, hasher);
110 name.hash_stable(hcx, hasher);
112 ty::ReLateBound(db, ty::BrEnv) => {
113 db.hash_stable(hcx, hasher);
115 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
116 def_id.hash_stable(hcx, hasher);
117 index.hash_stable(hcx, hasher);
118 name.hash_stable(hcx, hasher);
120 ty::ReScope(scope) => {
121 scope.hash_stable(hcx, hasher);
123 ty::ReFree(ref free_region) => {
124 free_region.hash_stable(hcx, hasher);
126 ty::ReClosureBound(vid) => {
127 vid.hash_stable(hcx, hasher);
129 ty::ReLateBound(..) |
131 ty::RePlaceholder(..) => {
132 bug!("StableHasher: unexpected region {:?}", *self)
138 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
140 fn hash_stable<W: StableHasherResult>(&self,
141 hcx: &mut StableHashingContext<'a>,
142 hasher: &mut StableHasher<W>) {
143 self.index().hash_stable(hcx, hasher);
147 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundVar {
149 fn hash_stable<W: StableHasherResult>(&self,
150 hcx: &mut StableHashingContext<'gcx>,
151 hasher: &mut StableHasher<W>) {
152 self.index().hash_stable(hcx, hasher);
156 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
157 for ty::adjustment::AutoBorrow<'gcx> {
158 fn hash_stable<W: StableHasherResult>(&self,
159 hcx: &mut StableHashingContext<'a>,
160 hasher: &mut StableHasher<W>) {
161 mem::discriminant(self).hash_stable(hcx, hasher);
163 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
164 region.hash_stable(hcx, hasher);
165 mutability.hash_stable(hcx, hasher);
167 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
168 mutability.hash_stable(hcx, hasher);
174 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
175 for ty::adjustment::Adjust<'gcx> {
176 fn hash_stable<W: StableHasherResult>(&self,
177 hcx: &mut StableHashingContext<'a>,
178 hasher: &mut StableHasher<W>) {
179 mem::discriminant(self).hash_stable(hcx, hasher);
181 ty::adjustment::Adjust::NeverToAny |
182 ty::adjustment::Adjust::ReifyFnPointer |
183 ty::adjustment::Adjust::UnsafeFnPointer |
184 ty::adjustment::Adjust::ClosureFnPointer |
185 ty::adjustment::Adjust::MutToConstPointer |
186 ty::adjustment::Adjust::Unsize => {}
187 ty::adjustment::Adjust::Deref(ref overloaded) => {
188 overloaded.hash_stable(hcx, hasher);
190 ty::adjustment::Adjust::Borrow(ref autoref) => {
191 autoref.hash_stable(hcx, hasher);
197 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
198 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
199 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
200 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
205 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
206 fn hash_stable<W: StableHasherResult>(&self,
207 hcx: &mut StableHashingContext<'gcx>,
208 hasher: &mut StableHasher<W>) {
209 mem::discriminant(self).hash_stable(hcx, hasher);
211 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
212 allow_two_phase_borrow.hash_stable(hcx, hasher);
214 ty::adjustment::AutoBorrowMutability::Immutable => {}
219 impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
221 impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
223 impl_stable_hash_for!(enum ty::BorrowKind {
229 impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] {
231 ByRef(up_var_borrow),
234 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
239 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
246 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
247 where T: HashStable<StableHashingContext<'a>>
249 fn hash_stable<W: StableHasherResult>(&self,
250 hcx: &mut StableHashingContext<'a>,
251 hasher: &mut StableHasher<W>) {
252 self.skip_binder().hash_stable(hcx, hasher);
256 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
258 impl_stable_hash_for!(enum ty::Visibility {
264 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
265 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
266 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
267 impl_stable_hash_for!(impl<A, B> for tuple_struct ty::OutlivesPredicate<A, B> { a, b });
268 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
269 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
271 impl_stable_hash_for!(
272 impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] {
275 RegionOutlives(pred),
280 ClosureKind(def_id, closure_substs, closure_kind),
281 ConstEvaluatable(def_id, substs),
285 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
286 fn hash_stable<W: StableHasherResult>(&self,
287 _: &mut StableHashingContext<'a>,
288 hasher: &mut StableHasher<W>) {
289 std_hash::Hash::hash(self, hasher);
293 impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
294 fn hash_stable<W: StableHasherResult>(&self,
295 _: &mut StableHashingContext<'a>,
296 hasher: &mut StableHasher<W>) {
297 std_hash::Hash::hash(self, hasher);
301 impl_stable_hash_for!(enum ty::VariantDiscr {
306 impl_stable_hash_for!(struct ty::FieldDef {
308 ident -> (ident.name),
312 impl_stable_hash_for!(
313 impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
314 Unevaluated(def_id, substs),
317 ByRef(id, alloc, offset),
321 impl_stable_hash_for! {
322 impl<Tag> for struct mir::interpret::Pointer<Tag> {
329 impl_stable_hash_for!(
330 impl<Tag> for enum mir::interpret::Scalar<Tag> [ mir::interpret::Scalar ] {
336 impl_stable_hash_for!(
337 impl<'tcx, M> for enum mir::interpret::AllocType<'tcx, M> [ mir::interpret::AllocType ] {
344 // AllocIds get resolved to whatever they point to (to be stable)
345 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
346 fn hash_stable<W: StableHasherResult>(
348 hcx: &mut StableHashingContext<'a>,
349 hasher: &mut StableHasher<W>,
351 ty::tls::with_opt(|tcx| {
352 trace!("hashing {:?}", *self);
353 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
354 let alloc_kind = tcx.alloc_map.lock().get(*self);
355 alloc_kind.hash_stable(hcx, hasher);
360 // Allocations treat their relocations specially
361 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
362 fn hash_stable<W: StableHasherResult>(
364 hcx: &mut StableHashingContext<'a>,
365 hasher: &mut StableHasher<W>,
367 self.bytes.hash_stable(hcx, hasher);
368 for reloc in self.relocations.iter() {
369 reloc.hash_stable(hcx, hasher);
371 self.undef_mask.hash_stable(hcx, hasher);
372 self.align.hash_stable(hcx, hasher);
373 self.mutability.hash_stable(hcx, hasher);
377 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
382 impl_stable_hash_for!(struct ty::Const<'tcx> {
387 impl_stable_hash_for!(enum mir::interpret::ErrorHandled {
392 impl_stable_hash_for!(struct mir::interpret::FrameInfo<'tcx> {
398 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
399 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
401 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
406 impl_stable_hash_for!(
407 impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O>
408 [ mir::interpret::EvalErrorKind ]
410 FunctionArgCountMismatch,
411 DanglingPointerDeref,
414 InvalidFunctionPointer,
416 InvalidNullPointerUsage,
422 StackFrameLimitReached,
425 CalledClosureAsFunction,
426 VtableForArgumentlessMethod,
427 ModifiedConstantMemory,
430 ReallocateNonBasePtr,
431 DeallocateNonBasePtr,
434 ReadFromReturnPointer,
435 UnimplementedTraitSelection,
438 DerefFunctionPointer,
443 GeneratorResumedAfterReturn,
444 GeneratorResumedAfterPanic,
447 ReadUndefBytes(offset),
448 InvalidDiscriminant(val),
449 Panic { msg, file, line, col },
451 FunctionAbiMismatch(a, b),
452 FunctionArgMismatch(a, b),
453 FunctionRetMismatch(a, b),
455 UnterminatedCString(ptr),
456 PointerOutOfBounds { ptr, check, allocation_size },
459 BoundsCheck { len, index },
463 AlignmentCheckFailed { required, has },
464 ValidationFailure(s),
465 TypeNotPrimitive(ty),
466 ReallocatedWrongMemoryKind(a, b),
467 DeallocatedWrongMemoryKind(a, b),
468 IncorrectAllocationInformation(a, b, c, d),
470 HeapAllocNonPowerOfTwoAlignment(n),
476 impl_stable_hash_for!(enum mir::interpret::InboundsCheck {
481 impl_stable_hash_for!(enum mir::interpret::Lock {
487 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
492 impl_stable_hash_for!(enum mir::interpret::AccessKind {
497 impl_stable_hash_for!(enum ty::Variance {
504 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
508 impl_stable_hash_for!(struct ty::Generics {
512 // Reverse map to each param's `index` field, from its `def_id`.
513 param_def_id_to_index -> _, // Don't hash this
515 has_late_bound_regions,
518 impl_stable_hash_for!(struct ty::GenericParamDef {
526 impl_stable_hash_for!(enum ty::GenericParamDefKind {
528 Type { has_default, object_lifetime_default, synthetic },
531 impl_stable_hash_for!(
532 impl<T> for enum ::middle::resolve_lifetime::Set1<T> [ ::middle::resolve_lifetime::Set1 ] {
539 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
545 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
547 EarlyBound(index, decl, is_in_band),
548 LateBound(db_index, decl, is_in_band),
549 LateBoundAnon(db_index, anon_index),
550 Free(call_site_scope_data, decl)
553 impl_stable_hash_for!(enum ty::cast::CastKind {
567 impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
569 impl_stable_hash_for!(enum ::middle::region::ScopeData {
574 Remainder(first_statement_index)
577 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
578 type KeyType = region::Scope;
581 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
586 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
590 impl_stable_hash_for!(struct ty::FreeRegion {
595 impl_stable_hash_for!(enum ty::BoundRegion {
597 BrNamed(def_id, name),
602 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
605 fn hash_stable<W: StableHasherResult>(&self,
606 hcx: &mut StableHashingContext<'a>,
607 hasher: &mut StableHasher<W>) {
610 mem::discriminant(self).hash_stable(hcx, hasher);
617 // Nothing more to hash.
620 int_ty.hash_stable(hcx, hasher);
623 uint_ty.hash_stable(hcx, hasher);
626 float_ty.hash_stable(hcx, hasher);
628 Adt(adt_def, substs) => {
629 adt_def.hash_stable(hcx, hasher);
630 substs.hash_stable(hcx, hasher);
632 Array(inner_ty, len) => {
633 inner_ty.hash_stable(hcx, hasher);
634 len.hash_stable(hcx, hasher);
637 inner_ty.hash_stable(hcx, hasher);
639 RawPtr(pointee_ty) => {
640 pointee_ty.hash_stable(hcx, hasher);
642 Ref(region, pointee_ty, mutbl) => {
643 region.hash_stable(hcx, hasher);
644 pointee_ty.hash_stable(hcx, hasher);
645 mutbl.hash_stable(hcx, hasher);
647 FnDef(def_id, substs) => {
648 def_id.hash_stable(hcx, hasher);
649 substs.hash_stable(hcx, hasher);
652 sig.hash_stable(hcx, hasher);
654 Dynamic(ref existential_predicates, region) => {
655 existential_predicates.hash_stable(hcx, hasher);
656 region.hash_stable(hcx, hasher);
658 Closure(def_id, closure_substs) => {
659 def_id.hash_stable(hcx, hasher);
660 closure_substs.hash_stable(hcx, hasher);
662 Generator(def_id, generator_substs, movability) => {
663 def_id.hash_stable(hcx, hasher);
664 generator_substs.hash_stable(hcx, hasher);
665 movability.hash_stable(hcx, hasher);
667 GeneratorWitness(types) => {
668 types.hash_stable(hcx, hasher)
670 Tuple(inner_tys) => {
671 inner_tys.hash_stable(hcx, hasher);
673 Projection(ref data) | UnnormalizedProjection(ref data) => {
674 data.hash_stable(hcx, hasher);
676 Opaque(def_id, substs) => {
677 def_id.hash_stable(hcx, hasher);
678 substs.hash_stable(hcx, hasher);
681 param_ty.hash_stable(hcx, hasher);
684 bound_ty.hash_stable(hcx, hasher);
687 def_id.hash_stable(hcx, hasher);
690 infer_ty.hash_stable(hcx, hasher);
696 impl_stable_hash_for!(enum ty::InferTy {
705 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
708 fn hash_stable<W: StableHasherResult>(&self,
709 _hcx: &mut StableHashingContext<'a>,
710 _hasher: &mut StableHasher<W>) {
711 // TyVid values are confined to an inference context and hence
712 // should not be hashed.
713 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
717 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
720 fn hash_stable<W: StableHasherResult>(&self,
721 _hcx: &mut StableHashingContext<'a>,
722 _hasher: &mut StableHasher<W>) {
723 // IntVid values are confined to an inference context and hence
724 // should not be hashed.
725 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
729 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
732 fn hash_stable<W: StableHasherResult>(&self,
733 _hcx: &mut StableHashingContext<'a>,
734 _hasher: &mut StableHasher<W>) {
735 // FloatVid values are confined to an inference context and hence
736 // should not be hashed.
737 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
741 impl_stable_hash_for!(struct ty::ParamTy {
746 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
751 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
752 for ty::ExistentialPredicate<'gcx>
754 fn hash_stable<W: StableHasherResult>(&self,
755 hcx: &mut StableHashingContext<'a>,
756 hasher: &mut StableHasher<W>) {
757 mem::discriminant(self).hash_stable(hcx, hasher);
759 ty::ExistentialPredicate::Trait(ref trait_ref) => {
760 trait_ref.hash_stable(hcx, hasher);
762 ty::ExistentialPredicate::Projection(ref projection) => {
763 projection.hash_stable(hcx, hasher);
765 ty::ExistentialPredicate::AutoTrait(def_id) => {
766 def_id.hash_stable(hcx, hasher);
772 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
777 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
783 impl_stable_hash_for!(struct ty::Instance<'tcx> {
788 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
789 fn hash_stable<W: StableHasherResult>(&self,
790 hcx: &mut StableHashingContext<'a>,
791 hasher: &mut StableHasher<W>) {
792 mem::discriminant(self).hash_stable(hcx, hasher);
795 ty::InstanceDef::Item(def_id) => {
796 def_id.hash_stable(hcx, hasher);
798 ty::InstanceDef::VtableShim(def_id) => {
799 def_id.hash_stable(hcx, hasher);
801 ty::InstanceDef::Intrinsic(def_id) => {
802 def_id.hash_stable(hcx, hasher);
804 ty::InstanceDef::FnPtrShim(def_id, ty) => {
805 def_id.hash_stable(hcx, hasher);
806 ty.hash_stable(hcx, hasher);
808 ty::InstanceDef::Virtual(def_id, n) => {
809 def_id.hash_stable(hcx, hasher);
810 n.hash_stable(hcx, hasher);
812 ty::InstanceDef::ClosureOnceShim { call_once } => {
813 call_once.hash_stable(hcx, hasher);
815 ty::InstanceDef::DropGlue(def_id, ty) => {
816 def_id.hash_stable(hcx, hasher);
817 ty.hash_stable(hcx, hasher);
819 ty::InstanceDef::CloneShim(def_id, ty) => {
820 def_id.hash_stable(hcx, hasher);
821 ty.hash_stable(hcx, hasher);
827 impl_stable_hash_for!(struct ty::TraitDef {
828 // We already have the def_path_hash below, no need to hash it twice
837 impl_stable_hash_for!(struct ty::Destructor {
841 impl_stable_hash_for!(struct ty::CrateVariancesMap {
843 // This is just an irrelevant helper value.
847 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
849 // This is just an irrelevant helper value.
850 empty_predicate -> _,
853 impl_stable_hash_for!(struct ty::AssociatedItem {
855 ident -> (ident.name),
860 method_has_self_argument
863 impl_stable_hash_for!(enum ty::AssociatedKind {
870 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
871 TraitContainer(def_id),
872 ImplContainer(def_id)
876 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
877 for ty::steal::Steal<T>
878 where T: HashStable<StableHashingContext<'a>>
880 fn hash_stable<W: StableHasherResult>(&self,
881 hcx: &mut StableHashingContext<'a>,
882 hasher: &mut StableHasher<W>) {
883 self.borrow().hash_stable(hcx, hasher);
887 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
892 impl_stable_hash_for!(enum traits::Reveal {
897 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
898 ReachableFromImplTrait,
904 impl<'a> HashStable<StableHashingContext<'a>>
905 for ::middle::privacy::AccessLevels {
906 fn hash_stable<W: StableHasherResult>(&self,
907 hcx: &mut StableHashingContext<'a>,
908 hasher: &mut StableHasher<W>) {
909 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
910 let ::middle::privacy::AccessLevels {
914 map.hash_stable(hcx, hasher);
919 impl_stable_hash_for!(struct ty::CrateInherentImpls {
923 impl_stable_hash_for!(enum ::session::CompileIncomplete {
925 Errored(error_reported)
928 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
930 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
934 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
935 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
936 fn hash_stable<W: StableHasherResult>(&self,
937 hcx: &mut StableHashingContext<'a>,
938 hasher: &mut StableHasher<W>) {
939 use traits::Vtable::*;
941 mem::discriminant(self).hash_stable(hcx, hasher);
944 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
945 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
946 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
947 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
948 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
949 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
950 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
951 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
952 &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher),
957 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
958 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
959 fn hash_stable<W: StableHasherResult>(&self,
960 hcx: &mut StableHashingContext<'a>,
961 hasher: &mut StableHasher<W>) {
962 let traits::VtableImplData {
967 impl_def_id.hash_stable(hcx, hasher);
968 substs.hash_stable(hcx, hasher);
969 nested.hash_stable(hcx, hasher);
973 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
974 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
975 fn hash_stable<W: StableHasherResult>(&self,
976 hcx: &mut StableHashingContext<'a>,
977 hasher: &mut StableHasher<W>) {
978 let traits::VtableAutoImplData {
982 trait_def_id.hash_stable(hcx, hasher);
983 nested.hash_stable(hcx, hasher);
987 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
988 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
989 fn hash_stable<W: StableHasherResult>(&self,
990 hcx: &mut StableHashingContext<'a>,
991 hasher: &mut StableHasher<W>) {
992 let traits::VtableObjectData {
997 upcast_trait_ref.hash_stable(hcx, hasher);
998 vtable_base.hash_stable(hcx, hasher);
999 nested.hash_stable(hcx, hasher);
1003 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1004 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1005 fn hash_stable<W: StableHasherResult>(&self,
1006 hcx: &mut StableHashingContext<'a>,
1007 hasher: &mut StableHasher<W>) {
1008 let traits::VtableBuiltinData {
1011 nested.hash_stable(hcx, hasher);
1015 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1016 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1017 fn hash_stable<W: StableHasherResult>(&self,
1018 hcx: &mut StableHashingContext<'a>,
1019 hasher: &mut StableHasher<W>) {
1020 let traits::VtableClosureData {
1025 closure_def_id.hash_stable(hcx, hasher);
1026 substs.hash_stable(hcx, hasher);
1027 nested.hash_stable(hcx, hasher);
1031 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1032 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1033 fn hash_stable<W: StableHasherResult>(&self,
1034 hcx: &mut StableHashingContext<'a>,
1035 hasher: &mut StableHasher<W>) {
1036 let traits::VtableFnPointerData {
1040 fn_ty.hash_stable(hcx, hasher);
1041 nested.hash_stable(hcx, hasher);
1045 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1046 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1047 fn hash_stable<W: StableHasherResult>(&self,
1048 hcx: &mut StableHashingContext<'a>,
1049 hasher: &mut StableHasher<W>) {
1050 let traits::VtableGeneratorData {
1055 generator_def_id.hash_stable(hcx, hasher);
1056 substs.hash_stable(hcx, hasher);
1057 nested.hash_stable(hcx, hasher);
1061 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1062 for traits::VtableTraitAliasData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1063 fn hash_stable<W: StableHasherResult>(&self,
1064 hcx: &mut StableHashingContext<'a>,
1065 hasher: &mut StableHasher<W>) {
1066 let traits::VtableTraitAliasData {
1071 alias_def_id.hash_stable(hcx, hasher);
1072 substs.hash_stable(hcx, hasher);
1073 nested.hash_stable(hcx, hasher);
1077 impl_stable_hash_for!(
1078 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1079 max_universe, variables, value
1083 impl_stable_hash_for!(
1084 struct infer::canonical::CanonicalVarValues<'tcx> {
1089 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1093 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1096 PlaceholderRegion(placeholder),
1099 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1105 impl_stable_hash_for!(
1106 impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
1107 var_values, region_constraints, certainty, value
1111 impl_stable_hash_for!(enum infer::canonical::Certainty {
1115 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1116 fn hash_stable<W: StableHasherResult>(&self,
1117 hcx: &mut StableHashingContext<'a>,
1118 hasher: &mut StableHasher<W>) {
1119 use traits::WhereClause::*;
1121 mem::discriminant(self).hash_stable(hcx, hasher);
1123 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1124 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1125 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1126 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1131 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1132 fn hash_stable<W: StableHasherResult>(&self,
1133 hcx: &mut StableHashingContext<'a>,
1134 hasher: &mut StableHasher<W>) {
1135 use traits::WellFormed::*;
1137 mem::discriminant(self).hash_stable(hcx, hasher);
1139 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1140 Ty(ty) => ty.hash_stable(hcx, hasher),
1145 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1146 fn hash_stable<W: StableHasherResult>(&self,
1147 hcx: &mut StableHashingContext<'a>,
1148 hasher: &mut StableHasher<W>) {
1149 use traits::FromEnv::*;
1151 mem::discriminant(self).hash_stable(hcx, hasher);
1153 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1154 Ty(ty) => ty.hash_stable(hcx, hasher),
1159 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1160 fn hash_stable<W: StableHasherResult>(&self,
1161 hcx: &mut StableHashingContext<'a>,
1162 hasher: &mut StableHasher<W>) {
1163 use traits::DomainGoal::*;
1165 mem::discriminant(self).hash_stable(hcx, hasher);
1167 Holds(wc) => wc.hash_stable(hcx, hasher),
1168 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1169 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1170 Normalize(projection) => projection.hash_stable(hcx, hasher),
1175 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1176 fn hash_stable<W: StableHasherResult>(&self,
1177 hcx: &mut StableHashingContext<'a>,
1178 hasher: &mut StableHasher<W>) {
1179 use traits::GoalKind::*;
1181 mem::discriminant(self).hash_stable(hcx, hasher);
1183 Implies(hypotheses, goal) => {
1184 hypotheses.hash_stable(hcx, hasher);
1185 goal.hash_stable(hcx, hasher);
1187 And(goal1, goal2) => {
1188 goal1.hash_stable(hcx, hasher);
1189 goal2.hash_stable(hcx, hasher);
1191 Not(goal) => goal.hash_stable(hcx, hasher),
1192 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1193 Quantified(quantifier, goal) => {
1194 quantifier.hash_stable(hcx, hasher);
1195 goal.hash_stable(hcx, hasher);
1202 impl_stable_hash_for!(
1203 struct traits::ProgramClause<'tcx> {
1204 goal, hypotheses, category
1208 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1214 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1215 fn hash_stable<W: StableHasherResult>(&self,
1216 hcx: &mut StableHashingContext<'a>,
1217 hasher: &mut StableHasher<W>) {
1218 use traits::Clause::*;
1220 mem::discriminant(self).hash_stable(hcx, hasher);
1222 Implies(clause) => clause.hash_stable(hcx, hasher),
1223 ForAll(clause) => clause.hash_stable(hcx, hasher),
1228 impl_stable_hash_for!(enum traits::QuantifierKind {
1233 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1235 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1237 impl_stable_hash_for!(
1238 struct traits::Environment<'tcx> {