Skip to content

Commit bfa1331

Browse files
author
blake2-ppc
committed
std::hash: Add testcase for colliding hashes of tuples
Add a testcase that verifies that (s, t) and (u, v) don't collide even if s + t == u + v (concatenation).
1 parent 73fdacb commit bfa1331

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: src/libstd/hash.rs

+14
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,18 @@ mod tests {
595595
fn test_float_hashes_of_zero() {
596596
assert_eq!(0.0.hash(), (-0.0).hash());
597597
}
598+
599+
#[test]
600+
fn test_hash_no_concat_alias() {
601+
let s = ("aa", "bb");
602+
let t = ("aabb", "");
603+
let u = ("a", "abb");
604+
605+
let v = (&[1u8], &[0u8, 0], &[0u8]);
606+
let w = (&[1u8, 0, 0, 0], &[], &[]);
607+
608+
assert!(v != w);
609+
assert!(s.hash() != t.hash() && s.hash() != u.hash());
610+
assert!(v.hash() != w.hash());
611+
}
598612
}

0 commit comments

Comments
 (0)