2022-10-03 20:27:11 -05:00
|
|
|
// check-pass
|
|
|
|
// edition: 2021
|
|
|
|
|
|
|
|
#![feature(async_fn_in_trait)]
|
|
|
|
#![allow(incomplete_features)]
|
|
|
|
|
|
|
|
trait MyTrait {
|
|
|
|
async fn foo(&self) -> i32;
|
2022-10-07 11:08:56 -05:00
|
|
|
async fn bar(&self) -> i32;
|
2022-10-03 20:27:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MyTrait for i32 {
|
|
|
|
async fn foo(&self) -> i32 {
|
|
|
|
*self
|
|
|
|
}
|
2022-10-07 11:08:56 -05:00
|
|
|
|
|
|
|
async fn bar(&self) -> i32 {
|
|
|
|
self.foo().await
|
|
|
|
}
|
2022-10-03 20:27:11 -05:00
|
|
|
}
|
|
|
|
|
2022-10-07 11:08:56 -05:00
|
|
|
fn main() {
|
|
|
|
let x = 5;
|
|
|
|
// Calling from non-async context
|
|
|
|
let _ = x.foo();
|
|
|
|
let _ = x.bar();
|
|
|
|
// Calling from async block in non-async context
|
|
|
|
async {
|
2022-10-27 17:47:30 -05:00
|
|
|
let _: i32 = x.foo().await;
|
|
|
|
let _: i32 = x.bar().await;
|
2022-10-07 11:08:56 -05:00
|
|
|
};
|
|
|
|
}
|