Skip to content

Commit a6741b0

Browse files
committed
Auto merge of #1541 - RalfJung:rustup, r=RalfJung
Rustup, expand collection tests
2 parents dc0a54c + e61be0b commit a6741b0

File tree

6 files changed

+93
-8
lines changed

6 files changed

+93
-8
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e114d6228b948ce056de0bcdec2603c8e89d3727
1+
a1894e4afe1a39f718cc27232a5a2f0d02b501f6

tests/run-pass/zero-sized-binary-heap-push.rs renamed to tests/run-pass/binary-heap.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BinaryHeap;
22
use std::iter::Iterator;
33

4-
fn main() {
4+
fn zero_sized_push() {
55
const N: usize = 8;
66

77
for len in 0..N {
@@ -16,3 +16,22 @@ fn main() {
1616
tester.clear();
1717
}
1818
}
19+
20+
fn drain() {
21+
let mut heap = (0..128i32).collect::<BinaryHeap<_>>();
22+
23+
assert!(!heap.is_empty());
24+
25+
let mut sum = 0;
26+
for x in heap.drain() {
27+
sum += x;
28+
}
29+
assert_eq!(sum, 127*128/2);
30+
31+
assert!(heap.is_empty());
32+
}
33+
34+
fn main() {
35+
zero_sized_push();
36+
drain();
37+
}

tests/run-pass/btreemap.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ pub enum Foo {
77
_C,
88
}
99

10+
// Gather all references from a mutable iterator and make sure Miri notices if
11+
// using them is dangerous.
12+
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
13+
// Gather all those references.
14+
let mut refs: Vec<&mut T> = iter.collect();
15+
// Use them all. Twice, to be sure we got all interleavings.
16+
for r in refs.iter_mut() {
17+
std::mem::swap(dummy, r);
18+
}
19+
for r in refs {
20+
std::mem::swap(dummy, r);
21+
}
22+
}
23+
1024
pub fn main() {
1125
let mut b = BTreeSet::new();
1226
b.insert(Foo::A("\'"));
@@ -19,11 +33,14 @@ pub fn main() {
1933
// Also test a lower-alignment type, where the NodeHeader overlaps with
2034
// the keys.
2135
let mut b = BTreeSet::new();
22-
b.insert(1024);
23-
b.insert(7);
36+
b.insert(1024u16);
37+
b.insert(7u16);
2438

2539
let mut b = BTreeMap::new();
26-
b.insert("bar", 1024);
27-
b.insert("baz", 7);
28-
for _val in b.iter_mut() {}
40+
b.insert(format!("bar"), 1024);
41+
b.insert(format!("baz"), 7);
42+
for i in 0..60 {
43+
b.insert(format!("key{}", i), i);
44+
}
45+
test_all_refs(&mut 13, b.values_mut());
2946
}

tests/run-pass/hashmap.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
use std::collections::HashMap;
22
use std::hash::BuildHasher;
33

4+
// Gather all references from a mutable iterator and make sure Miri notices if
5+
// using them is dangerous.
6+
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
7+
// Gather all those references.
8+
let mut refs: Vec<&mut T> = iter.collect();
9+
// Use them all. Twice, to be sure we got all interleavings.
10+
for r in refs.iter_mut() {
11+
std::mem::swap(dummy, r);
12+
}
13+
for r in refs {
14+
std::mem::swap(dummy, r);
15+
}
16+
}
17+
418
fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
519
map.insert(0, 0);
620
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
@@ -16,6 +30,8 @@ fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
1630
map.insert(i, num-1-i);
1731
}
1832
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
33+
34+
test_all_refs(&mut 13, map.values_mut());
1935
}
2036

2137
fn main() {

tests/run-pass/linked-list.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ use std::collections::LinkedList;
44
fn list_from<T: Clone>(v: &[T]) -> LinkedList<T> {
55
v.iter().cloned().collect()
66
}
7-
7+
8+
// Gather all references from a mutable iterator and make sure Miri notices if
9+
// using them is dangerous.
10+
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
11+
// Gather all those references.
12+
let mut refs: Vec<&mut T> = iter.collect();
13+
// Use them all. Twice, to be sure we got all interleavings.
14+
for r in refs.iter_mut() {
15+
std::mem::swap(dummy, r);
16+
}
17+
for r in refs {
18+
std::mem::swap(dummy, r);
19+
}
20+
}
21+
822
fn main() {
923
let mut m = list_from(&[0, 2, 4, 6, 8]);
1024
let len = m.len();
@@ -30,6 +44,9 @@ fn main() {
3044
}
3145

3246
assert_eq!(m.len(), 3 + len * 2);
47+
let mut m2 = m.clone();
3348
assert_eq!(m.into_iter().collect::<Vec<_>>(),
3449
[-10, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 99]);
50+
51+
test_all_refs(&mut 13, m2.iter_mut());
3552
}

tests/run-pass/vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Gather all references from a mutable iterator and make sure Miri notices if
2+
// using them is dangerous.
3+
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
4+
// Gather all those references.
5+
let mut refs: Vec<&mut T> = iter.collect();
6+
// Use them all. Twice, to be sure we got all interleavings.
7+
for r in refs.iter_mut() {
8+
std::mem::swap(dummy, r);
9+
}
10+
for r in refs {
11+
std::mem::swap(dummy, r);
12+
}
13+
}
14+
115
fn make_vec() -> Vec<u8> {
216
let mut v = Vec::with_capacity(4);
317
v.push(1);
@@ -53,6 +67,8 @@ fn vec_iter_and_mut() {
5367
*i += 1;
5468
}
5569
assert_eq!(v.iter().sum::<i32>(), 2+3+4+5);
70+
71+
test_all_refs(&mut 13, v.iter_mut());
5672
}
5773

5874
fn vec_iter_and_mut_rev() {

0 commit comments

Comments
 (0)