diff options
| -rw-r--r-- | src/tools/miri/tests/fail/coroutine-pinned-moved.rs | 3 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass/coroutine.rs | 223 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs | 3 |
3 files changed, 149 insertions, 80 deletions
diff --git a/src/tools/miri/tests/fail/coroutine-pinned-moved.rs b/src/tools/miri/tests/fail/coroutine-pinned-moved.rs index 8648be2a264..46ec58810a6 100644 --- a/src/tools/miri/tests/fail/coroutine-pinned-moved.rs +++ b/src/tools/miri/tests/fail/coroutine-pinned-moved.rs @@ -7,7 +7,8 @@ use std::{ }; fn firstn() -> impl Coroutine<Yield = u64, Return = ()> { - #[coroutine] static move || { + #[coroutine] + static move || { let mut num = 0; let num = &mut num; *num += 0; diff --git a/src/tools/miri/tests/pass/coroutine.rs b/src/tools/miri/tests/pass/coroutine.rs index e76abfc4185..7822c136d91 100644 --- a/src/tools/miri/tests/pass/coroutine.rs +++ b/src/tools/miri/tests/pass/coroutine.rs @@ -43,94 +43,144 @@ fn basic() { panic!() } - finish(1, false, #[coroutine] || yield 1); + finish( + 1, + false, + #[coroutine] + || yield 1, + ); - finish(3, false, #[coroutine] || { - let mut x = 0; - yield 1; - x += 1; - yield 1; - x += 1; - yield 1; - assert_eq!(x, 2); - }); + finish( + 3, + false, + #[coroutine] + || { + let mut x = 0; + yield 1; + x += 1; + yield 1; + x += 1; + yield 1; + assert_eq!(x, 2); + }, + ); - finish(7 * 8 / 2, false, #[coroutine] || { - for i in 0..8 { - yield i; - } - }); + finish( + 7 * 8 / 2, + false, + #[coroutine] + || { + for i in 0..8 { + yield i; + } + }, + ); - finish(1, false, #[coroutine] || { - if true { - yield 1; - } else { - } - }); + finish( + 1, + false, + #[coroutine] + || { + if true { + yield 1; + } else { + } + }, + ); - finish(1, false, #[coroutine] || { - if false { - } else { - yield 1; - } - }); + finish( + 1, + false, + #[coroutine] + || { + if false { + } else { + yield 1; + } + }, + ); - finish(2, false, #[coroutine] || { - if { - yield 1; - false - } { + finish( + 2, + false, + #[coroutine] + || { + if { + yield 1; + false + } { + yield 1; + panic!() + } yield 1; - panic!() - } - yield 1; - }); + }, + ); // also test self-referential coroutines assert_eq!( - finish(5, true, #[coroutine] static || { - let mut x = 5; - let y = &mut x; - *y = 5; - yield *y; - *y = 10; - x - }), + finish( + 5, + true, + #[coroutine] + static || { + let mut x = 5; + let y = &mut x; + *y = 5; + yield *y; + *y = 10; + x + } + ), 10 ); assert_eq!( - finish(5, true, #[coroutine] || { - let mut x = Box::new(5); - let y = &mut *x; - *y = 5; - yield *y; - *y = 10; - *x - }), + finish( + 5, + true, + #[coroutine] + || { + let mut x = Box::new(5); + let y = &mut *x; + *y = 5; + yield *y; + *y = 10; + *x + } + ), 10 ); let b = true; - finish(1, false, #[coroutine] || { - yield 1; - if b { - return; - } - #[allow(unused)] - let x = never(); - #[allow(unreachable_code)] - yield 2; - drop(x); - }); - - finish(3, false, #[coroutine] || { - yield 1; - #[allow(unreachable_code)] - let _x: (String, !) = (String::new(), { + finish( + 1, + false, + #[coroutine] + || { + yield 1; + if b { + return; + } + #[allow(unused)] + let x = never(); + #[allow(unreachable_code)] yield 2; - return; - }); - }); + drop(x); + }, + ); + + finish( + 3, + false, + #[coroutine] + || { + yield 1; + #[allow(unreachable_code)] + let _x: (String, !) = (String::new(), { + yield 2; + return; + }); + }, + ); } fn smoke_resume_arg() { @@ -172,7 +222,8 @@ fn smoke_resume_arg() { } drain( - &mut #[coroutine] |mut b| { + &mut #[coroutine] + |mut b| { while b != 0 { b = yield (b + 1); } @@ -181,21 +232,35 @@ fn smoke_resume_arg() { vec![(1, Yielded(2)), (-45, Yielded(-44)), (500, Yielded(501)), (0, Complete(-1))], ); - expect_drops(2, || drain(&mut #[coroutine] |a| yield a, vec![(DropMe, Yielded(DropMe))])); + expect_drops(2, || { + drain( + &mut #[coroutine] + |a| yield a, + vec![(DropMe, Yielded(DropMe))], + ) + }); expect_drops(6, || { drain( - &mut #[coroutine] |a| yield yield a, + &mut #[coroutine] + |a| yield yield a, vec![(DropMe, Yielded(DropMe)), (DropMe, Yielded(DropMe)), (DropMe, Complete(DropMe))], ) }); #[allow(unreachable_code)] - expect_drops(2, || drain(&mut #[coroutine] |a| yield return a, vec![(DropMe, Complete(DropMe))])); + expect_drops(2, || { + drain( + &mut #[coroutine] + |a| yield return a, + vec![(DropMe, Complete(DropMe))], + ) + }); expect_drops(2, || { drain( - &mut #[coroutine] |a: DropMe| { + &mut #[coroutine] + |a: DropMe| { if false { yield () } else { a } }, vec![(DropMe, Complete(DropMe))], @@ -205,7 +270,8 @@ fn smoke_resume_arg() { expect_drops(4, || { drain( #[allow(unused_assignments, unused_variables)] - &mut #[coroutine] |mut a: DropMe| { + &mut #[coroutine] + |mut a: DropMe| { a = yield; a = yield; a = yield; @@ -228,7 +294,8 @@ fn uninit_fields() { } fn run<T>(x: bool, y: bool) { - let mut c = #[coroutine] || { + let mut c = #[coroutine] + || { if x { let _a: T; if y { diff --git a/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs b/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs index bb98e024a0a..259fc72d392 100644 --- a/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs +++ b/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs @@ -8,7 +8,8 @@ use std::{ }; fn firstn() -> impl Coroutine<Yield = u64, Return = ()> { - #[coroutine] static move || { + #[coroutine] + static move || { let mut num = 0; let num = &mut num; |
