about summary refs log tree commit diff
path: root/tests/ui/coroutine/static-coroutine.rs
blob: eba6336d342fe06086da49737bde4bf1e2d73307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//@ 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(()));
}