]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/async-fn.rs
1608ea1888942834af37d87235973dd6b107c7fe
[rust.git] / tests / run-pass / async-fn.rs
1 #![feature(
2     async_await,
3     await_macro,
4     futures_api,
5 )]
6
7 use std::{future::Future, pin::Pin, task::Poll, ptr};
8 use std::task::{Waker, RawWaker, RawWakerVTable, Context};
9
10 // See if we can run a basic `async fn`
11 pub async fn foo(x: &u32, y: u32) -> u32 {
12     let y = &y;
13     let z = 9;
14     let z = &z;
15     let y = await!(async { *y + *z });
16     let a = 10;
17     let a = &a;
18     *x + y + *a
19 }
20
21 fn raw_waker_clone(_this: *const ()) -> RawWaker {
22     panic!("unimplemented");
23 }
24 fn raw_waker_wake(_this: *const ()) {
25     panic!("unimplemented");
26 }
27 fn raw_waker_wake_by_ref(_this: *const ()) {
28     panic!("unimplemented");
29 }
30 fn raw_waker_drop(_this: *const ()) {}
31
32 static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
33     raw_waker_clone,
34     raw_waker_wake,
35     raw_waker_wake_by_ref,
36     raw_waker_drop,
37 );
38
39 fn main() {
40     let x = 5;
41     let mut fut = foo(&x, 7);
42     let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
43     let mut context = Context::from_waker(&waker);
44     assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
45 }