about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJana Dönszelmann <jonathan@donsz.nl>2025-09-13 02:40:46 +0200
committerGitHub <noreply@github.com>2025-09-13 02:40:46 +0200
commitec0f3bd2edb427a27bac20b1ac7c7a5bd842bd37 (patch)
tree5a7a8696d8b409c35263e190fe04bf6287a2cd24
parent7928be014c7a6b97b2fcc01f8f8b7c0f6290a300 (diff)
parent79643ad48a9cd72066d2683fb7744380bb286074 (diff)
downloadrust-ec0f3bd2edb427a27bac20b1ac7c7a5bd842bd37.tar.gz
rust-ec0f3bd2edb427a27bac20b1ac7c7a5bd842bd37.zip
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
-rw-r--r--library/coretests/tests/hash/mod.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/library/coretests/tests/hash/mod.rs b/library/coretests/tests/hash/mod.rs
index 1f10a4733b0..043a3ee7423 100644
--- a/library/coretests/tests/hash/mod.rs
+++ b/library/coretests/tests/hash/mod.rs
@@ -53,12 +53,14 @@ fn test_writer_hasher() {
     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 test_writer_hasher() {
     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;