Improve core::hash coverage

This commit is contained in:
Christian Poveda
2025-09-12 13:54:11 -05:00
parent a171994070
commit 79643ad48a
+13
View File
@@ -53,12 +53,14 @@ fn hash<T: Hash>(t: &T) -> u64 {
assert_eq!(hash(&5_u16), 5);
assert_eq!(hash(&5_u32), 5);
assert_eq!(hash(&5_u64), 5);
assert_eq!(hash(&5_u128), 5);
assert_eq!(hash(&5_usize), 5);
assert_eq!(hash(&5_i8), 5);
assert_eq!(hash(&5_i16), 5);
assert_eq!(hash(&5_i32), 5);
assert_eq!(hash(&5_i64), 5);
assert_eq!(hash(&5_i128), 5);
assert_eq!(hash(&5_isize), 5);
assert_eq!(hash(&false), 0);
@@ -85,6 +87,17 @@ fn hash<T: Hash>(t: &T) -> u64 {
let ptr = ptr::without_provenance_mut::<i32>(5_usize);
assert_eq!(hash(&ptr), 5);
// Use a newtype to test the `Hash::hash_slice` default implementation.
struct Byte(u8);
impl Hash for Byte {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write_u8(self.0)
}
}
assert_eq!(hash(&[Byte(b'a')]), 97 + 1);
if cfg!(miri) {
// Miri cannot hash pointers
return;