Skip to content

Commit 36f5918

Browse files
committed
Test CopyTaggedPtr's HashStable impl
1 parent 251f662 commit 36f5918

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

compiler/rustc_data_structures/src/tagged_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,10 @@ unsafe impl Tag for Tag2 {
261261
}
262262
}
263263
}
264+
265+
#[cfg(test)]
266+
impl<HCX> crate::stable_hasher::HashStable<HCX> for Tag2 {
267+
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut crate::stable_hasher::StableHasher) {
268+
(*self as u8).hash_stable(hcx, hasher);
269+
}
270+
}

compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ptr;
22

3+
use crate::stable_hasher::{HashStable, StableHasher};
34
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
45

56
#[test]
@@ -25,6 +26,24 @@ fn smoke() {
2526
assert!(ptr::eq(copy.pointer(), reference));
2627
}
2728

29+
#[test]
30+
fn stable_hash_hashes_as_tuple() {
31+
let hash_packed = {
32+
let mut hasher = StableHasher::new();
33+
tag_ptr(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
34+
35+
hasher.finalize()
36+
};
37+
38+
let hash_tupled = {
39+
let mut hasher = StableHasher::new();
40+
(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
41+
hasher.finalize()
42+
};
43+
44+
assert_eq!(hash_packed, hash_tupled);
45+
}
46+
2847
/// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
2948
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> CopyTaggedPtr<P, T, true> {
3049
CopyTaggedPtr::new(ptr, tag)

0 commit comments

Comments
 (0)