2018-09-06 12:41:12 +00:00
|
|
|
// run-pass
|
2017-09-20 13:36:20 +00:00
|
|
|
// Test that box-statements with yields in them work.
|
|
|
|
|
2021-09-28 00:00:00 +00:00
|
|
|
#![feature(generators, box_syntax, generator_trait)]
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::ops::Generator;
|
|
|
|
use std::ops::GeneratorState;
|
2017-09-20 13:36:20 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = 0i32;
|
2020-07-28 00:00:00 +00:00
|
|
|
|| { //~ WARN unused generator that must be used
|
2017-09-20 13:36:20 +00:00
|
|
|
let y = 2u32;
|
|
|
|
{
|
|
|
|
let _t = box (&x, yield 0, &y);
|
|
|
|
}
|
|
|
|
match box (&x, yield 0, &y) {
|
|
|
|
_t => {}
|
|
|
|
}
|
|
|
|
};
|
2021-09-28 00:00:00 +00:00
|
|
|
|
|
|
|
let mut g = |_| box yield;
|
|
|
|
assert_eq!(Pin::new(&mut g).resume(1), GeneratorState::Yielded(()));
|
|
|
|
assert_eq!(Pin::new(&mut g).resume(2), GeneratorState::Complete(box 2));
|
2017-09-20 13:36:20 +00:00
|
|
|
}
|