1 #![feature(generators, generator_trait)]
3 use std::ops::{GeneratorState, Generator};
7 fn yield_during_iter_owned_data(x: Vec<i32>) {
8 // The generator owns `x`, so we error out when yielding with a
9 // reference to it. This winds up becoming a rather confusing
10 // regionck error -- in particular, we would freeze with the
11 // reference in scope, and it doesn't live long enough.
13 for p in &x { //~ ERROR
19 fn yield_during_iter_borrowed_slice(x: &[i32]) {
27 fn yield_during_iter_borrowed_slice_2() {
28 let mut x = vec![22_i32];
37 fn yield_during_iter_borrowed_slice_3() {
38 // OK to take a mutable ref to `x` and yield
39 // up pointers from it:
40 let mut x = vec![22_i32];
46 Pin::new(&mut b).resume(());
49 fn yield_during_iter_borrowed_slice_4() {
50 // ...but not OK to do that while reading
52 let mut x = vec![22_i32];
58 println!("{}", x[0]); //~ ERROR
59 Pin::new(&mut b).resume(());
62 fn yield_during_range_iter() {
72 Pin::new(&mut b).resume(());