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 https://github.com/rust-lang/rust/issues/39137
This commit is contained in:
Matthias Krüger 2022-10-16 17:51:30 +02:00 committed by GitHub
commit 91c7d02e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,17 @@ fn fake_hash<A: Hash>(v: &mut Vec<u8>, a: A) {
a.hash(&mut FakeHasher(v));
}
struct OnlyOneByteHasher;
impl Hasher for OnlyOneByteHasher {
fn finish(&self) -> u64 {
unreachable!()
}
fn write(&mut self, bytes: &[u8]) {
assert_eq!(bytes.len(), 1);
}
}
fn main() {
let person1 = Person {
id: 5,
@ -73,4 +84,13 @@ enum SingleVariantEnum {
let mut v = vec![];
fake_hash(&mut v, SingleVariantEnum::A(17));
assert_eq!(vec![17], v);
// issue #39137
#[repr(u8)]
#[derive(Hash)]
enum E {
A,
B,
}
E::A.hash(&mut OnlyOneByteHasher);
}