Skip to content

Commit a63f62f

Browse files
authored
Unrolled build for #146481
Rollup merge of #146481 - ferrocene:pvdrz/improve-hash-coverage, r=jhpratt Improve `core::hash` coverage This PR improves the `core::hash` coverage by adding a new test to `coretests` and extending one of the existing tests to use 128-bit integers r? libs
2 parents 4ba1cf9 + 79643ad commit a63f62f

File tree

1 file changed

+13
-0
lines changed
  • library/coretests/tests/hash

1 file changed

+13
-0
lines changed

library/coretests/tests/hash/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ fn test_writer_hasher() {
5353
assert_eq!(hash(&5_u16), 5);
5454
assert_eq!(hash(&5_u32), 5);
5555
assert_eq!(hash(&5_u64), 5);
56+
assert_eq!(hash(&5_u128), 5);
5657
assert_eq!(hash(&5_usize), 5);
5758

5859
assert_eq!(hash(&5_i8), 5);
5960
assert_eq!(hash(&5_i16), 5);
6061
assert_eq!(hash(&5_i32), 5);
6162
assert_eq!(hash(&5_i64), 5);
63+
assert_eq!(hash(&5_i128), 5);
6264
assert_eq!(hash(&5_isize), 5);
6365

6466
assert_eq!(hash(&false), 0);
@@ -85,6 +87,17 @@ fn test_writer_hasher() {
8587
let ptr = ptr::without_provenance_mut::<i32>(5_usize);
8688
assert_eq!(hash(&ptr), 5);
8789

90+
// Use a newtype to test the `Hash::hash_slice` default implementation.
91+
struct Byte(u8);
92+
93+
impl Hash for Byte {
94+
fn hash<H: Hasher>(&self, state: &mut H) {
95+
state.write_u8(self.0)
96+
}
97+
}
98+
99+
assert_eq!(hash(&[Byte(b'a')]), 97 + 1);
100+
88101
if cfg!(miri) {
89102
// Miri cannot hash pointers
90103
return;

0 commit comments

Comments
 (0)