From 27fe671a559504c25d3d05050c6f504d0b243683 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Thu, 27 Jun 2024 15:09:45 +1000 Subject: [PATCH] Fix Hash for EndianReader Since we have a manual PartialEq implementation, we need a matching manual Hash implementation. --- src/read/endian_reader.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/read/endian_reader.rs b/src/read/endian_reader.rs index c35267ef..5e65b4d1 100644 --- a/src/read/endian_reader.rs +++ b/src/read/endian_reader.rs @@ -5,6 +5,7 @@ use alloc::rc::Rc; use alloc::string::String; use alloc::sync::Arc; use core::fmt::Debug; +use core::hash::{Hash, Hasher}; use core::ops::{Deref, Index, Range, RangeFrom, RangeTo}; use core::slice; use core::str; @@ -116,7 +117,7 @@ pub type EndianArcSlice = EndianReader>; /// pub type MmapFileReader = gimli::EndianReader; /// # fn test(_: &MmapFileReader) { } /// ``` -#[derive(Debug, Clone, Copy, Hash)] +#[derive(Debug, Clone, Copy)] pub struct EndianReader where Endian: Endianity, @@ -144,6 +145,17 @@ where { } +impl Hash for EndianReader +where + Endian: Endianity, + T: CloneStableDeref + Debug, +{ + fn hash(&self, state: &mut H) { + // This must match the `PartialEq` implementation. + self.bytes().hash(state); + } +} + // This is separated out from `EndianReader` so that we can avoid running afoul // of borrowck. We need to `read_slice(&mut self, ...) -> &[u8]` and then call // `self.endian.read_whatever` on the result. The problem is that the returned