2019-02-13 10:22:06 -06:00
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
|
|
|
|
2017-08-28 07:10:59 -05:00
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
|
|
|
pub enum Foo {
|
|
|
|
A(&'static str),
|
|
|
|
_B,
|
|
|
|
_C,
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 07:10:59 -05:00
|
|
|
pub fn main() {
|
2019-02-13 10:22:06 -06:00
|
|
|
let mut b = BTreeSet::new();
|
2017-08-28 07:10:59 -05:00
|
|
|
b.insert(Foo::A("\'"));
|
|
|
|
b.insert(Foo::A("/="));
|
|
|
|
b.insert(Foo::A("#"));
|
|
|
|
b.insert(Foo::A("0o"));
|
2018-10-11 04:24:22 -05:00
|
|
|
assert!(b.remove(&Foo::A("/=")));
|
|
|
|
assert!(!b.remove(&Foo::A("/=")));
|
2019-02-13 10:22:06 -06:00
|
|
|
|
|
|
|
// Also test a lower-alignment type, where the NodeHeader overlaps with
|
|
|
|
// the keys.
|
|
|
|
let mut b = BTreeSet::new();
|
2020-09-10 01:38:43 -05:00
|
|
|
b.insert(1024u16);
|
|
|
|
b.insert(7u16);
|
2019-02-13 10:22:06 -06:00
|
|
|
|
|
|
|
let mut b = BTreeMap::new();
|
2020-09-10 01:38:43 -05:00
|
|
|
b.insert(format!("bar"), 1024);
|
|
|
|
b.insert(format!("baz"), 7);
|
|
|
|
for i in 0..60 {
|
|
|
|
b.insert(format!("key{}", i), i);
|
|
|
|
}
|
|
|
|
test_all_refs(&mut 13, b.values_mut());
|
2017-08-28 07:10:59 -05:00
|
|
|
}
|