Skip to content

Commit 9810fdd

Browse files
authored
Fix Hash for EndianReader (gimli-rs#723)
Since we have a manual PartialEq implementation, we need a matching manual Hash implementation.
1 parent f1097e3 commit 9810fdd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/read/endian_reader.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use alloc::rc::Rc;
55
use alloc::string::String;
66
use alloc::sync::Arc;
77
use core::fmt::Debug;
8+
use core::hash::{Hash, Hasher};
89
use core::ops::{Deref, Index, Range, RangeFrom, RangeTo};
910
use core::slice;
1011
use core::str;
@@ -116,7 +117,7 @@ pub type EndianArcSlice<Endian> = EndianReader<Endian, Arc<[u8]>>;
116117
/// pub type MmapFileReader<Endian> = gimli::EndianReader<Endian, ArcMmapFile>;
117118
/// # fn test(_: &MmapFileReader<gimli::NativeEndian>) { }
118119
/// ```
119-
#[derive(Debug, Clone, Copy, Hash)]
120+
#[derive(Debug, Clone, Copy)]
120121
pub struct EndianReader<Endian, T>
121122
where
122123
Endian: Endianity,
@@ -144,6 +145,17 @@ where
144145
{
145146
}
146147

148+
impl<Endian, T> Hash for EndianReader<Endian, T>
149+
where
150+
Endian: Endianity,
151+
T: CloneStableDeref<Target = [u8]> + Debug,
152+
{
153+
fn hash<H: Hasher>(&self, state: &mut H) {
154+
// This must match the `PartialEq` implementation.
155+
self.bytes().hash(state);
156+
}
157+
}
158+
147159
// This is separated out from `EndianReader` so that we can avoid running afoul
148160
// of borrowck. We need to `read_slice(&mut self, ...) -> &[u8]` and then call
149161
// `self.endian.read_whatever` on the result. The problem is that the returned

0 commit comments

Comments
 (0)