Skip to content

Commit 7448e79

Browse files
committed
Auto merge of #1550 - RalfJung:vecdeque, r=RalfJung
test VecDeque::iter_mut aliasing Blocked on rust-lang/rust#76911
2 parents 6a342a6 + 63a0f04 commit 7448e79

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

ci.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function run_tests {
2525
./miri test --locked
2626
if ! [ -n "${MIRI_TEST_TARGET+exists}" ]; then
2727
# Only for host architecture: tests with MIR optimizations
28-
#FIXME: Only testing opt level 1 due to <https://github.com/rust-lang/rust/issues/77564>.
29-
MIRIFLAGS="-Z mir-opt-level=1" ./miri test --locked
28+
MIRIFLAGS="-Z mir-opt-level=3" ./miri test --locked
3029
fi
3130
# "miri test" has built the sysroot for us, now this should pass without
3231
# any interactive questions.

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
efbaa413061c2a6e52f06f00a60ee7830fcf3ea5
1+
c9ced8523bbb90561385aab305232f2167228a83

tests/run-pass/vecdeque.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
use std::collections::VecDeque;
22

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+
315
fn main() {
416
let mut dst = VecDeque::new();
517
dst.push_front(Box::new(1));
@@ -18,6 +30,21 @@ fn main() {
1830
println!("{:?}", VecDeque::<u32>::new().iter());
1931

2032
for a in dst {
21-
assert_eq!(*a, 2);
33+
assert_eq!(*a, 2);
2234
}
35+
36+
// # Aliasing tests.
37+
let mut v = std::collections::VecDeque::new();
38+
v.push_back(1);
39+
v.push_back(2);
40+
41+
// Test `fold` bad aliasing.
42+
let mut it = v.iter_mut();
43+
let ref0 = it.next().unwrap();
44+
let sum = it.fold(0, |x, y| x + *y);
45+
assert_eq!(*ref0 + sum, 3);
46+
47+
// Test general iterator aliasing.
48+
v.push_front(0);
49+
test_all_refs(&mut 0, v.iter_mut());
2350
}

0 commit comments

Comments
 (0)