about summary refs log tree commit diff
path: root/library/coretests
diff options
context:
space:
mode:
authorChristian Poveda <christian.poveda@ferrous-systems.com>2025-09-12 13:54:11 -0500
committerChristian Poveda <christian.poveda@ferrous-systems.com>2025-09-12 13:54:15 -0500
commit79643ad48a9cd72066d2683fb7744380bb286074 (patch)
tree834ae3cfc4a05745eaa07f7b4112e9aba519ada9 /library/coretests
parenta171994070dc18c3a32fc1aa2d98cf03ae96b63e (diff)
downloadrust-79643ad48a9cd72066d2683fb7744380bb286074.tar.gz
rust-79643ad48a9cd72066d2683fb7744380bb286074.zip
Improve `core::hash` coverage
Diffstat (limited to 'library/coretests')
-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;