Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e114d6228b948ce056de0bcdec2603c8e89d3727
a1894e4afe1a39f718cc27232a5a2f0d02b501f6
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,3 +16,22 @@ fn main() {
tester.clear();
}
}

fn drain() {
let mut heap = (0..128i32).collect::<BinaryHeap<_>>();

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();
}
27 changes: 22 additions & 5 deletions tests/run-pass/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}
}

pub fn main() {
let mut b = BTreeSet::new();
b.insert(Foo::A("\'"));
Expand All @@ -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());
}
16 changes: 16 additions & 0 deletions tests/run-pass/hashmap.rs
Original file line number Diff line number Diff line change
@@ -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<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);
}
}

fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
map.insert(0, 0);
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
Expand All @@ -16,6 +30,8 @@ fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
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() {
Expand Down
19 changes: 18 additions & 1 deletion tests/run-pass/linked-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ use std::collections::LinkedList;
fn list_from<T: Clone>(v: &[T]) -> LinkedList<T> {
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<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);
}
}

fn main() {
let mut m = list_from(&[0, 2, 4, 6, 8]);
let len = m.len();
Expand All @@ -30,6 +44,9 @@ fn main() {
}

assert_eq!(m.len(), 3 + len * 2);
let mut m2 = m.clone();
assert_eq!(m.into_iter().collect::<Vec<_>>(),
[-10, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 99]);

test_all_refs(&mut 13, m2.iter_mut());
}
16 changes: 16 additions & 0 deletions tests/run-pass/vec.rs
Original file line number Diff line number Diff line change
@@ -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<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);
}
}

fn make_vec() -> Vec<u8> {
let mut v = Vec::with_capacity(4);
v.push(1);
Expand Down Expand Up @@ -53,6 +67,8 @@ fn vec_iter_and_mut() {
*i += 1;
}
assert_eq!(v.iter().sum::<i32>(), 2+3+4+5);

test_all_refs(&mut 13, v.iter_mut());
}

fn vec_iter_and_mut_rev() {
Expand Down