1 //@compile-flags: -Zmiri-strict-provenance
2 #![feature(btree_drain_filter)]
3 use std::collections::{BTreeMap, BTreeSet};
6 #[derive(PartialEq, Eq, PartialOrd, Ord)]
13 // Gather all references from a mutable iterator and make sure Miri notices if
14 // using them is dangerous.
15 fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
16 // Gather all those references.
17 let mut refs: Vec<&mut T> = iter.collect();
18 // Use them all. Twice, to be sure we got all interleavings.
19 for r in refs.iter_mut() {
20 std::mem::swap(dummy, r);
23 std::mem::swap(dummy, r);
28 let mut b = BTreeSet::new();
29 b.insert(Foo::A("\'"));
30 b.insert(Foo::A("/="));
31 b.insert(Foo::A("#"));
32 b.insert(Foo::A("0o"));
33 assert!(b.remove(&Foo::A("/=")));
34 assert!(!b.remove(&Foo::A("/=")));
36 // Also test a lower-alignment type, where the NodeHeader overlaps with
38 let mut b = BTreeSet::new();
42 let mut b = BTreeMap::new();
43 b.insert(format!("bar"), 1024);
44 b.insert(format!("baz"), 7);
46 b.insert(format!("key{}", i), i);
48 test_all_refs(&mut 13, b.values_mut());
50 // Test forgetting the drain.
51 let mut d = b.drain_filter(|_, i| *i < 30);