rust/tests/run-pass/async-fn.rs

42 lines
1.0 KiB
Rust
Raw Normal View History

2019-04-06 15:11:59 -05:00
// ignore-test FIXME ignored to let https://github.com/rust-lang/rust/pull/59119 land
2018-11-20 09:09:06 -06:00
#![feature(
async_await,
await_macro,
futures_api,
)]
2019-02-15 02:32:54 -06:00
use std::{future::Future, pin::Pin, task::Poll, ptr};
use std::task::{Waker, RawWaker, RawWakerVTable};
2018-11-20 09:09:06 -06:00
// See if we can run a basic `async fn`
pub async fn foo(x: &u32, y: u32) -> u32 {
let y = &y;
let z = 9;
let z = &z;
let y = await!(async { *y + *z });
let a = 10;
let a = &a;
*x + y + *a
}
2019-02-15 02:32:54 -06:00
fn raw_waker_clone(_this: *const ()) -> RawWaker {
panic!("unimplemented");
}
fn raw_waker_wake(_this: *const ()) {
panic!("unimplemented");
}
fn raw_waker_drop(_this: *const ()) {}
2018-11-20 09:09:06 -06:00
2019-02-15 02:32:54 -06:00
static RAW_WAKER: RawWakerVTable = RawWakerVTable {
clone: raw_waker_clone,
wake: raw_waker_wake,
drop: raw_waker_drop,
};
2018-11-20 09:09:06 -06:00
2019-02-15 02:32:54 -06:00
fn main() {
2018-11-20 09:09:06 -06:00
let x = 5;
let mut fut = foo(&x, 7);
2019-02-15 02:32:54 -06:00
let waker = unsafe { Waker::new_unchecked(RawWaker::new(ptr::null(), &RAW_WAKER)) };
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&waker), Poll::Ready(31));
2018-11-20 09:09:06 -06:00
}