@@ -375,11 +375,30 @@ impl_stable_hash_for!(enum ::syntax::ast::Mutability {
375375 Mutable
376376} ) ;
377377
378- impl_stable_hash_for ! ( struct ty:: Const <' tcx> {
379- ty,
380- alloc,
381- val
382- } ) ;
378+
379+ impl < ' a , ' gcx > HashStable < StableHashingContext < ' a > > for ty:: Const < ' gcx > {
380+ fn hash_stable < W : StableHasherResult > (
381+ & self ,
382+ hcx : & mut StableHashingContext < ' a > ,
383+ hasher : & mut StableHasher < W > ,
384+ ) {
385+ let ty:: Const { ty, val, alloc } = self ;
386+ ty. hash_stable ( hcx, hasher) ;
387+ val. hash_stable ( hcx, hasher) ;
388+ // don't hash the memory for `Scalar` and `Slice`. There's nothing to be gained
389+ // by it. All the relevant info is contained in the value.
390+ if let mir:: interpret:: ConstValue :: ByRef = val {
391+ let ( alloc, ptr) = alloc. unwrap ( ) ;
392+ // type check for future changes
393+ let alloc: & ' gcx mir:: interpret:: Allocation = alloc;
394+ alloc. hash_stable ( hcx, hasher) ;
395+ ptr. offset . hash_stable ( hcx, hasher) ;
396+ // do not hash the alloc id in the pointer. It does not add anything new to the hash.
397+ // If the hash of the alloc id is the same, then the hash of the allocation would also
398+ // be the same.
399+ }
400+ }
401+ }
383402
384403impl_stable_hash_for ! ( impl <' tcx> for enum ty:: LazyConst <' tcx> [ ty:: LazyConst ] {
385404 Unevaluated ( did, substs) ,
0 commit comments