]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/in-trait/async-example.rs
Rollup merge of #105482 - wesleywiser:fix_debuginfo_ub, r=tmiasko
[rust.git] / src / test / ui / async-await / in-trait / async-example.rs
1 // check-pass
2 // edition: 2021
3
4 #![feature(async_fn_in_trait)]
5 #![allow(incomplete_features)]
6
7 trait MyTrait {
8     async fn foo(&self) -> i32;
9     async fn bar(&self) -> i32;
10 }
11
12 impl MyTrait for i32 {
13     async fn foo(&self) -> i32 {
14         *self
15     }
16
17     async fn bar(&self) -> i32 {
18         self.foo().await
19     }
20 }
21
22 fn main() {
23     let x = 5;
24     // Calling from non-async context
25     let _ = x.foo();
26     let _ = x.bar();
27     // Calling from async block in non-async context
28     async {
29         let _: i32 = x.foo().await;
30         let _: i32 = x.bar().await;
31     };
32 }