]> git.lizzy.rs Git - rust.git/blobdiff - library/core/tests/hash/sip.rs
Rollup merge of #104194 - BoxyUwU:early_binder_docs, r=compiler-errors
[rust.git] / library / core / tests / hash / sip.rs
index 877d0841830551b0b104f0f3d5967e553007278f..3abf6efcfa9ba842d312f4bc4deb1a29a5b61d9b 100644 (file)
@@ -8,7 +8,6 @@
 struct Bytes<'a>(&'a [u8]);
 
 impl<'a> Hash for Bytes<'a> {
-    #[allow(unused_must_use)]
     fn hash<H: Hasher>(&self, state: &mut H) {
         let Bytes(v) = *self;
         state.write(v);
@@ -24,6 +23,20 @@ fn hash<T: Hash>(x: &T) -> u64 {
     hash_with(SipHasher::new(), x)
 }
 
+#[test]
+const fn test_const_sip() {
+    let val1 = 0x45;
+    let val2 = 0xfeed;
+
+    const fn const_hash<T: ~const Hash>(x: &T) -> u64 {
+        let mut st = SipHasher::new();
+        x.hash(&mut st);
+        st.finish()
+    }
+
+    assert!(const_hash(&(val1)) != const_hash(&(val2)));
+}
+
 #[test]
 #[allow(unused_must_use)]
 fn test_siphash_1_3() {