rust/src/test/ui/generator/static-generators.rs

21 lines
616 B
Rust
Raw Normal View History

// run-pass
#![feature(generators, generator_trait)]
2018-10-04 13:49:38 -05:00
use std::pin::Pin;
use std::ops::{Generator, GeneratorState};
fn main() {
let mut generator = static || {
let a = true;
let b = &a;
yield;
assert_eq!(b as *const _, &a as *const _);
};
2018-10-04 13:49:38 -05:00
// Safety: We shadow the original generator variable so have no safe API to
// move it after this point.
let mut generator = unsafe { Pin::new_unchecked(&mut generator) };
assert_eq!(generator.as_mut().resume(), GeneratorState::Yielded(()));
assert_eq!(generator.as_mut().resume(), GeneratorState::Complete(()));
2017-12-22 15:12:27 -06:00
}