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!(enum crate::session::CompileIncomplete {
951 Errored(error_reported)
954 impl_stable_hash_for!(struct crate::util::common::ErrorReported {});
956 impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
960 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
961 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
962 fn hash_stable<W: StableHasherResult>(&self,
963 hcx: &mut StableHashingContext<'a>,
964 hasher: &mut StableHasher<W>) {
965 use crate::traits::Vtable::*;
967 mem::discriminant(self).hash_stable(hcx, hasher);
970 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
971 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
972 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
973 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
974 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
975 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
976 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
977 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
978 &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher),
983 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
984 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
985 fn hash_stable<W: StableHasherResult>(&self,
986 hcx: &mut StableHashingContext<'a>,
987 hasher: &mut StableHasher<W>) {
988 let traits::VtableImplData {
993 impl_def_id.hash_stable(hcx, hasher);
994 substs.hash_stable(hcx, hasher);
995 nested.hash_stable(hcx, hasher);
999 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1000 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1001 fn hash_stable<W: StableHasherResult>(&self,
1002 hcx: &mut StableHashingContext<'a>,
1003 hasher: &mut StableHasher<W>) {
1004 let traits::VtableAutoImplData {
1008 trait_def_id.hash_stable(hcx, hasher);
1009 nested.hash_stable(hcx, hasher);
1013 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1014 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1015 fn hash_stable<W: StableHasherResult>(&self,
1016 hcx: &mut StableHashingContext<'a>,
1017 hasher: &mut StableHasher<W>) {
1018 let traits::VtableObjectData {
1023 upcast_trait_ref.hash_stable(hcx, hasher);
1024 vtable_base.hash_stable(hcx, hasher);
1025 nested.hash_stable(hcx, hasher);
1029 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1030 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1031 fn hash_stable<W: StableHasherResult>(&self,
1032 hcx: &mut StableHashingContext<'a>,
1033 hasher: &mut StableHasher<W>) {
1034 let traits::VtableBuiltinData {
1037 nested.hash_stable(hcx, hasher);
1041 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1042 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1043 fn hash_stable<W: StableHasherResult>(&self,
1044 hcx: &mut StableHashingContext<'a>,
1045 hasher: &mut StableHasher<W>) {
1046 let traits::VtableClosureData {
1051 closure_def_id.hash_stable(hcx, hasher);
1052 substs.hash_stable(hcx, hasher);
1053 nested.hash_stable(hcx, hasher);
1057 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1058 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1059 fn hash_stable<W: StableHasherResult>(&self,
1060 hcx: &mut StableHashingContext<'a>,
1061 hasher: &mut StableHasher<W>) {
1062 let traits::VtableFnPointerData {
1066 fn_ty.hash_stable(hcx, hasher);
1067 nested.hash_stable(hcx, hasher);
1071 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1072 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1073 fn hash_stable<W: StableHasherResult>(&self,
1074 hcx: &mut StableHashingContext<'a>,
1075 hasher: &mut StableHasher<W>) {
1076 let traits::VtableGeneratorData {
1081 generator_def_id.hash_stable(hcx, hasher);
1082 substs.hash_stable(hcx, hasher);
1083 nested.hash_stable(hcx, hasher);
1087 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1088 for traits::VtableTraitAliasData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1089 fn hash_stable<W: StableHasherResult>(&self,
1090 hcx: &mut StableHashingContext<'a>,
1091 hasher: &mut StableHasher<W>) {
1092 let traits::VtableTraitAliasData {
1097 alias_def_id.hash_stable(hcx, hasher);
1098 substs.hash_stable(hcx, hasher);
1099 nested.hash_stable(hcx, hasher);
1103 impl_stable_hash_for!(
1104 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1105 max_universe, variables, value
1109 impl_stable_hash_for!(
1110 struct infer::canonical::CanonicalVarValues<'tcx> {
1115 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1119 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1121 PlaceholderTy(placeholder),
1123 PlaceholderRegion(placeholder),
1126 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1132 impl_stable_hash_for!(
1133 impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
1134 var_values, region_constraints, certainty, value
1138 impl_stable_hash_for!(enum infer::canonical::Certainty {
1142 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1143 fn hash_stable<W: StableHasherResult>(&self,
1144 hcx: &mut StableHashingContext<'a>,
1145 hasher: &mut StableHasher<W>) {
1146 use crate::traits::WhereClause::*;
1148 mem::discriminant(self).hash_stable(hcx, hasher);
1150 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1151 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1152 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1153 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1158 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1159 fn hash_stable<W: StableHasherResult>(&self,
1160 hcx: &mut StableHashingContext<'a>,
1161 hasher: &mut StableHasher<W>) {
1162 use crate::traits::WellFormed::*;
1164 mem::discriminant(self).hash_stable(hcx, hasher);
1166 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1167 Ty(ty) => ty.hash_stable(hcx, hasher),
1172 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1173 fn hash_stable<W: StableHasherResult>(&self,
1174 hcx: &mut StableHashingContext<'a>,
1175 hasher: &mut StableHasher<W>) {
1176 use crate::traits::FromEnv::*;
1178 mem::discriminant(self).hash_stable(hcx, hasher);
1180 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1181 Ty(ty) => ty.hash_stable(hcx, hasher),
1186 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1187 fn hash_stable<W: StableHasherResult>(&self,
1188 hcx: &mut StableHashingContext<'a>,
1189 hasher: &mut StableHasher<W>) {
1190 use crate::traits::DomainGoal::*;
1192 mem::discriminant(self).hash_stable(hcx, hasher);
1194 Holds(wc) => wc.hash_stable(hcx, hasher),
1195 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1196 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1197 Normalize(projection) => projection.hash_stable(hcx, hasher),
1202 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1203 fn hash_stable<W: StableHasherResult>(&self,
1204 hcx: &mut StableHashingContext<'a>,
1205 hasher: &mut StableHasher<W>) {
1206 use crate::traits::GoalKind::*;
1208 mem::discriminant(self).hash_stable(hcx, hasher);
1210 Implies(hypotheses, goal) => {
1211 hypotheses.hash_stable(hcx, hasher);
1212 goal.hash_stable(hcx, hasher);
1214 And(goal1, goal2) => {
1215 goal1.hash_stable(hcx, hasher);
1216 goal2.hash_stable(hcx, hasher);
1218 Not(goal) => goal.hash_stable(hcx, hasher),
1219 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1220 Quantified(quantifier, goal) => {
1221 quantifier.hash_stable(hcx, hasher);
1222 goal.hash_stable(hcx, hasher);
1225 a.hash_stable(hcx, hasher);
1226 b.hash_stable(hcx, hasher);
1233 impl_stable_hash_for!(
1234 struct traits::ProgramClause<'tcx> {
1235 goal, hypotheses, category
1239 impl_stable_hash_for!(enum traits::ProgramClauseCategory {
1245 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1246 fn hash_stable<W: StableHasherResult>(&self,
1247 hcx: &mut StableHashingContext<'a>,
1248 hasher: &mut StableHasher<W>) {
1249 use crate::traits::Clause::*;
1251 mem::discriminant(self).hash_stable(hcx, hasher);
1253 Implies(clause) => clause.hash_stable(hcx, hasher),
1254 ForAll(clause) => clause.hash_stable(hcx, hasher),
1259 impl_stable_hash_for!(enum traits::QuantifierKind {
1264 impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1266 impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1268 impl_stable_hash_for!(
1269 struct traits::Environment<'tcx> {
1274 impl_stable_hash_for!(
1275 impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
1281 impl_stable_hash_for!(
1282 struct ty::CanonicalUserTypeAnnotation<'tcx> {
1283 user_ty, span, inferred_ty
1287 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::UserType<'gcx> {
1288 fn hash_stable<W: StableHasherResult>(&self,
1289 hcx: &mut StableHashingContext<'a>,
1290 hasher: &mut StableHasher<W>) {
1291 mem::discriminant(self).hash_stable(hcx, hasher);
1293 ty::UserType::Ty(ref ty) => {
1294 ty.hash_stable(hcx, hasher);
1296 ty::UserType::TypeOf(ref def_id, ref substs) => {
1297 def_id.hash_stable(hcx, hasher);
1298 substs.hash_stable(hcx, hasher);
1304 impl<'a> HashStable<StableHashingContext<'a>> for ty::UserTypeAnnotationIndex {
1306 fn hash_stable<W: StableHasherResult>(&self,
1307 hcx: &mut StableHashingContext<'a>,
1308 hasher: &mut StableHasher<W>) {
1309 self.index().hash_stable(hcx, hasher);