2024-09-06 00:52:32 +00:00
|
|
|
LL| |#![feature(coverage_attribute)]
|
|
|
|
LL| |#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
|
|
|
|
LL| |#![feature(noop_waker)]
|
|
|
|
LL| |#![rustfmt::skip]
|
|
|
|
LL| |//@ edition: 2021
|
|
|
|
LL| |
|
|
|
|
LL| |#[coverage(off)]
|
|
|
|
LL| |async fn ready() -> u8 { 1 }
|
|
|
|
LL| |
|
|
|
|
LL| 1|async fn await_ready() -> u8 {
|
2024-09-05 22:25:25 +00:00
|
|
|
LL| 1| // await should be covered even if the function never yields
|
2024-09-06 00:52:32 +00:00
|
|
|
LL| 1| ready()
|
2024-09-05 22:25:25 +00:00
|
|
|
LL| 1| .await
|
2024-09-06 00:52:32 +00:00
|
|
|
LL| 1|}
|
|
|
|
LL| |
|
|
|
|
LL| 1|fn main() {
|
|
|
|
LL| 1| let mut future = Box::pin(await_ready());
|
|
|
|
LL| 1| executor::block_on(future.as_mut());
|
|
|
|
LL| 1|}
|
|
|
|
LL| |
|
|
|
|
LL| |mod executor {
|
|
|
|
LL| | use core::future::Future;
|
|
|
|
LL| | use core::pin::pin;
|
|
|
|
LL| | use core::task::{Context, Poll, Waker};
|
|
|
|
LL| |
|
|
|
|
LL| | #[coverage(off)]
|
|
|
|
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
|
|
|
|
LL| | let mut future = pin!(future);
|
|
|
|
LL| | let mut context = Context::from_waker(Waker::noop());
|
|
|
|
LL| |
|
|
|
|
LL| | loop {
|
|
|
|
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
|
|
|
|
LL| | break val;
|
|
|
|
LL| | }
|
|
|
|
LL| | }
|
|
|
|
LL| | }
|
|
|
|
LL| |}
|
|
|
|
|