Skip to content

Commit

Permalink
Add a regression test for #39137
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 9, 2022
1 parent 0ca3565 commit bfd5bfe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/ui/deriving/deriving-hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -73,4 +84,13 @@ fn main() {
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);
}

0 comments on commit bfd5bfe

Please sign in to comment.