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