Skip to content

Commit b0857a7

Browse files
committed
Synchronize StableHash with the updated PartialEq impl
1 parent b3731ee commit b0857a7

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/librustc/ich/impls_ty.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -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

384403
impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] {
385404
Unevaluated(did, substs),

src/librustc/ty/sty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,8 @@ impl<'tcx> Hash for Const<'tcx> {
21322132
let Const { ty, val, alloc } = self;
21332133
ty.hash(hasher);
21342134
val.hash(hasher);
2135+
// don't hash the memory for `Scalar` and `Slice`. There's nothing to be gained
2136+
// by it. All the relevant info is contained in the value.
21352137
if let ConstValue::ByRef = val {
21362138
let (alloc, ptr) = alloc.unwrap();
21372139
// type check for future changes

0 commit comments

Comments
 (0)