summaryrefslogtreecommitdiffstats
path: root/vendor/gix-hashtable/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-hashtable/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-hashtable/src')
-rw-r--r--vendor/gix-hashtable/src/lib.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/gix-hashtable/src/lib.rs b/vendor/gix-hashtable/src/lib.rs
index 6392a9a5c..476600578 100644
--- a/vendor/gix-hashtable/src/lib.rs
+++ b/vendor/gix-hashtable/src/lib.rs
@@ -40,6 +40,15 @@ pub mod hash {
#[derive(Default, Clone, Copy)]
pub struct Hasher(u64);
+ macro_rules! panic_other_writers {
+ ($func:ident, $type:ty) => {
+ #[cold]
+ fn $func(&mut self, _i: $type) {
+ panic!("This hasher only supports manually verified `Hash` implementations")
+ }
+ };
+ }
+
impl std::hash::Hasher for Hasher {
fn finish(&self) -> u64 {
self.0
@@ -49,6 +58,21 @@ pub mod hash {
fn write(&mut self, bytes: &[u8]) {
self.0 = u64::from_ne_bytes(bytes[..8].try_into().unwrap());
}
+
+ // Panic if someone tries to use this with a different function,
+ // only manually verified types should be used with this hasher
+ panic_other_writers!(write_u8, u8);
+ panic_other_writers!(write_u16, u16);
+ panic_other_writers!(write_u32, u32);
+ panic_other_writers!(write_u64, u64);
+ panic_other_writers!(write_u128, u128);
+ panic_other_writers!(write_usize, usize);
+ panic_other_writers!(write_i8, i8);
+ panic_other_writers!(write_i16, i16);
+ panic_other_writers!(write_i32, i32);
+ panic_other_writers!(write_i64, i64);
+ panic_other_writers!(write_i128, i128);
+ panic_other_writers!(write_isize, isize);
}
/// A Hasher for usage with HashMap keys that are already robust hashes (like an `ObjectId`).