Auto merge of #3222 - RalfJung:waker-noop, r=RalfJung
tests: use Waker::noop instead of defining our own Waker
This commit is contained in:
commit
aaeb4dd3a9
5 changed files with 17 additions and 63 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#![feature(never_type)]
|
||||
#![feature(noop_waker)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
|
|
@ -58,17 +59,9 @@ async fn hello_world() {
|
|||
}
|
||||
|
||||
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll, Wake, Waker};
|
||||
use std::task::{Context, Poll, Waker};
|
||||
|
||||
struct MyWaker;
|
||||
impl Wake for MyWaker {
|
||||
fn wake(self: Arc<Self>) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
let waker = Waker::from(Arc::new(MyWaker));
|
||||
let waker = Waker::noop();
|
||||
let mut context = Context::from_waker(&waker);
|
||||
|
||||
let mut pinned = Box::pin(fut);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![feature(dyn_star)]
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![feature(noop_waker)]
|
||||
// rustfmt destroys `dyn* Trait` syntax
|
||||
#![rustfmt::skip]
|
||||
|
||||
|
|
@ -89,25 +90,10 @@ fn dispatch_on_pin_mut() {
|
|||
use std::pin::Pin;
|
||||
use std::task::*;
|
||||
|
||||
pub fn noop_waker() -> Waker {
|
||||
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
|
||||
|
||||
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
|
||||
unsafe { Waker::from_raw(raw) }
|
||||
}
|
||||
|
||||
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
|
||||
|
||||
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
|
||||
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
|
||||
}
|
||||
|
||||
unsafe fn noop(_p: *const ()) {}
|
||||
|
||||
let mut fut = async_main();
|
||||
|
||||
// Poll loop, just to test the future...
|
||||
let waker = noop_waker();
|
||||
let waker = Waker::noop();
|
||||
let ctx = &mut Context::from_waker(&waker);
|
||||
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//@revisions: stack tree
|
||||
//@[tree]compile-flags: -Zmiri-tree-borrows
|
||||
#![feature(noop_waker)]
|
||||
|
||||
use std::future::*;
|
||||
use std::marker::PhantomPinned;
|
||||
|
|
@ -29,19 +30,6 @@ impl Future for Delay {
|
|||
}
|
||||
}
|
||||
|
||||
fn mk_waker() -> Waker {
|
||||
use std::sync::Arc;
|
||||
|
||||
struct MyWaker;
|
||||
impl Wake for MyWaker {
|
||||
fn wake(self: Arc<Self>) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
Waker::from(Arc::new(MyWaker))
|
||||
}
|
||||
|
||||
async fn do_stuff() {
|
||||
(&mut Delay::new(1)).await;
|
||||
}
|
||||
|
|
@ -89,7 +77,7 @@ impl Future for DoStuff {
|
|||
}
|
||||
|
||||
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
|
||||
let waker = mk_waker();
|
||||
let waker = Waker::noop();
|
||||
let mut context = Context::from_waker(&waker);
|
||||
|
||||
let mut pinned = pin!(fut);
|
||||
|
|
@ -102,7 +90,7 @@ fn run_fut<T>(fut: impl Future<Output = T>) -> T {
|
|||
}
|
||||
|
||||
fn self_referential_box() {
|
||||
let waker = mk_waker();
|
||||
let waker = Waker::noop();
|
||||
let cx = &mut Context::from_waker(&waker);
|
||||
|
||||
async fn my_fut() -> i32 {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,13 @@
|
|||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
use core::task::{Context, Poll};
|
||||
#![feature(noop_waker)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
struct NopWaker;
|
||||
|
||||
impl std::task::Wake for NopWaker {
|
||||
fn wake(self: Arc<Self>) {}
|
||||
}
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll, Waker};
|
||||
|
||||
pub fn fuzzing_block_on<O, F: Future<Output = O>>(fut: F) -> O {
|
||||
let mut fut = std::pin::pin!(fut);
|
||||
let waker = std::task::Waker::from(Arc::new(NopWaker));
|
||||
let mut context = std::task::Context::from_waker(&waker);
|
||||
let waker = Waker::noop();
|
||||
let mut context = Context::from_waker(&waker);
|
||||
loop {
|
||||
match fut.as_mut().poll(&mut context) {
|
||||
Poll::Ready(v) => return v,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![feature(noop_waker)]
|
||||
use std::future::Future;
|
||||
use std::ptr;
|
||||
|
||||
|
|
@ -53,17 +54,9 @@ fn data_moved() {
|
|||
}
|
||||
|
||||
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll, Wake, Waker};
|
||||
use std::task::{Context, Poll, Waker};
|
||||
|
||||
struct MyWaker;
|
||||
impl Wake for MyWaker {
|
||||
fn wake(self: Arc<Self>) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
let waker = Waker::from(Arc::new(MyWaker));
|
||||
let waker = Waker::noop();
|
||||
let mut context = Context::from_waker(&waker);
|
||||
|
||||
let mut pinned = Box::pin(fut);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue