about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-04-14 11:59:53 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-14 11:59:53 +0000
commit36f5918bf169a7ab5ae24a5aad12dd6ecd20b8c4 (patch)
tree16ab00a52d1bc85bf6a8b1954ca0391bf244013f
parent251f662e4dc50055e8376f3c1bb8ac61ac7148c1 (diff)
downloadrust-36f5918bf169a7ab5ae24a5aad12dd6ecd20b8c4.tar.gz
rust-36f5918bf169a7ab5ae24a5aad12dd6ecd20b8c4.zip
Test `CopyTaggedPtr`'s `HashStable` impl
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr.rs7
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs19
2 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs
index 14f282dcbeb..1fc5dad1d95 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr.rs
@@ -261,3 +261,10 @@ unsafe impl Tag for Tag2 {
         }
     }
 }
+
+#[cfg(test)]
+impl<HCX> crate::stable_hasher::HashStable<HCX> for Tag2 {
+    fn hash_stable(&self, hcx: &mut HCX, hasher: &mut crate::stable_hasher::StableHasher) {
+        (*self as u8).hash_stable(hcx, hasher);
+    }
+}
diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs
index 09e7b59fd64..bfcc2e603de 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs
@@ -1,5 +1,6 @@
 use std::ptr;
 
+use crate::stable_hasher::{HashStable, StableHasher};
 use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
 
 #[test]
@@ -25,6 +26,24 @@ fn smoke() {
     assert!(ptr::eq(copy.pointer(), reference));
 }
 
+#[test]
+fn stable_hash_hashes_as_tuple() {
+    let hash_packed = {
+        let mut hasher = StableHasher::new();
+        tag_ptr(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
+
+        hasher.finalize()
+    };
+
+    let hash_tupled = {
+        let mut hasher = StableHasher::new();
+        (&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
+        hasher.finalize()
+    };
+
+    assert_eq!(hash_packed, hash_tupled);
+}
+
 /// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
 fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> CopyTaggedPtr<P, T, true> {
     CopyTaggedPtr::new(ptr, tag)