Skip to content

Commit 2228b3f

Browse files
committed
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.
1 parent 9b9eecf commit 2228b3f

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -168,31 +168,21 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
168168
}
169169
}
170170

171-
// Allocations treat their relocations specially
172-
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
171+
// `Relocations` with default type parameters is a sorted map.
172+
impl<'a, Tag> HashStable<StableHashingContext<'a>>
173+
for mir::interpret::Relocations<Tag>
174+
where
175+
Tag: HashStable<StableHashingContext<'a>>,
176+
{
173177
fn hash_stable<W: StableHasherResult>(
174178
&self,
175179
hcx: &mut StableHashingContext<'a>,
176180
hasher: &mut StableHasher<W>,
177181
) {
178-
let mir::interpret::Allocation {
179-
relocations, align, mutability, size,
180-
extra: _,
181-
.. /* private bytes and undef_mask */
182-
} = self;
183-
184-
let bytes = self.inspect_with_undef_and_ptr_outside_interpreter(0..self.len());
185-
let undef_mask = self.undef_mask();
186-
187-
bytes.hash_stable(hcx, hasher);
188-
relocations.len().hash_stable(hcx, hasher);
189-
for reloc in relocations.iter() {
182+
self.len().hash_stable(hcx, hasher);
183+
for reloc in self.iter() {
190184
reloc.hash_stable(hcx, hasher);
191185
}
192-
undef_mask.hash_stable(hcx, hasher);
193-
size.hash_stable(hcx, hasher);
194-
align.hash_stable(hcx, hasher);
195-
mutability.hash_stable(hcx, hasher);
196186
}
197187
}
198188

src/librustc/mir/interpret/allocation.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ use rustc_data_structures::sorted_map::SortedMap;
1313
use rustc_target::abi::HasDataLayout;
1414
use std::borrow::Cow;
1515

16-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
16+
#[derive(
17+
Clone,
18+
Debug,
19+
Eq,
20+
PartialEq,
21+
PartialOrd,
22+
Ord,
23+
Hash,
24+
RustcEncodable,
25+
RustcDecodable,
26+
HashStable,
27+
)]
1728
pub struct Allocation<Tag=(),Extra=()> {
1829
/// The actual bytes of the allocation.
1930
/// Note that the bytes of a pointer represent the offset of the pointer.

0 commit comments

Comments
 (0)