summaryrefslogtreecommitdiffstats
path: root/tests/ui/generator/yield-in-box.rs
blob: dd6fa7c151aa7b82f93d0a964738e363eea551f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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));
}