Skip to content

Commit

Permalink
Synchronize StableHash with the updated PartialEq impl
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 15, 2019
1 parent b3731ee commit b0857a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,30 @@ impl_stable_hash_for!(enum ::syntax::ast::Mutability {
Mutable
});

impl_stable_hash_for!(struct ty::Const<'tcx> {
ty,
alloc,
val
});

impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Const<'gcx> {
fn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>,
) {
let ty::Const { ty, val, alloc } = self;
ty.hash_stable(hcx, hasher);
val.hash_stable(hcx, hasher);
// don't hash the memory for `Scalar` and `Slice`. There's nothing to be gained
// by it. All the relevant info is contained in the value.
if let mir::interpret::ConstValue::ByRef = val {
let (alloc, ptr) = alloc.unwrap();
// type check for future changes
let alloc: &'gcx mir::interpret::Allocation = alloc;
alloc.hash_stable(hcx, hasher);
ptr.offset.hash_stable(hcx, hasher);
// do not hash the alloc id in the pointer. It does not add anything new to the hash.
// If the hash of the alloc id is the same, then the hash of the allocation would also
// be the same.
}
}
}

impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] {
Unevaluated(did, substs),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,8 @@ impl<'tcx> Hash for Const<'tcx> {
let Const { ty, val, alloc } = self;
ty.hash(hasher);
val.hash(hasher);
// don't hash the memory for `Scalar` and `Slice`. There's nothing to be gained
// by it. All the relevant info is contained in the value.
if let ConstValue::ByRef = val {
let (alloc, ptr) = alloc.unwrap();
// type check for future changes
Expand Down

0 comments on commit b0857a7

Please sign in to comment.