about summary refs log tree commit diff
path: root/tests/coverage/await_ready.rs
blob: 9212a4ba705a8e31085901b3d7f291f91a56a660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![feature(coverage_attribute)]
#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
#![feature(noop_waker)]
#![rustfmt::skip]
//@ edition: 2021

#[coverage(off)]
async fn ready() -> u8 { 1 }

async fn await_ready() -> u8 {
    // await should be covered even if the function never yields
    ready()
        .await
}

fn main() {
    let mut future = Box::pin(await_ready());
    executor::block_on(future.as_mut());
}

mod executor {
    use core::future::Future;
    use core::pin::pin;
    use core::task::{Context, Poll, Waker};

    #[coverage(off)]
    pub fn block_on<F: Future>(mut future: F) -> F::Output {
        let mut future = pin!(future);
        let mut context = Context::from_waker(Waker::noop());

        loop {
            if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
                break val;
            }
        }
    }
}