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