]> git.proxmox.com Git - rustc.git/blob - tests/ui/coroutine/yield-while-ref-reborrowed.rs
bump version to 1.80.1+dfsg1-1~bpo12+pve1
[rustc.git] / tests / ui / coroutine / yield-while-ref-reborrowed.rs
1 #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
2
3 use std::cell::Cell;
4 use std::ops::{Coroutine, CoroutineState};
5 use std::pin::Pin;
6
7 fn reborrow_shared_ref(x: &i32) {
8 // This is OK -- we have a borrow live over the yield, but it's of
9 // data that outlives the coroutine.
10 let mut b = #[coroutine]
11 move || {
12 let a = &*x;
13 yield ();
14 println!("{}", a);
15 };
16 Pin::new(&mut b).resume(());
17 }
18
19 fn reborrow_mutable_ref(x: &mut i32) {
20 // This is OK -- we have a borrow live over the yield, but it's of
21 // data that outlives the coroutine.
22 let mut b = #[coroutine]
23 move || {
24 let a = &mut *x;
25 yield ();
26 println!("{}", a);
27 };
28 Pin::new(&mut b).resume(());
29 }
30
31 fn reborrow_mutable_ref_2(x: &mut i32) {
32 // ...but not OK to go on using `x`.
33 let mut b = #[coroutine]
34 || {
35 let a = &mut *x;
36 yield ();
37 println!("{}", a);
38 };
39 println!("{}", x); //~ ERROR
40 Pin::new(&mut b).resume(());
41 }
42
43 fn main() {}