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),
77 ty::subst::UnpackedKind::Const(ct) => ct.hash_stable(hcx, hasher),
82 impl<'a> HashStable<StableHashingContext<'a>>
84 fn hash_stable<W: StableHasherResult>(&self,
85 hcx: &mut StableHashingContext<'a>,
86 hasher: &mut StableHasher<W>) {
87 mem::discriminant(self).hash_stable(hcx, hasher);
92 // No variant fields to hash for these ...
94 ty::ReLateBound(db, ty::BrAnon(i)) => {
95 db.hash_stable(hcx, hasher);
96 i.hash_stable(hcx, hasher);
98 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
99 db.hash_stable(hcx, hasher);
100 def_id.hash_stable(hcx, hasher);
101 name.hash_stable(hcx, hasher);
103 ty::ReLateBound(db, ty::BrEnv) => {
104 db.hash_stable(hcx, hasher);
106 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
107 def_id.hash_stable(hcx, hasher);
108 index.hash_stable(hcx, hasher);
109 name.hash_stable(hcx, hasher);
111 ty::ReScope(scope) => {
112 scope.hash_stable(hcx, hasher);
114 ty::ReFree(ref free_region) => {
115 free_region.hash_stable(hcx, hasher);
117 ty::ReClosureBound(vid) => {
118 vid.hash_stable(hcx, hasher);
120 ty::ReLateBound(..) |
122 ty::RePlaceholder(..) => {
123 bug!("StableHasher: unexpected region {:?}", *self)
129 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
131 fn hash_stable<W: StableHasherResult>(&self,
132 hcx: &mut StableHashingContext<'a>,
133 hasher: &mut StableHasher<W>) {
134 self.index().hash_stable(hcx, hasher);
138 impl<'gcx, 'tcx> HashStable<StableHashingContext<'gcx>> for ty::ConstVid<'tcx> {
140 fn hash_stable<W: StableHasherResult>(&self,
141 hcx: &mut StableHashingContext<'gcx>,
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!(tuple_struct ty::util::NeedsDrop { value });
221 impl_stable_hash_for!(tuple_struct ty::AdtSizedConstraint<'tcx> { list });
223 impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
225 impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
227 impl_stable_hash_for!(enum ty::BorrowKind {
233 impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] {
235 ByRef(up_var_borrow),
238 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
243 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
250 impl_stable_hash_for!(struct ty::ResolvedOpaqueTy<'tcx> {
255 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
256 where T: HashStable<StableHashingContext<'a>>
258 fn hash_stable<W: StableHasherResult>(&self,
259 hcx: &mut StableHashingContext<'a>,
260 hasher: &mut StableHasher<W>) {
261 self.skip_binder().hash_stable(hcx, hasher);
265 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
267 impl_stable_hash_for!(enum ty::Visibility {
273 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
274 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
275 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
276 impl_stable_hash_for!(impl<A, B> for tuple_struct ty::OutlivesPredicate<A, B> { a, b });
277 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
278 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
280 impl_stable_hash_for!(
281 impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] {
284 RegionOutlives(pred),
289 ClosureKind(def_id, closure_substs, closure_kind),
290 ConstEvaluatable(def_id, substs),
294 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
295 fn hash_stable<W: StableHasherResult>(&self,
296 _: &mut StableHashingContext<'a>,
297 hasher: &mut StableHasher<W>) {
298 std_hash::Hash::hash(self, hasher);
302 impl<'a> HashStable<StableHashingContext<'a>> for ty::VariantFlags {
303 fn hash_stable<W: StableHasherResult>(&self,
304 _: &mut StableHashingContext<'a>,
305 hasher: &mut StableHasher<W>) {
306 std_hash::Hash::hash(self, hasher);
310 impl_stable_hash_for!(
311 impl<'tcx> for enum ty::InferConst<'tcx> [ ty::InferConst ] {
314 Canonical(debruijn, var),
318 impl_stable_hash_for!(enum ty::VariantDiscr {
323 impl_stable_hash_for!(struct ty::FieldDef {
325 ident -> (ident.name),
329 impl_stable_hash_for!(
330 impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
339 impl_stable_hash_for!(struct crate::mir::interpret::RawConst<'tcx> {
344 impl_stable_hash_for! {
345 impl<Tag> for struct mir::interpret::Pointer<Tag> {
352 impl_stable_hash_for!(
353 impl<Tag> for enum mir::interpret::Scalar<Tag> [ mir::interpret::Scalar ] {
359 impl_stable_hash_for!(
360 impl<'tcx> for enum mir::interpret::AllocKind<'tcx> [ mir::interpret::AllocKind ] {
367 // AllocIds get resolved to whatever they point to (to be stable)
368 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
369 fn hash_stable<W: StableHasherResult>(
371 hcx: &mut StableHashingContext<'a>,
372 hasher: &mut StableHasher<W>,
374 ty::tls::with_opt(|tcx| {
375 trace!("hashing {:?}", *self);
376 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
377 let alloc_kind = tcx.alloc_map.lock().get(*self);
378 alloc_kind.hash_stable(hcx, hasher);
383 // Allocations treat their relocations specially
384 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
385 fn hash_stable<W: StableHasherResult>(
387 hcx: &mut StableHashingContext<'a>,
388 hasher: &mut StableHasher<W>,
390 self.bytes.hash_stable(hcx, hasher);
391 for reloc in self.relocations.iter() {
392 reloc.hash_stable(hcx, hasher);
394 self.undef_mask.hash_stable(hcx, hasher);
395 self.align.hash_stable(hcx, hasher);
396 self.mutability.hash_stable(hcx, hasher);
400 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
405 impl_stable_hash_for!(struct ty::Const<'tcx> {
410 impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] {
411 Unevaluated(did, substs),
415 impl_stable_hash_for!(enum mir::interpret::ErrorHandled {
420 impl_stable_hash_for!(struct mir::interpret::FrameInfo<'tcx> {
426 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
427 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
429 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
434 impl_stable_hash_for!(
435 impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O>
436 [ mir::interpret::EvalErrorKind ]
438 FunctionArgCountMismatch,
439 DanglingPointerDeref,
442 InvalidFunctionPointer,
444 InvalidNullPointerUsage,
450 StackFrameLimitReached,
453 CalledClosureAsFunction,
454 VtableForArgumentlessMethod,
455 ModifiedConstantMemory,
459 ReallocateNonBasePtr,
460 DeallocateNonBasePtr,
463 ReadFromReturnPointer,
464 UnimplementedTraitSelection,
467 DerefFunctionPointer,
472 GeneratorResumedAfterReturn,
473 GeneratorResumedAfterPanic,
476 ReadUndefBytes(offset),
477 InvalidDiscriminant(val),
478 Panic { msg, file, line, col },
480 FunctionAbiMismatch(a, b),
481 FunctionArgMismatch(a, b),
482 FunctionRetMismatch(a, b),
484 UnterminatedCString(ptr),
485 PointerOutOfBounds { ptr, check, allocation_size },
488 BoundsCheck { len, index },
492 AlignmentCheckFailed { required, has },
493 ValidationFailure(s),
494 TypeNotPrimitive(ty),
495 ReallocatedWrongMemoryKind(a, b),
496 DeallocatedWrongMemoryKind(a, b),
497 IncorrectAllocationInformation(a, b, c, d),
499 HeapAllocNonPowerOfTwoAlignment(n),
505 impl_stable_hash_for!(enum mir::interpret::InboundsCheck {
510 impl_stable_hash_for!(enum ty::Variance {
517 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
521 impl_stable_hash_for!(struct ty::Generics {
525 // Reverse map to each param's `index` field, from its `def_id`.
526 param_def_id_to_index -> _, // Don't hash this
528 has_late_bound_regions,
531 impl_stable_hash_for!(struct ty::GenericParamDef {
539 impl_stable_hash_for!(enum ty::GenericParamDefKind {
541 Type { has_default, object_lifetime_default, synthetic },
545 impl_stable_hash_for!(
546 impl<T> for enum crate::middle::resolve_lifetime::Set1<T>
547 [ crate::middle::resolve_lifetime::Set1 ]
555 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::LifetimeDefOrigin {
561 impl_stable_hash_for!(enum crate::middle::resolve_lifetime::Region {
563 EarlyBound(index, decl, is_in_band),
564 LateBound(db_index, decl, is_in_band),
565 LateBoundAnon(db_index, anon_index),
566 Free(call_site_scope_data, decl)
569 impl_stable_hash_for!(enum ty::cast::CastKind {
583 impl_stable_hash_for!(struct crate::middle::region::Scope { id, data });
585 impl_stable_hash_for!(enum crate::middle::region::ScopeData {
590 Remainder(first_statement_index)
593 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
594 type KeyType = region::Scope;
597 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
602 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
606 impl_stable_hash_for!(struct ty::FreeRegion {
611 impl_stable_hash_for!(enum ty::BoundRegion {
613 BrNamed(def_id, name),
618 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
621 fn hash_stable<W: StableHasherResult>(&self,
622 hcx: &mut StableHashingContext<'a>,
623 hasher: &mut StableHasher<W>) {
624 use crate::ty::TyKind::*;
626 mem::discriminant(self).hash_stable(hcx, hasher);
633 // Nothing more to hash.
636 int_ty.hash_stable(hcx, hasher);
639 uint_ty.hash_stable(hcx, hasher);
642 float_ty.hash_stable(hcx, hasher);
644 Adt(adt_def, substs) => {
645 adt_def.hash_stable(hcx, hasher);
646 substs.hash_stable(hcx, hasher);
648 Array(inner_ty, len) => {
649 inner_ty.hash_stable(hcx, hasher);
650 len.hash_stable(hcx, hasher);
653 inner_ty.hash_stable(hcx, hasher);
655 RawPtr(pointee_ty) => {
656 pointee_ty.hash_stable(hcx, hasher);
658 Ref(region, pointee_ty, mutbl) => {
659 region.hash_stable(hcx, hasher);
660 pointee_ty.hash_stable(hcx, hasher);
661 mutbl.hash_stable(hcx, hasher);
663 FnDef(def_id, substs) => {
664 def_id.hash_stable(hcx, hasher);
665 substs.hash_stable(hcx, hasher);
668 sig.hash_stable(hcx, hasher);
670 Dynamic(ref existential_predicates, region) => {
671 existential_predicates.hash_stable(hcx, hasher);
672 region.hash_stable(hcx, hasher);
674 Closure(def_id, closure_substs) => {
675 def_id.hash_stable(hcx, hasher);
676 closure_substs.hash_stable(hcx, hasher);
678 Generator(def_id, generator_substs, movability) => {
679 def_id.hash_stable(hcx, hasher);
680 generator_substs.hash_stable(hcx, hasher);
681 movability.hash_stable(hcx, hasher);
683 GeneratorWitness(types) => {
684 types.hash_stable(hcx, hasher)
686 Tuple(inner_tys) => {
687 inner_tys.hash_stable(hcx, hasher);
689 Projection(ref data) | UnnormalizedProjection(ref data) => {
690 data.hash_stable(hcx, hasher);
692 Opaque(def_id, substs) => {
693 def_id.hash_stable(hcx, hasher);
694 substs.hash_stable(hcx, hasher);
697 param_ty.hash_stable(hcx, hasher);
699 Bound(debruijn, bound_ty) => {
700 debruijn.hash_stable(hcx, hasher);
701 bound_ty.hash_stable(hcx, hasher);
703 ty::Placeholder(placeholder_ty) => {
704 placeholder_ty.hash_stable(hcx, hasher);
707 def_id.hash_stable(hcx, hasher);
710 infer_ty.hash_stable(hcx, hasher);
716 impl_stable_hash_for!(enum ty::InferTy {
725 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
728 fn hash_stable<W: StableHasherResult>(&self,
729 _hcx: &mut StableHashingContext<'a>,
730 _hasher: &mut StableHasher<W>) {
731 // TyVid values are confined to an inference context and hence
732 // should not be hashed.
733 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
737 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
740 fn hash_stable<W: StableHasherResult>(&self,
741 _hcx: &mut StableHashingContext<'a>,
742 _hasher: &mut StableHasher<W>) {
743 // IntVid values are confined to an inference context and hence
744 // should not be hashed.
745 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
749 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
752 fn hash_stable<W: StableHasherResult>(&self,
753 _hcx: &mut StableHashingContext<'a>,
754 _hasher: &mut StableHasher<W>) {
755 // FloatVid values are confined to an inference context and hence
756 // should not be hashed.
757 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
761 impl_stable_hash_for!(struct ty::ParamConst {
766 impl_stable_hash_for!(struct ty::ParamTy {
771 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
776 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
777 for ty::ExistentialPredicate<'gcx>
779 fn hash_stable<W: StableHasherResult>(&self,
780 hcx: &mut StableHashingContext<'a>,
781 hasher: &mut StableHasher<W>) {
782 mem::discriminant(self).hash_stable(hcx, hasher);
784 ty::ExistentialPredicate::Trait(ref trait_ref) => {
785 trait_ref.hash_stable(hcx, hasher);
787 ty::ExistentialPredicate::Projection(ref projection) => {
788 projection.hash_stable(hcx, hasher);
790 ty::ExistentialPredicate::AutoTrait(def_id) => {
791 def_id.hash_stable(hcx, hasher);
797 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
802 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
808 impl_stable_hash_for!(struct ty::Instance<'tcx> {
813 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
814 fn hash_stable<W: StableHasherResult>(&self,
815 hcx: &mut StableHashingContext<'a>,
816 hasher: &mut StableHasher<W>) {
817 mem::discriminant(self).hash_stable(hcx, hasher);
820 ty::InstanceDef::Item(def_id) => {
821 def_id.hash_stable(hcx, hasher);
823 ty::InstanceDef::VtableShim(def_id) => {
824 def_id.hash_stable(hcx, hasher);
826 ty::InstanceDef::Intrinsic(def_id) => {
827 def_id.hash_stable(hcx, hasher);
829 ty::InstanceDef::FnPtrShim(def_id, ty) => {
830 def_id.hash_stable(hcx, hasher);
831 ty.hash_stable(hcx, hasher);
833 ty::InstanceDef::Virtual(def_id, n) => {
834 def_id.hash_stable(hcx, hasher);
835 n.hash_stable(hcx, hasher);
837 ty::InstanceDef::ClosureOnceShim { call_once } => {
838 call_once.hash_stable(hcx, hasher);
840 ty::InstanceDef::DropGlue(def_id, ty) => {
841 def_id.hash_stable(hcx, hasher);
842 ty.hash_stable(hcx, hasher);
844 ty::InstanceDef::CloneShim(def_id, ty) => {
845 def_id.hash_stable(hcx, hasher);
846 ty.hash_stable(hcx, hasher);
852 impl_stable_hash_for!(struct ty::TraitDef {
853 // We already have the def_path_hash below, no need to hash it twice
862 impl_stable_hash_for!(struct ty::Destructor {
866 impl_stable_hash_for!(struct ty::CrateVariancesMap {
868 // This is just an irrelevant helper value.
872 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
874 // This is just an irrelevant helper value.
875 empty_predicate -> _,
878 impl_stable_hash_for!(struct ty::AssociatedItem {
880 ident -> (ident.name),
885 method_has_self_argument
888 impl_stable_hash_for!(enum ty::AssociatedKind {
895 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
896 TraitContainer(def_id),
897 ImplContainer(def_id)
901 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
902 for ty::steal::Steal<T>
903 where T: HashStable<StableHashingContext<'a>>
905 fn hash_stable<W: StableHasherResult>(&self,
906 hcx: &mut StableHashingContext<'a>,
907 hasher: &mut StableHasher<W>) {
908 self.borrow().hash_stable(hcx, hasher);
912 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
918 impl_stable_hash_for!(enum traits::Reveal {
923 impl_stable_hash_for!(enum crate::middle::privacy::AccessLevel {
924 ReachableFromImplTrait,
930 impl<'a> HashStable<StableHashingContext<'a>>
931 for crate::middle::privacy::AccessLevels {
932 fn hash_stable<W: StableHasherResult>(&self,
933 hcx: &mut StableHashingContext<'a>,
934 hasher: &mut StableHasher<W>) {
935 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
936 let crate::middle::privacy::AccessLevels {
940 map.hash_stable(hcx, hasher);
945 impl_stable_hash_for!(struct ty::CrateInherentImpls {
949 impl_stable_hash_for!(struct crate::util::common::ErrorReported {});
951 impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
955 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
956 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
957 fn hash_stable<W: StableHasherResult>(&self,
958 hcx: &mut StableHashingContext<'a>,
959 hasher: &mut StableHasher<W>) {
960 use crate::traits::Vtable::*;
962 mem::discriminant(self).hash_stable(hcx, hasher);
965 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
966 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
967 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
968 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
969 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
970 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
971 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
972 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
973 &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher),
978 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
979 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
980 fn hash_stable<W: StableHasherResult>(&self,
981 hcx: &mut StableHashingContext<'a>,
982 hasher: &mut StableHasher<W>) {
983 let traits::VtableImplData {
988 impl_def_id.hash_stable(hcx, hasher);
989 substs.hash_stable(hcx, hasher);
990 nested.hash_stable(hcx, hasher);
994 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
995 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
996 fn hash_stable<W: StableHasherResult>(&self,
997 hcx: &mut StableHashingContext<'a>,
998 hasher: &mut StableHasher<W>) {
999 let traits::VtableAutoImplData {
1003 trait_def_id.hash_stable(hcx, hasher);
1004 nested.hash_stable(hcx, hasher);
1008 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1009 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1010 fn hash_stable<W: StableHasherResult>(&self,
1011 hcx: &mut StableHashingContext<'a>,
1012 hasher: &mut StableHasher<W>) {
1013 let traits::VtableObjectData {
1018 upcast_trait_ref.hash_stable(hcx, hasher);
1019 vtable_base.hash_stable(hcx, hasher);
1020 nested.hash_stable(hcx, hasher);
1024 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1025 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1026 fn hash_stable<W: StableHasherResult>(&self,
1027 hcx: &mut StableHashingContext<'a>,
1028 hasher: &mut StableHasher<W>) {
1029 let traits::VtableBuiltinData {
1032 nested.hash_stable(hcx, hasher);
1036 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1037 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1038 fn hash_stable<W: StableHasherResult>(&self,
1039 hcx: &mut StableHashingContext<'a>,
1040 hasher: &mut StableHasher<W>) {
1041 let traits::VtableClosureData {
1046 closure_def_id.hash_stable(hcx, hasher);
1047 substs.hash_stable(hcx, hasher);
1048 nested.hash_stable(hcx, hasher);
1052 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1053 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1054 fn hash_stable<W: StableHasherResult>(&self,
1055 hcx: &mut StableHashingContext<'a>,
1056 hasher: &mut StableHasher<W>) {
1057 let traits::VtableFnPointerData {
1061 fn_ty.hash_stable(hcx, hasher);
1062 nested.hash_stable(hcx, hasher);
1066 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1067 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1068 fn hash_stable<W: StableHasherResult>(&self,
1069 hcx: &mut StableHashingContext<'a>,
1070 hasher: &mut StableHasher<W>) {
1071 let traits::VtableGeneratorData {
1076 generator_def_id.hash_stable(hcx, hasher);
1077 substs.hash_stable(hcx, hasher);
1078 nested.hash_stable(hcx, hasher);
1082 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1083 for traits::VtableTraitAliasData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1084 fn hash_stable<W: StableHasherResult>(&self,
1085 hcx: &mut StableHashingContext<'a>,
1086 hasher: &mut StableHasher<W>) {
1087 let traits::VtableTraitAliasData {
1092 alias_def_id.hash_stable(hcx, hasher);
1093 substs.hash_stable(hcx, hasher);
1094 nested.hash_stable(hcx, hasher);
1098 impl_stable_hash_for!(
1099 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1100 max_universe, variables, value
1104 impl_stable_hash_for!(
1105 struct infer::canonical::CanonicalVarValues<'tcx> {
1110 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1114 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1116 PlaceholderTy(placeholder),
1118 PlaceholderRegion(placeholder),
1121 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1127 impl_stable_hash_for!(
1128 impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
1129 var_values, region_constraints, certainty, value
1133 impl_stable_hash_for!(enum infer::canonical::Certainty {
1137 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1138 fn hash_stable<W: StableHasherResult>(&self,
1139 hcx: &mut StableHashingContext<'a>,
1140 hasher: &mut StableHasher<W>) {
1141 use crate::traits::WhereClause::*;
1143 mem::discriminant(self).hash_stable(hcx, hasher);
1145 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1146 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1147 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1148 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1153 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1154 fn hash_stable<W: StableHasherResult>(&self,
1155 hcx: &mut StableHashingContext<'a>,
1156 hasher: &mut StableHasher<W>) {
1157 use crate::traits::WellFormed::*;
1159 mem::discriminant(self).hash_stable(hcx, hasher);
1161 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1162 Ty(ty) => ty.hash_stable(hcx, hasher),
1167 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1168 fn hash_stable<W: StableHasherResult>(&self,
1169 hcx: &mut StableHashingContext<'a>,
1170 hasher: &mut StableHasher<W>) {
1171 use crate::traits::FromEnv::*;
1173 mem::discriminant(self).hash_stable(hcx, hasher);
1175 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1176 Ty(ty) => ty.hash_stable(hcx, hasher),
1181 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1182 fn hash_stable<W: StableHasherResult>(&self,
1183 hcx: &mut StableHashingContext<'a>,
1184 hasher: &mut StableHasher<W>) {
1185 use crate::traits::DomainGoal::*;
1187 mem::discriminant(self).hash_stable(hcx, hasher);
1189 Holds(wc) => wc.hash_stable(hcx, hasher),
1190 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1191 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1192 Normalize(projection) => projection.hash_stable(hcx, hasher),
1197 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1198 fn hash_stable<W: StableHasherResult>(&self,
1199 hcx: &mut StableHashingContext<'a>,
1200 hasher: &mut StableHasher<W>) {
1201 use crate::traits::GoalKind::*;
1203 mem::discriminant(self).hash_stable(hcx, hasher);
1205 Implies(hypotheses, goal) => {
1206 hypotheses.hash_stable(hcx, hasher);
1207 goal.hash_stable(hcx, hasher);
1209 And(goal1, goal2) => {
1210 goal1.hash_stable(hcx, hasher);
1211 goal2.hash_stable(hcx, hasher);
1213 Not(goal) => goal.hash_stable(hcx, hasher),
1214 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1215 Quantified(quantifier, goal) => {
1216 quantifier.hash_stable(hcx, hasher);
1217 goal.hash_stable(hcx, hasher);
1220 a.hash_stable(hcx, hasher);
1221 b.hash_stable(hcx, hasher);
1228 impl_stable_hash_for!(
1229 struct traits::ProgramClause<'tcx> {
1230 goal, hypotheses, category
1234 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1240 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1241 fn hash_stable<W: StableHasherResult>(&self,
1242 hcx: &mut StableHashingContext<'a>,
1243 hasher: &mut StableHasher<W>) {
1244 use crate::traits::Clause::*;
1246 mem::discriminant(self).hash_stable(hcx, hasher);
1248 Implies(clause) => clause.hash_stable(hcx, hasher),
1249 ForAll(clause) => clause.hash_stable(hcx, hasher),
1254 impl_stable_hash_for!(enum traits::QuantifierKind {
1259 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1261 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1263 impl_stable_hash_for!(
1264 struct traits::Environment<'tcx> {
1269 impl_stable_hash_for!(
1270 impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
1276 impl_stable_hash_for!(
1277 struct ty::CanonicalUserTypeAnnotation<'tcx> {
1278 user_ty, span, inferred_ty
1282 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::UserType<'gcx> {
1283 fn hash_stable<W: StableHasherResult>(&self,
1284 hcx: &mut StableHashingContext<'a>,
1285 hasher: &mut StableHasher<W>) {
1286 mem::discriminant(self).hash_stable(hcx, hasher);
1288 ty::UserType::Ty(ref ty) => {
1289 ty.hash_stable(hcx, hasher);
1291 ty::UserType::TypeOf(ref def_id, ref substs) => {
1292 def_id.hash_stable(hcx, hasher);
1293 substs.hash_stable(hcx, hasher);
1299 impl<'a> HashStable<StableHashingContext<'a>> for ty::UserTypeAnnotationIndex {
1301 fn hash_stable<W: StableHasherResult>(&self,
1302 hcx: &mut StableHashingContext<'a>,
1303 hasher: &mut StableHasher<W>) {
1304 self.index().hash_stable(hcx, hasher);