diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2021-12-18 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2021-12-18 00:00:00 +0000 |
| commit | d0281bcb25d779a7b27cd8d5de394f2c9f72f33c (patch) | |
| tree | 02a2e397938115e23d2a056dec30036ed5c50a02 /compiler/rustc_data_structures/src/stable_hasher/tests.rs | |
| parent | d496cca3b161d9f6a3f9202f97e45382281ba749 (diff) | |
| download | rust-d0281bcb25d779a7b27cd8d5de394f2c9f72f33c.tar.gz rust-d0281bcb25d779a7b27cd8d5de394f2c9f72f33c.zip | |
Implement StableHash for BitSet and BitMatrix via Hash
This fixes an issue where bit sets / bit matrices the same word content but a different domain size would receive the same hash.
Diffstat (limited to 'compiler/rustc_data_structures/src/stable_hasher/tests.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/stable_hasher/tests.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/stable_hasher/tests.rs b/compiler/rustc_data_structures/src/stable_hasher/tests.rs index cd6ff96a555..391db67d29d 100644 --- a/compiler/rustc_data_structures/src/stable_hasher/tests.rs +++ b/compiler/rustc_data_structures/src/stable_hasher/tests.rs @@ -71,3 +71,30 @@ fn test_hash_isize() { assert_eq!(h.finalize(), expected); } + +fn hash<T: HashStable<()>>(t: &T) -> u128 { + let mut h = StableHasher::new(); + let ctx = &mut (); + t.hash_stable(ctx, &mut h); + h.finish() +} + +// Check that bit set hash includes the domain size. +#[test] +fn test_hash_bit_set() { + use rustc_index::bit_set::BitSet; + let a: BitSet<usize> = BitSet::new_empty(1); + let b: BitSet<usize> = BitSet::new_empty(2); + assert_ne!(a, b); + assert_ne!(hash(&a), hash(&b)); +} + +// Check that bit matrix hash includes the matrix dimensions. +#[test] +fn test_hash_bit_matrix() { + use rustc_index::bit_set::BitMatrix; + let a: BitMatrix<usize, usize> = BitMatrix::new(1, 1); + let b: BitMatrix<usize, usize> = BitMatrix::new(1, 2); + assert_ne!(a, b); + assert_ne!(hash(&a), hash(&b)); +} |
