mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Improve core::hash coverage
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user