1 // revisions: no_drop_tracking drop_tracking drop_tracking_mir
2 // [drop_tracking] compile-flags: -Zdrop-tracking
3 // [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
7 #![feature(never_type)]
9 use std::future::Future;
11 // See if we can run a basic `async fn`
12 pub async fn foo(x: &u32, y: u32) -> u32 {
16 let y = async { *y + *z }.await;
22 async fn add(x: u32, y: u32) -> u32 {
23 let a = async { x + y };
27 async fn build_aggregate(a: u32, b: u32, c: u32, d: u32) -> u32 {
28 let x = (add(a, b).await, add(c, d).await);
37 async fn includes_never(crash: bool, x: u32) -> u32 {
38 let result = async { x * x }.await;
44 result *= async { x + x }.await;
49 async fn partial_init(x: u32) -> u32 {
50 #[allow(unreachable_code)]
51 let _x: (String, !) = (String::new(), return async { x + x }.await);
54 async fn read_exact(_from: &mut &[u8], _to: &mut [u8]) -> Option<()> {
58 async fn hello_world() {
60 let mut reader = &data[..];
62 let mut marker = [0u8; 1];
63 read_exact(&mut reader, &mut marker).await.unwrap();
66 fn run_fut<T>(fut: impl Future<Output = T>) -> T {
68 use std::task::{Context, Poll, Wake, Waker};
71 impl Wake for MyWaker {
72 fn wake(self: Arc<Self>) {
77 let waker = Waker::from(Arc::new(MyWaker));
78 let mut context = Context::from_waker(&waker);
80 let mut pinned = Box::pin(fut);
82 match pinned.as_mut().poll(&mut context) {
83 Poll::Pending => continue,
84 Poll::Ready(v) => return v,
91 assert_eq!(run_fut(foo(&x, 7)), 31);
92 assert_eq!(run_fut(build_aggregate(1, 2, 3, 4)), 10);
93 assert_eq!(run_fut(includes_never(false, 4)), 16);
94 assert_eq!(run_fut(partial_init(4)), 8);
95 run_fut(hello_world());