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

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

22 lines
660 B
Rust
Raw Normal View History

//@ run-pass
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
2023-10-19 16:06:43 +00:00
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 _);
};
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
}