]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/yield-while-local-borrowed.rs
Fix more tests with `GeneratorState` rename
[rust.git] / src / test / ui / generator / yield-while-local-borrowed.rs
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.
4 //
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.
10
11 #![feature(generators, generator_trait)]
12
13 use std::ops::{GeneratorState, Generator};
14 use std::cell::Cell;
15
16 fn borrow_local_inline() {
17     // Not OK to yield with a borrow of a temporary.
18     //
19     // (This error occurs because the region shows up in the type of
20     // `b` and gets extended by region inference.)
21     let mut b = move || {
22         let a = &3; //~ ERROR
23         yield();
24         println!("{}", a);
25     };
26     b.resume();
27 }
28
29 fn borrow_local_inline_done() {
30     // No error here -- `a` is not in scope at the point of `yield`.
31     let mut b = move || {
32         {
33             let a = &3;
34         }
35         yield();
36     };
37     b.resume();
38 }
39
40 fn borrow_local() {
41     // Not OK to yield with a borrow of a temporary.
42     //
43     // (This error occurs because the region shows up in the type of
44     // `b` and gets extended by region inference.)
45     let mut b = move || {
46         let a = 3;
47         {
48             let b = &a; //~ ERROR
49             yield();
50             println!("{}", b);
51         }
52     };
53     b.resume();
54 }
55
56 fn main() { }