rust/tests/ui/coroutine/static-coroutine.rs
Oli Scherer aef0f4024a Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00

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(()));
}