1 use std::collections::HashMap;
2 use std::hash::BuildHasher;
4 // Gather all references from a mutable iterator and make sure Miri notices if
5 // using them is dangerous.
6 fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
7 // Gather all those references.
8 let mut refs: Vec<&mut T> = iter.collect();
9 // Use them all. Twice, to be sure we got all interleavings.
10 for r in refs.iter_mut() {
11 std::mem::swap(dummy, r);
14 std::mem::swap(dummy, r);
18 fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
20 assert_eq!(map.values().fold(0, |x, y| x + y), 0);
26 assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2); // check the right things are in the table now
28 // Inserting again replaces the existing entries
30 map.insert(i, num - 1 - i);
32 assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2);
34 test_all_refs(&mut 13, map.values_mut());
38 // hashbrown uses Miri on its own CI; we just do a smoketest here.
39 smoketest_map(HashMap::new());