mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
25 lines
624 B
Rust
25 lines
624 B
Rust
// run-pass
|
|
// 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;
|
|
|
|
fn main() {
|
|
let x = 0i32;
|
|
|| { //~ WARN unused generator that must be used
|
|
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));
|
|
}
|