Test CopyTaggedPtr
's HashStable
impl
This commit is contained in:
parent
251f662e4d
commit
36f5918bf1
2 changed files with 26 additions and 0 deletions
|
@ -261,3 +261,10 @@ unsafe impl Tag for Tag2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl<HCX> crate::stable_hasher::HashStable<HCX> for Tag2 {
|
||||||
|
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut crate::stable_hasher::StableHasher) {
|
||||||
|
(*self as u8).hash_stable(hcx, hasher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
use crate::stable_hasher::{HashStable, StableHasher};
|
||||||
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
|
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -25,6 +26,24 @@ fn smoke() {
|
||||||
assert!(ptr::eq(copy.pointer(), reference));
|
assert!(ptr::eq(copy.pointer(), reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stable_hash_hashes_as_tuple() {
|
||||||
|
let hash_packed = {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
tag_ptr(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
|
||||||
|
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
|
let hash_tupled = {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(hash_packed, hash_tupled);
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
|
/// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
|
||||||
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> CopyTaggedPtr<P, T, true> {
|
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> CopyTaggedPtr<P, T, true> {
|
||||||
CopyTaggedPtr::new(ptr, tag)
|
CopyTaggedPtr::new(ptr, tag)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue