mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
21 lines
621 B
Rust
21 lines
621 B
Rust
//@ run-pass
|
|
|
|
#![feature(coroutines, coroutine_trait)]
|
|
|
|
use std::pin::Pin;
|
|
use std::ops::{Coroutine, CoroutineState};
|
|
|
|
fn main() {
|
|
let mut 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(()));
|
|
}
|