1
Fork 0

coverage: Use Waker::noop in async tests

This commit is contained in:
Zalathar 2023-12-15 16:38:27 +11:00
parent 604f185fae
commit 5764ccc5e8
9 changed files with 134 additions and 353 deletions

View file

@ -1,4 +1,6 @@
// compile-flags: --edition=2018
#![feature(coverage_attribute)]
#![feature(noop_waker)]
// edition: 2018
fn non_async_func() {
println!("non_async_func was covered");
@ -30,22 +32,14 @@ fn main() {
}
mod executor {
use core::{
future::Future,
pin::Pin,
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
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 = unsafe { Pin::new_unchecked(&mut future) };
use std::hint::unreachable_unchecked;
static VTABLE: RawWakerVTable = RawWakerVTable::new(
|_| unsafe { unreachable_unchecked() }, // clone
|_| unsafe { unreachable_unchecked() }, // wake
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
|_| (),
);
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
let mut future = pin!(future);
let waker = Waker::noop();
let mut context = Context::from_waker(&waker);
loop {