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