1 //! This module contains `HashStable` implementations for various data types
2 //! from rustc::ty in no particular order.
4 use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
5 use rustc_data_structures::fx::FxHashMap;
6 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
7 StableHasher, StableHasherResult};
8 use std::cell::RefCell;
9 use std::hash as std_hash;
11 use crate::middle::region;
17 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
19 where T: HashStable<StableHashingContext<'a>> {
20 fn hash_stable<W: StableHasherResult>(&self,
21 hcx: &mut StableHashingContext<'a>,
22 hasher: &mut StableHasher<W>) {
24 static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
25 RefCell::new(Default::default());
28 let hash = CACHE.with(|cache| {
29 let key = (self.as_ptr() as usize, self.len());
30 if let Some(&hash) = cache.borrow().get(&key) {
34 let mut hasher = StableHasher::new();
35 (&self[..]).hash_stable(hcx, &mut hasher);
37 let hash: Fingerprint = hasher.finish();
38 cache.borrow_mut().insert(key, hash);
42 hash.hash_stable(hcx, hasher);
46 impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T>
47 where T: HashStable<StableHashingContext<'a>>
49 type KeyType = Fingerprint;
52 fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
53 let mut hasher = StableHasher::new();
54 let mut hcx: StableHashingContext<'a> = hcx.clone();
55 self.hash_stable(&mut hcx, &mut hasher);
60 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
61 fn hash_stable<W: StableHasherResult>(&self,
62 hcx: &mut StableHashingContext<'a>,
63 hasher: &mut StableHasher<W>) {
64 self.unpack().hash_stable(hcx, hasher);
68 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
69 for ty::subst::UnpackedKind<'gcx> {
70 fn hash_stable<W: StableHasherResult>(&self,
71 hcx: &mut StableHashingContext<'a>,
72 hasher: &mut StableHasher<W>) {
73 mem::discriminant(self).hash_stable(hcx, hasher);
75 ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
76 ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
81 impl<'a> HashStable<StableHashingContext<'a>>
83 fn hash_stable<W: StableHasherResult>(&self,
84 hcx: &mut StableHashingContext<'a>,
85 hasher: &mut StableHasher<W>) {
86 mem::discriminant(self).hash_stable(hcx, hasher);
91 // No variant fields to hash for these ...
93 ty::ReLateBound(db, ty::BrAnon(i)) => {
94 db.hash_stable(hcx, hasher);
95 i.hash_stable(hcx, hasher);
97 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
98 db.hash_stable(hcx, hasher);
99 def_id.hash_stable(hcx, hasher);
100 name.hash_stable(hcx, hasher);
102 ty::ReLateBound(db, ty::BrEnv) => {
103 db.hash_stable(hcx, hasher);
105 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
106 def_id.hash_stable(hcx, hasher);
107 index.hash_stable(hcx, hasher);
108 name.hash_stable(hcx, hasher);
110 ty::ReScope(scope) => {
111 scope.hash_stable(hcx, hasher);
113 ty::ReFree(ref free_region) => {
114 free_region.hash_stable(hcx, hasher);
116 ty::ReClosureBound(vid) => {
117 vid.hash_stable(hcx, hasher);
119 ty::ReLateBound(..) |
121 ty::RePlaceholder(..) => {
122 bug!("StableHasher: unexpected region {:?}", *self)
128 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
130 fn hash_stable<W: StableHasherResult>(&self,
131 hcx: &mut StableHashingContext<'a>,
132 hasher: &mut StableHasher<W>) {
133 self.index().hash_stable(hcx, hasher);
137 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundVar {
139 fn hash_stable<W: StableHasherResult>(&self,
140 hcx: &mut StableHashingContext<'gcx>,
141 hasher: &mut StableHasher<W>) {
142 self.index().hash_stable(hcx, hasher);
146 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
147 for ty::adjustment::AutoBorrow<'gcx> {
148 fn hash_stable<W: StableHasherResult>(&self,
149 hcx: &mut StableHashingContext<'a>,
150 hasher: &mut StableHasher<W>) {
151 mem::discriminant(self).hash_stable(hcx, hasher);
153 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
154 region.hash_stable(hcx, hasher);
155 mutability.hash_stable(hcx, hasher);
157 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
158 mutability.hash_stable(hcx, hasher);
164 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
165 for ty::adjustment::Adjust<'gcx> {
166 fn hash_stable<W: StableHasherResult>(&self,
167 hcx: &mut StableHashingContext<'a>,
168 hasher: &mut StableHasher<W>) {
169 mem::discriminant(self).hash_stable(hcx, hasher);
171 ty::adjustment::Adjust::NeverToAny |
172 ty::adjustment::Adjust::ReifyFnPointer |
173 ty::adjustment::Adjust::UnsafeFnPointer |
174 ty::adjustment::Adjust::ClosureFnPointer |
175 ty::adjustment::Adjust::MutToConstPointer |
176 ty::adjustment::Adjust::Unsize => {}
177 ty::adjustment::Adjust::Deref(ref overloaded) => {
178 overloaded.hash_stable(hcx, hasher);
180 ty::adjustment::Adjust::Borrow(ref autoref) => {
181 autoref.hash_stable(hcx, hasher);
187 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
188 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
189 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
190 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
195 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
196 fn hash_stable<W: StableHasherResult>(&self,
197 hcx: &mut StableHashingContext<'gcx>,
198 hasher: &mut StableHasher<W>) {
199 mem::discriminant(self).hash_stable(hcx, hasher);
201 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
202 allow_two_phase_borrow.hash_stable(hcx, hasher);
204 ty::adjustment::AutoBorrowMutability::Immutable => {}
209 impl_stable_hash_for!(tuple_struct ty::util::NeedsDrop { value });
211 impl_stable_hash_for!(tuple_struct ty::AdtSizedConstraint<'tcx> { list });
213 impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
215 impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
217 impl_stable_hash_for!(enum ty::BorrowKind {
223 impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] {
225 ByRef(up_var_borrow),
228 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
233 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
240 impl_stable_hash_for!(struct ty::ResolvedOpaqueTy<'tcx> {
245 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
246 where T: HashStable<StableHashingContext<'a>>
248 fn hash_stable<W: StableHasherResult>(&self,
249 hcx: &mut StableHashingContext<'a>,
250 hasher: &mut StableHasher<W>) {
251 self.skip_binder().hash_stable(hcx, hasher);
255 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
257 impl_stable_hash_for!(enum ty::Visibility {
263 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
264 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
265 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
266 impl_stable_hash_for!(impl<A, B> for tuple_struct ty::OutlivesPredicate<A, B> { a, b });
267 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
268 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
270 impl_stable_hash_for!(
271 impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] {
274 RegionOutlives(pred),
279 ClosureKind(def_id, closure_substs, closure_kind),
280 ConstEvaluatable(def_id, substs),
284 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
285 fn hash_stable<W: StableHasherResult>(&self,
286 _: &mut StableHashingContext<'a>,
287 hasher: &mut StableHasher<W>) {
288 std_hash::Hash::hash(self, hasher);
292 impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
293 fn hash_stable<W: StableHasherResult>(&self,
294 _: &mut StableHashingContext<'a>,
295 hasher: &mut StableHasher<W>) {
296 std_hash::Hash::hash(self, hasher);
300 impl_stable_hash_for!(enum ty::VariantDiscr {
305 impl_stable_hash_for!(struct ty::FieldDef {
307 ident -> (ident.name),
311 impl_stable_hash_for!(
312 impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
318 impl_stable_hash_for!(struct crate::mir::interpret::RawConst<'tcx> {
323 impl_stable_hash_for! {
324 impl<Tag> for struct mir::interpret::Pointer<Tag> {
331 impl_stable_hash_for!(
332 impl<Tag> for enum mir::interpret::Scalar<Tag> [ mir::interpret::Scalar ] {
338 impl_stable_hash_for!(
339 impl<'tcx> for enum mir::interpret::AllocKind<'tcx> [ mir::interpret::AllocKind ] {
346 // AllocIds get resolved to whatever they point to (to be stable)
347 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
348 fn hash_stable<W: StableHasherResult>(
350 hcx: &mut StableHashingContext<'a>,
351 hasher: &mut StableHasher<W>,
353 ty::tls::with_opt(|tcx| {
354 trace!("hashing {:?}", *self);
355 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
356 let alloc_kind = tcx.alloc_map.lock().get(*self);
357 alloc_kind.hash_stable(hcx, hasher);
362 // Allocations treat their relocations specially
363 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
364 fn hash_stable<W: StableHasherResult>(
366 hcx: &mut StableHashingContext<'a>,
367 hasher: &mut StableHasher<W>,
369 self.bytes.hash_stable(hcx, hasher);
370 for reloc in self.relocations.iter() {
371 reloc.hash_stable(hcx, hasher);
373 self.undef_mask.hash_stable(hcx, hasher);
374 self.align.hash_stable(hcx, hasher);
375 self.mutability.hash_stable(hcx, hasher);
379 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
384 impl_stable_hash_for!(struct ty::Const<'tcx> {
389 impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] {
390 Unevaluated(did, substs),
394 impl_stable_hash_for!(enum mir::interpret::ErrorHandled {
399 impl_stable_hash_for!(struct mir::interpret::FrameInfo<'tcx> {
405 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
406 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
408 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
413 impl_stable_hash_for!(
414 impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O>
415 [ mir::interpret::EvalErrorKind ]
417 FunctionArgCountMismatch,
418 DanglingPointerDeref,
421 InvalidFunctionPointer,
423 InvalidNullPointerUsage,
429 StackFrameLimitReached,
432 CalledClosureAsFunction,
433 VtableForArgumentlessMethod,
434 ModifiedConstantMemory,
438 ReallocateNonBasePtr,
439 DeallocateNonBasePtr,
442 ReadFromReturnPointer,
443 UnimplementedTraitSelection,
446 DerefFunctionPointer,
451 GeneratorResumedAfterReturn,
452 GeneratorResumedAfterPanic,
455 ReadUndefBytes(offset),
456 InvalidDiscriminant(val),
457 Panic { msg, file, line, col },
459 FunctionAbiMismatch(a, b),
460 FunctionArgMismatch(a, b),
461 FunctionRetMismatch(a, b),
463 UnterminatedCString(ptr),
464 PointerOutOfBounds { ptr, check, allocation_size },
467 BoundsCheck { len, index },
471 AlignmentCheckFailed { required, has },
472 ValidationFailure(s),
473 TypeNotPrimitive(ty),
474 ReallocatedWrongMemoryKind(a, b),
475 DeallocatedWrongMemoryKind(a, b),
476 IncorrectAllocationInformation(a, b, c, d),
478 HeapAllocNonPowerOfTwoAlignment(n),
484 impl_stable_hash_for!(enum mir::interpret::InboundsCheck {
489 impl_stable_hash_for!(enum ty::Variance {
496 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
500 impl_stable_hash_for!(struct ty::Generics {
504 // Reverse map to each param's `index` field, from its `def_id`.
505 param_def_id_to_index -> _, // Don't hash this
507 has_late_bound_regions,
510 impl_stable_hash_for!(struct ty::GenericParamDef {
518 impl_stable_hash_for!(enum ty::GenericParamDefKind {
520 Type { has_default, object_lifetime_default, synthetic },
523 impl_stable_hash_for!(
524 impl<T> for enum crate::middle::resolve_lifetime::Set1<T>
525 [ crate::middle::resolve_lifetime::Set1 ]
533 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::LifetimeDefOrigin {
539 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::Region {
541 EarlyBound(index, decl, is_in_band),
542 LateBound(db_index, decl, is_in_band),
543 LateBoundAnon(db_index, anon_index),
544 Free(call_site_scope_data, decl)
547 impl_stable_hash_for!(enum ty::cast::CastKind {
561 impl_stable_hash_for!(struct crate::middle::region::Scope { id, data });
563 impl_stable_hash_for!(enum crate::middle::region::ScopeData {
568 Remainder(first_statement_index)
571 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
572 type KeyType = region::Scope;
575 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
580 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
584 impl_stable_hash_for!(struct ty::FreeRegion {
589 impl_stable_hash_for!(enum ty::BoundRegion {
591 BrNamed(def_id, name),
596 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
599 fn hash_stable<W: StableHasherResult>(&self,
600 hcx: &mut StableHashingContext<'a>,
601 hasher: &mut StableHasher<W>) {
602 use crate::ty::TyKind::*;
604 mem::discriminant(self).hash_stable(hcx, hasher);
611 // Nothing more to hash.
614 int_ty.hash_stable(hcx, hasher);
617 uint_ty.hash_stable(hcx, hasher);
620 float_ty.hash_stable(hcx, hasher);
622 Adt(adt_def, substs) => {
623 adt_def.hash_stable(hcx, hasher);
624 substs.hash_stable(hcx, hasher);
626 Array(inner_ty, len) => {
627 inner_ty.hash_stable(hcx, hasher);
628 len.hash_stable(hcx, hasher);
631 inner_ty.hash_stable(hcx, hasher);
633 RawPtr(pointee_ty) => {
634 pointee_ty.hash_stable(hcx, hasher);
636 Ref(region, pointee_ty, mutbl) => {
637 region.hash_stable(hcx, hasher);
638 pointee_ty.hash_stable(hcx, hasher);
639 mutbl.hash_stable(hcx, hasher);
641 FnDef(def_id, substs) => {
642 def_id.hash_stable(hcx, hasher);
643 substs.hash_stable(hcx, hasher);
646 sig.hash_stable(hcx, hasher);
648 Dynamic(ref existential_predicates, region) => {
649 existential_predicates.hash_stable(hcx, hasher);
650 region.hash_stable(hcx, hasher);
652 Closure(def_id, closure_substs) => {
653 def_id.hash_stable(hcx, hasher);
654 closure_substs.hash_stable(hcx, hasher);
656 Generator(def_id, generator_substs, movability) => {
657 def_id.hash_stable(hcx, hasher);
658 generator_substs.hash_stable(hcx, hasher);
659 movability.hash_stable(hcx, hasher);
661 GeneratorWitness(types) => {
662 types.hash_stable(hcx, hasher)
664 Tuple(inner_tys) => {
665 inner_tys.hash_stable(hcx, hasher);
667 Projection(ref data) | UnnormalizedProjection(ref data) => {
668 data.hash_stable(hcx, hasher);
670 Opaque(def_id, substs) => {
671 def_id.hash_stable(hcx, hasher);
672 substs.hash_stable(hcx, hasher);
675 param_ty.hash_stable(hcx, hasher);
677 Bound(debruijn, bound_ty) => {
678 debruijn.hash_stable(hcx, hasher);
679 bound_ty.hash_stable(hcx, hasher);
681 ty::Placeholder(placeholder_ty) => {
682 placeholder_ty.hash_stable(hcx, hasher);
685 def_id.hash_stable(hcx, hasher);
688 infer_ty.hash_stable(hcx, hasher);
694 impl_stable_hash_for!(enum ty::InferTy {
703 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
706 fn hash_stable<W: StableHasherResult>(&self,
707 _hcx: &mut StableHashingContext<'a>,
708 _hasher: &mut StableHasher<W>) {
709 // TyVid values are confined to an inference context and hence
710 // should not be hashed.
711 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
715 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
718 fn hash_stable<W: StableHasherResult>(&self,
719 _hcx: &mut StableHashingContext<'a>,
720 _hasher: &mut StableHasher<W>) {
721 // IntVid values are confined to an inference context and hence
722 // should not be hashed.
723 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
727 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
730 fn hash_stable<W: StableHasherResult>(&self,
731 _hcx: &mut StableHashingContext<'a>,
732 _hasher: &mut StableHasher<W>) {
733 // FloatVid values are confined to an inference context and hence
734 // should not be hashed.
735 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
739 impl_stable_hash_for!(struct ty::ParamTy {
744 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
749 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
750 for ty::ExistentialPredicate<'gcx>
752 fn hash_stable<W: StableHasherResult>(&self,
753 hcx: &mut StableHashingContext<'a>,
754 hasher: &mut StableHasher<W>) {
755 mem::discriminant(self).hash_stable(hcx, hasher);
757 ty::ExistentialPredicate::Trait(ref trait_ref) => {
758 trait_ref.hash_stable(hcx, hasher);
760 ty::ExistentialPredicate::Projection(ref projection) => {
761 projection.hash_stable(hcx, hasher);
763 ty::ExistentialPredicate::AutoTrait(def_id) => {
764 def_id.hash_stable(hcx, hasher);
770 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
775 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
781 impl_stable_hash_for!(struct ty::Instance<'tcx> {
786 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
787 fn hash_stable<W: StableHasherResult>(&self,
788 hcx: &mut StableHashingContext<'a>,
789 hasher: &mut StableHasher<W>) {
790 mem::discriminant(self).hash_stable(hcx, hasher);
793 ty::InstanceDef::Item(def_id) => {
794 def_id.hash_stable(hcx, hasher);
796 ty::InstanceDef::VtableShim(def_id) => {
797 def_id.hash_stable(hcx, hasher);
799 ty::InstanceDef::Intrinsic(def_id) => {
800 def_id.hash_stable(hcx, hasher);
802 ty::InstanceDef::FnPtrShim(def_id, ty) => {
803 def_id.hash_stable(hcx, hasher);
804 ty.hash_stable(hcx, hasher);
806 ty::InstanceDef::Virtual(def_id, n) => {
807 def_id.hash_stable(hcx, hasher);
808 n.hash_stable(hcx, hasher);
810 ty::InstanceDef::ClosureOnceShim { call_once } => {
811 call_once.hash_stable(hcx, hasher);
813 ty::InstanceDef::DropGlue(def_id, ty) => {
814 def_id.hash_stable(hcx, hasher);
815 ty.hash_stable(hcx, hasher);
817 ty::InstanceDef::CloneShim(def_id, ty) => {
818 def_id.hash_stable(hcx, hasher);
819 ty.hash_stable(hcx, hasher);
825 impl_stable_hash_for!(struct ty::TraitDef {
826 // We already have the def_path_hash below, no need to hash it twice
835 impl_stable_hash_for!(struct ty::Destructor {
839 impl_stable_hash_for!(struct ty::CrateVariancesMap {
841 // This is just an irrelevant helper value.
845 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
847 // This is just an irrelevant helper value.
848 empty_predicate -> _,
851 impl_stable_hash_for!(struct ty::AssociatedItem {
853 ident -> (ident.name),
858 method_has_self_argument
861 impl_stable_hash_for!(enum ty::AssociatedKind {
868 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
869 TraitContainer(def_id),
870 ImplContainer(def_id)
874 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
875 for ty::steal::Steal<T>
876 where T: HashStable<StableHashingContext<'a>>
878 fn hash_stable<W: StableHasherResult>(&self,
879 hcx: &mut StableHashingContext<'a>,
880 hasher: &mut StableHasher<W>) {
881 self.borrow().hash_stable(hcx, hasher);
885 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
891 impl_stable_hash_for!(enum traits::Reveal {
896 impl_stable_hash_for!(enum crate::middle::privacy::AccessLevel {
897 ReachableFromImplTrait,
903 impl<'a> HashStable<StableHashingContext<'a>>
904 for crate::middle::privacy::AccessLevels {
905 fn hash_stable<W: StableHasherResult>(&self,
906 hcx: &mut StableHashingContext<'a>,
907 hasher: &mut StableHasher<W>) {
908 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
909 let crate::middle::privacy::AccessLevels {
913 map.hash_stable(hcx, hasher);
918 impl_stable_hash_for!(struct ty::CrateInherentImpls {
922 impl_stable_hash_for!(enum crate::session::CompileIncomplete {
924 Errored(error_reported)
927 impl_stable_hash_for!(struct crate::util::common::ErrorReported {});
929 impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
933 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
934 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
935 fn hash_stable<W: StableHasherResult>(&self,
936 hcx: &mut StableHashingContext<'a>,
937 hasher: &mut StableHasher<W>) {
938 use crate::traits::Vtable::*;
940 mem::discriminant(self).hash_stable(hcx, hasher);
943 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
944 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
945 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
946 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
947 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
948 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
949 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
950 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
951 &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher),
956 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
957 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
958 fn hash_stable<W: StableHasherResult>(&self,
959 hcx: &mut StableHashingContext<'a>,
960 hasher: &mut StableHasher<W>) {
961 let traits::VtableImplData {
966 impl_def_id.hash_stable(hcx, hasher);
967 substs.hash_stable(hcx, hasher);
968 nested.hash_stable(hcx, hasher);
972 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
973 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
974 fn hash_stable<W: StableHasherResult>(&self,
975 hcx: &mut StableHashingContext<'a>,
976 hasher: &mut StableHasher<W>) {
977 let traits::VtableAutoImplData {
981 trait_def_id.hash_stable(hcx, hasher);
982 nested.hash_stable(hcx, hasher);
986 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
987 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
988 fn hash_stable<W: StableHasherResult>(&self,
989 hcx: &mut StableHashingContext<'a>,
990 hasher: &mut StableHasher<W>) {
991 let traits::VtableObjectData {
996 upcast_trait_ref.hash_stable(hcx, hasher);
997 vtable_base.hash_stable(hcx, hasher);
998 nested.hash_stable(hcx, hasher);
1002 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1003 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1004 fn hash_stable<W: StableHasherResult>(&self,
1005 hcx: &mut StableHashingContext<'a>,
1006 hasher: &mut StableHasher<W>) {
1007 let traits::VtableBuiltinData {
1010 nested.hash_stable(hcx, hasher);
1014 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1015 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1016 fn hash_stable<W: StableHasherResult>(&self,
1017 hcx: &mut StableHashingContext<'a>,
1018 hasher: &mut StableHasher<W>) {
1019 let traits::VtableClosureData {
1024 closure_def_id.hash_stable(hcx, hasher);
1025 substs.hash_stable(hcx, hasher);
1026 nested.hash_stable(hcx, hasher);
1030 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1031 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1032 fn hash_stable<W: StableHasherResult>(&self,
1033 hcx: &mut StableHashingContext<'a>,
1034 hasher: &mut StableHasher<W>) {
1035 let traits::VtableFnPointerData {
1039 fn_ty.hash_stable(hcx, hasher);
1040 nested.hash_stable(hcx, hasher);
1044 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1045 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1046 fn hash_stable<W: StableHasherResult>(&self,
1047 hcx: &mut StableHashingContext<'a>,
1048 hasher: &mut StableHasher<W>) {
1049 let traits::VtableGeneratorData {
1054 generator_def_id.hash_stable(hcx, hasher);
1055 substs.hash_stable(hcx, hasher);
1056 nested.hash_stable(hcx, hasher);
1060 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1061 for traits::VtableTraitAliasData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1062 fn hash_stable<W: StableHasherResult>(&self,
1063 hcx: &mut StableHashingContext<'a>,
1064 hasher: &mut StableHasher<W>) {
1065 let traits::VtableTraitAliasData {
1070 alias_def_id.hash_stable(hcx, hasher);
1071 substs.hash_stable(hcx, hasher);
1072 nested.hash_stable(hcx, hasher);
1076 impl_stable_hash_for!(
1077 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1078 max_universe, variables, value
1082 impl_stable_hash_for!(
1083 struct infer::canonical::CanonicalVarValues<'tcx> {
1088 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1092 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1094 PlaceholderTy(placeholder),
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 crate::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 crate::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 crate::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 crate::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 crate::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);
1198 a.hash_stable(hcx, hasher);
1199 b.hash_stable(hcx, hasher);
1206 impl_stable_hash_for!(
1207 struct traits::ProgramClause<'tcx> {
1208 goal, hypotheses, category
1212 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1218 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1219 fn hash_stable<W: StableHasherResult>(&self,
1220 hcx: &mut StableHashingContext<'a>,
1221 hasher: &mut StableHasher<W>) {
1222 use crate::traits::Clause::*;
1224 mem::discriminant(self).hash_stable(hcx, hasher);
1226 Implies(clause) => clause.hash_stable(hcx, hasher),
1227 ForAll(clause) => clause.hash_stable(hcx, hasher),
1232 impl_stable_hash_for!(enum traits::QuantifierKind {
1237 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1239 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1241 impl_stable_hash_for!(
1242 struct traits::Environment<'tcx> {
1247 impl_stable_hash_for!(
1248 impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
1254 impl_stable_hash_for!(
1255 struct ty::CanonicalUserTypeAnnotation<'tcx> {
1256 user_ty, span, inferred_ty
1260 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::UserType<'gcx> {
1261 fn hash_stable<W: StableHasherResult>(&self,
1262 hcx: &mut StableHashingContext<'a>,
1263 hasher: &mut StableHasher<W>) {
1264 mem::discriminant(self).hash_stable(hcx, hasher);
1266 ty::UserType::Ty(ref ty) => {
1267 ty.hash_stable(hcx, hasher);
1269 ty::UserType::TypeOf(ref def_id, ref substs) => {
1270 def_id.hash_stable(hcx, hasher);
1271 substs.hash_stable(hcx, hasher);
1277 impl<'a> HashStable<StableHashingContext<'a>> for ty::UserTypeAnnotationIndex {
1279 fn hash_stable<W: StableHasherResult>(&self,
1280 hcx: &mut StableHashingContext<'a>,
1281 hasher: &mut StableHasher<W>) {
1282 self.index().hash_stable(hcx, hasher);