mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Test CopyTaggedPtr
's HashStable
impl
This commit is contained in:
parent
251f662e4d
commit
36f5918bf1
@ -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 crate::stable_hasher::{HashStable, StableHasher};
|
||||
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
|
||||
|
||||
#[test]
|
||||
@ -25,6 +26,24 @@ fn smoke() {
|
||||
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.
|
||||
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> CopyTaggedPtr<P, T, true> {
|
||||
CopyTaggedPtr::new(ptr, tag)
|
||||
|
Loading…
Reference in New Issue
Block a user