mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
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(()));
|
|
}
|