2018-09-06 07:41:12 -05:00
|
|
|
// run-pass
|
|
|
|
|
2017-10-07 09:36:28 -05:00
|
|
|
#![feature(generators, generator_trait)]
|
|
|
|
|
2018-10-04 13:49:38 -05:00
|
|
|
use std::pin::Pin;
|
2017-10-07 09:36:28 -05:00
|
|
|
use std::ops::{Generator, GeneratorState};
|
|
|
|
|
|
|
|
fn main() {
|
2018-03-19 18:48:41 -05:00
|
|
|
let mut generator = static || {
|
|
|
|
let a = true;
|
|
|
|
let b = &a;
|
|
|
|
yield;
|
|
|
|
assert_eq!(b as *const _, &a as *const _);
|
2017-10-07 09:36:28 -05:00
|
|
|
};
|
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) };
|
2020-01-25 13:03:10 -06:00
|
|
|
assert_eq!(generator.as_mut().resume(()), GeneratorState::Yielded(()));
|
|
|
|
assert_eq!(generator.as_mut().resume(()), GeneratorState::Complete(()));
|
2017-12-22 15:12:27 -06:00
|
|
|
}
|