]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/yield-while-local-borrowed.rs
Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDenton
[rust.git] / src / test / ui / generator / yield-while-local-borrowed.rs
1 #![feature(generators, generator_trait)]
2
3 use std::ops::{GeneratorState, Generator};
4 use std::cell::Cell;
5 use std::pin::Pin;
6
7 fn borrow_local_inline() {
8     // Not OK to yield with a borrow of a temporary.
9     //
10     // (This error occurs because the region shows up in the type of
11     // `b` and gets extended by region inference.)
12     let mut b = move || {
13         let a = &mut 3;
14         //~^ ERROR borrow may still be in use when generator yields
15         yield();
16         println!("{}", a);
17     };
18     Pin::new(&mut b).resume(());
19 }
20
21 fn borrow_local_inline_done() {
22     // No error here -- `a` is not in scope at the point of `yield`.
23     let mut b = move || {
24         {
25             let a = &mut 3;
26         }
27         yield();
28     };
29     Pin::new(&mut b).resume(());
30 }
31
32 fn borrow_local() {
33     // Not OK to yield with a borrow of a temporary.
34     //
35     // (This error occurs because the region shows up in the type of
36     // `b` and gets extended by region inference.)
37     let mut b = move || {
38         let a = 3;
39         {
40             let b = &a;
41             //~^ ERROR borrow may still be in use when generator yields
42             yield();
43             println!("{}", b);
44         }
45     };
46     Pin::new(&mut b).resume(());
47 }
48
49 fn main() { }