2018-09-06 12:41:12 +00:00
|
|
|
// run-pass
|
|
|
|
|
2023-10-19 21:46:28 +00:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2017-10-07 14:36:28 +00:00
|
|
|
|
2018-10-04 18:49:38 +00:00
|
|
|
use std::pin::Pin;
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
2017-10-07 14:36:28 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-10-19 21:46:28 +00:00
|
|
|
let mut coroutine = static || {
|
2018-03-19 23:48:41 +00:00
|
|
|
let a = true;
|
|
|
|
let b = &a;
|
|
|
|
yield;
|
|
|
|
assert_eq!(b as *const _, &a as *const _);
|
2017-10-07 14:36:28 +00:00
|
|
|
};
|
2023-10-19 21:46:28 +00:00
|
|
|
// SAFETY: We shadow the original coroutine variable so have no safe API to
|
2018-10-04 18:49:38 +00:00
|
|
|
// move it after this point.
|
2023-10-19 21:46:28 +00:00
|
|
|
let mut coroutine = unsafe { Pin::new_unchecked(&mut coroutine) };
|
|
|
|
assert_eq!(coroutine.as_mut().resume(()), CoroutineState::Yielded(()));
|
|
|
|
assert_eq!(coroutine.as_mut().resume(()), CoroutineState::Complete(()));
|
2017-12-22 21:12:27 +00:00
|
|
|
}
|