Skip to content

Commit 91c7d02

Browse files
authored
Rollup merge of #102857 - saethlin:derived-enum-hash-test, r=Mark-Simulacrum
Add a regression test for #39137 The problem in the issue has been fixed in the meantime, so since this adds a regression test I think this closes #39137
2 parents 8be3ce9 + bfd5bfe commit 91c7d02

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/ui/deriving/deriving-hash.rs

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ fn fake_hash<A: Hash>(v: &mut Vec<u8>, a: A) {
4444
a.hash(&mut FakeHasher(v));
4545
}
4646

47+
struct OnlyOneByteHasher;
48+
impl Hasher for OnlyOneByteHasher {
49+
fn finish(&self) -> u64 {
50+
unreachable!()
51+
}
52+
53+
fn write(&mut self, bytes: &[u8]) {
54+
assert_eq!(bytes.len(), 1);
55+
}
56+
}
57+
4758
fn main() {
4859
let person1 = Person {
4960
id: 5,
@@ -73,4 +84,13 @@ fn main() {
7384
let mut v = vec![];
7485
fake_hash(&mut v, SingleVariantEnum::A(17));
7586
assert_eq!(vec![17], v);
87+
88+
// issue #39137
89+
#[repr(u8)]
90+
#[derive(Hash)]
91+
enum E {
92+
A,
93+
B,
94+
}
95+
E::A.hash(&mut OnlyOneByteHasher);
7696
}

0 commit comments

Comments
 (0)