rust/tests/ui/coroutine/static-coroutine.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
620 B
Rust
Raw Normal View History

// run-pass
2023-10-19 21:46:28 +00:00
#![feature(coroutines, coroutine_trait)]
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};
fn main() {
2023-10-19 21:46:28 +00:00
let mut coroutine = static || {
let a = true;
let b = &a;
yield;
assert_eq!(b as *const _, &a as *const _);
};
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
}