File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff line change 1- efbaa413061c2a6e52f06f00a60ee7830fcf3ea5
1+ c9ced8523bbb90561385aab305232f2167228a83
Original file line number Diff line number Diff line change 11use 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+
315fn 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}
You can’t perform that action at this time.
0 commit comments