about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Molzer <andreas.molzer@gmx.de>2019-08-17 19:49:51 +0200
committerAndreas Molzer <andreas.molzer@gmx.de>2019-08-17 19:58:15 +0200
commit2228b3f08631b5e9b32e6b6c82e758fe4bcbbd60 (patch)
tree8209c518d8cd231be57cad0ab84a43f58db1e3c3
parent9b9eecf964235f781806ce3e026c1522eb35e013 (diff)
downloadrust-2228b3f08631b5e9b32e6b6c82e758fe4bcbbd60.tar.gz
rust-2228b3f08631b5e9b32e6b6c82e758fe4bcbbd60.zip
Derive HashStable for Allocation
Requires a manual implementation for Relocations since dereferencing to
SortedMap is not always implemented but that one is far more trivial.
Added fields could otherwise be silently forgotten since private fields
make destructing outside the module possible only with `..` pattern
which would then also be applicable to newly added public fields.
-rw-r--r--src/librustc/ich/impls_ty.rs26
-rw-r--r--src/librustc/mir/interpret/allocation.rs13
2 files changed, 20 insertions, 19 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs
index e33991bb1b6..be7669fcad8 100644
--- a/src/librustc/ich/impls_ty.rs
+++ b/src/librustc/ich/impls_ty.rs
@@ -168,31 +168,21 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
     }
 }
 
-// Allocations treat their relocations specially
-impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
+// `Relocations` with default type parameters is a sorted map.
+impl<'a, Tag> HashStable<StableHashingContext<'a>>
+for mir::interpret::Relocations<Tag>
+where
+    Tag: HashStable<StableHashingContext<'a>>,
+{
     fn hash_stable<W: StableHasherResult>(
         &self,
         hcx: &mut StableHashingContext<'a>,
         hasher: &mut StableHasher<W>,
     ) {
-        let mir::interpret::Allocation {
-            relocations, align, mutability, size,
-            extra: _,
-            .. /* private bytes and undef_mask */
-        } = self;
-
-        let bytes = self.inspect_with_undef_and_ptr_outside_interpreter(0..self.len());
-        let undef_mask = self.undef_mask();
-
-        bytes.hash_stable(hcx, hasher);
-        relocations.len().hash_stable(hcx, hasher);
-        for reloc in relocations.iter() {
+        self.len().hash_stable(hcx, hasher);
+        for reloc in self.iter() {
             reloc.hash_stable(hcx, hasher);
         }
-        undef_mask.hash_stable(hcx, hasher);
-        size.hash_stable(hcx, hasher);
-        align.hash_stable(hcx, hasher);
-        mutability.hash_stable(hcx, hasher);
     }
 }
 
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index 61b237c0bb3..363fcaae5b2 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -13,7 +13,18 @@ use rustc_data_structures::sorted_map::SortedMap;
 use rustc_target::abi::HasDataLayout;
 use std::borrow::Cow;
 
-#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
+#[derive(
+    Clone,
+    Debug,
+    Eq,
+    PartialEq,
+    PartialOrd,
+    Ord,
+    Hash,
+    RustcEncodable,
+    RustcDecodable,
+    HashStable,
+)]
 pub struct Allocation<Tag=(),Extra=()> {
     /// The actual bytes of the allocation.
     /// Note that the bytes of a pointer represent the offset of the pointer.