rust/tests/ui/generator/yield-in-box.rs

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

25 lines
624 B
Rust
Raw Normal View History

// run-pass
2017-09-20 13:36:20 +00:00
// Test that box-statements with yields in them work.
#![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;
|| { //~ 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 => {}
}
};
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
}