2019-12-31 05:10:52 -06:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::hash::BuildHasher;
|
2017-06-02 20:35:33 -05:00
|
|
|
|
2020-09-10 01:38:43 -05:00
|
|
|
// Gather all references from a mutable iterator and make sure Miri notices if
|
|
|
|
// using them is dangerous.
|
|
|
|
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
|
|
|
|
// Gather all those references.
|
|
|
|
let mut refs: Vec<&mut T> = iter.collect();
|
|
|
|
// Use them all. Twice, to be sure we got all interleavings.
|
|
|
|
for r in refs.iter_mut() {
|
|
|
|
std::mem::swap(dummy, r);
|
|
|
|
}
|
|
|
|
for r in refs {
|
|
|
|
std::mem::swap(dummy, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 04:34:15 -05:00
|
|
|
fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
|
2017-06-22 02:12:47 -05:00
|
|
|
map.insert(0, 0);
|
2017-06-02 20:35:33 -05:00
|
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
|
|
|
|
|
2019-05-01 13:43:43 -05:00
|
|
|
let num = 25;
|
2017-06-22 02:12:47 -05:00
|
|
|
for i in 1..num {
|
|
|
|
map.insert(i, i);
|
|
|
|
}
|
|
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
|
|
|
|
|
|
|
|
// Inserting again replaces the existing entries
|
|
|
|
for i in 0..num {
|
|
|
|
map.insert(i, num-1-i);
|
|
|
|
}
|
|
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
|
2020-09-10 01:38:43 -05:00
|
|
|
|
|
|
|
test_all_refs(&mut 13, map.values_mut());
|
2019-04-07 17:17:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-03-23 04:34:15 -05:00
|
|
|
// hashbrown uses Miri on its own CI; we just do a smoketest here.
|
|
|
|
smoketest_map(HashMap::new());
|
2017-06-02 20:35:33 -05:00
|
|
|
}
|