2018-09-06 14:41:12 +02:00
|
|
|
//@ run-pass
|
|
|
|
|
2024-04-11 13:15:34 +00:00
|
|
|
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
2017-10-07 16:36:28 +02:00
|
|
|
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
2024-04-11 13:15:34 +00:00
|
|
|
use std::pin::Pin;
|
2017-10-07 16:36:28 +02:00
|
|
|
|
|
|
|
fn main() {
|
2024-04-11 13:15:34 +00:00
|
|
|
let mut coroutine = #[coroutine]
|
|
|
|
static || {
|
2018-03-20 00:48:41 +01:00
|
|
|
let a = true;
|
|
|
|
let b = &a;
|
|
|
|
yield;
|
|
|
|
assert_eq!(b as *const _, &a as *const _);
|
2017-10-07 16:36:28 +02: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 20:49:38 +02: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 22:12:27 +01:00
|
|
|
}
|