1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(generators, generator_trait)]
13 use std::ops::{GeneratorState, Generator};
16 fn yield_during_iter_owned_data(x: Vec<i32>) {
17 // The generator owns `x`, so we error out when yielding with a
18 // reference to it. This winds up becoming a rather confusing
19 // regionck error -- in particular, we would freeze with the
20 // reference in scope, and it doesn't live long enough.
22 for p in &x { //~ ERROR
28 fn yield_during_iter_borrowed_slice(x: &[i32]) {
36 fn yield_during_iter_borrowed_slice_2() {
37 let mut x = vec![22_i32];
46 fn yield_during_iter_borrowed_slice_3() {
47 // OK to take a mutable ref to `x` and yield
48 // up pointers from it:
49 let mut x = vec![22_i32];
58 fn yield_during_iter_borrowed_slice_4() {
59 // ...but not OK to do that while reading
61 let mut x = vec![22_i32];
67 println!("{}", x[0]); //~ ERROR
71 fn yield_during_range_iter() {