]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/async-await-let-else.rs
Rollup merge of #107027 - GuillaumeGomez:rm-extra-removal, r=tmiasko
[rust.git] / tests / ui / async-await / async-await-let-else.rs
1 // edition:2021
2 // revisions: drop-tracking no-drop-tracking
3 // [drop-tracking] compile-flags: -Zdrop-tracking=yes
4 // [no-drop-tracking] compile-flags: -Zdrop-tracking=no
5
6 use std::rc::Rc;
7
8 async fn foo(x: Option<bool>) {
9     let Some(_) = x else {
10         let r = Rc::new(());
11         bar().await
12     };
13 }
14
15 async fn bar() -> ! {
16     panic!()
17 }
18
19 fn is_send<T: Send>(_: T) {}
20
21 async fn foo2(x: Option<bool>) {
22     let Some(_) = x else {
23         bar2(Rc::new(())).await
24     };
25 }
26
27 async fn bar2<T>(_: T) -> ! {
28     panic!()
29 }
30
31 async fn foo3(x: Option<bool>) {
32     let Some(_) = x else {
33         (Rc::new(()), bar().await);
34         return;
35     };
36 }
37
38 async fn foo4(x: Option<bool>) {
39     let Some(_) = x else {
40         let r = Rc::new(());
41         bar().await;
42         println!("{:?}", r);
43         return;
44     };
45 }
46
47 fn main() {
48     is_send(foo(Some(true)));
49     //~^ ERROR cannot be sent between threads safely
50     is_send(foo2(Some(true)));
51     //~^ ERROR cannot be sent between threads safely
52     is_send(foo3(Some(true)));
53     //~^ ERROR cannot be sent between threads safely
54     is_send(foo4(Some(true)));
55     //~^ ERROR cannot be sent between threads safely
56 }