diff --git a/rust-version b/rust-version index d2cf18f80f1..8e33b80ff68 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -e114d6228b948ce056de0bcdec2603c8e89d3727 +a1894e4afe1a39f718cc27232a5a2f0d02b501f6 diff --git a/tests/run-pass/zero-sized-binary-heap-push.rs b/tests/run-pass/binary-heap.rs similarity index 58% rename from tests/run-pass/zero-sized-binary-heap-push.rs rename to tests/run-pass/binary-heap.rs index c9312d79bfd..8b8fa6458e6 100644 --- a/tests/run-pass/zero-sized-binary-heap-push.rs +++ b/tests/run-pass/binary-heap.rs @@ -1,7 +1,7 @@ use std::collections::BinaryHeap; use std::iter::Iterator; -fn main() { +fn zero_sized_push() { const N: usize = 8; for len in 0..N { @@ -16,3 +16,22 @@ fn main() { tester.clear(); } } + +fn drain() { + let mut heap = (0..128i32).collect::>(); + + assert!(!heap.is_empty()); + + let mut sum = 0; + for x in heap.drain() { + sum += x; + } + assert_eq!(sum, 127*128/2); + + assert!(heap.is_empty()); +} + +fn main() { + zero_sized_push(); + drain(); +} diff --git a/tests/run-pass/btreemap.rs b/tests/run-pass/btreemap.rs index e2049d94803..603674cc450 100644 --- a/tests/run-pass/btreemap.rs +++ b/tests/run-pass/btreemap.rs @@ -7,6 +7,20 @@ pub enum Foo { _C, } +// 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) { + // 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); + } +} + pub fn main() { let mut b = BTreeSet::new(); b.insert(Foo::A("\'")); @@ -19,11 +33,14 @@ pub fn main() { // Also test a lower-alignment type, where the NodeHeader overlaps with // the keys. let mut b = BTreeSet::new(); - b.insert(1024); - b.insert(7); + b.insert(1024u16); + b.insert(7u16); let mut b = BTreeMap::new(); - b.insert("bar", 1024); - b.insert("baz", 7); - for _val in b.iter_mut() {} + 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()); } diff --git a/tests/run-pass/hashmap.rs b/tests/run-pass/hashmap.rs index 488fe6afe65..215f762efcc 100644 --- a/tests/run-pass/hashmap.rs +++ b/tests/run-pass/hashmap.rs @@ -1,6 +1,20 @@ use std::collections::HashMap; use std::hash::BuildHasher; +// 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) { + // 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); + } +} + fn smoketest_map(mut map: HashMap) { map.insert(0, 0); assert_eq!(map.values().fold(0, |x, y| x+y), 0); @@ -16,6 +30,8 @@ fn smoketest_map(mut map: HashMap) { map.insert(i, num-1-i); } assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); + + test_all_refs(&mut 13, map.values_mut()); } fn main() { diff --git a/tests/run-pass/linked-list.rs b/tests/run-pass/linked-list.rs index 976a35da606..0ed9d6032d0 100644 --- a/tests/run-pass/linked-list.rs +++ b/tests/run-pass/linked-list.rs @@ -4,7 +4,21 @@ fn list_from(v: &[T]) -> LinkedList { v.iter().cloned().collect() } - + +// 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) { + // 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); + } +} + fn main() { let mut m = list_from(&[0, 2, 4, 6, 8]); let len = m.len(); @@ -30,6 +44,9 @@ fn main() { } assert_eq!(m.len(), 3 + len * 2); + let mut m2 = m.clone(); assert_eq!(m.into_iter().collect::>(), [-10, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 99]); + + test_all_refs(&mut 13, m2.iter_mut()); } diff --git a/tests/run-pass/vec.rs b/tests/run-pass/vec.rs index 731358564b8..5fea4a9147a 100644 --- a/tests/run-pass/vec.rs +++ b/tests/run-pass/vec.rs @@ -1,3 +1,17 @@ +// 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) { + // 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); + } +} + fn make_vec() -> Vec { let mut v = Vec::with_capacity(4); v.push(1); @@ -53,6 +67,8 @@ fn vec_iter_and_mut() { *i += 1; } assert_eq!(v.iter().sum::(), 2+3+4+5); + + test_all_refs(&mut 13, v.iter_mut()); } fn vec_iter_and_mut_rev() {