rust/tests/ui/generator/static-generators.rs

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

21 lines
620 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 _);
};
2020-09-08 21:37:18 -05:00
// SAFETY: We shadow the original generator variable so have no safe API to
2018-10-04 13:49:38 -05:00
// 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
}