aef0f4024a
And suggest adding the `#[coroutine]` to the closure
22 lines
660 B
Rust
22 lines
660 B
Rust
//@ run-pass
|
|
|
|
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
|
use std::pin::Pin;
|
|
|
|
fn main() {
|
|
let mut coroutine = #[coroutine]
|
|
static || {
|
|
let a = true;
|
|
let b = &a;
|
|
yield;
|
|
assert_eq!(b as *const _, &a as *const _);
|
|
};
|
|
// SAFETY: We shadow the original coroutine variable so have no safe API to
|
|
// move it after this point.
|
|
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(()));
|
|
}
|