about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-11 14:47:26 +0000
committerbors <bors@rust-lang.org>2023-12-11 14:47:26 +0000
commitaaeb4dd3a93a6be4cba5eb173f35453803994773 (patch)
tree3029ce6433ddfe6b520fa473bd7a7af154c5c842
parent5ade8523a830eb8aea5cd0a3ddfb0a2467853e27 (diff)
parent4d3701958abbbf56083a59a814bb6b3a0f6d2c80 (diff)
downloadrust-aaeb4dd3a93a6be4cba5eb173f35453803994773.tar.gz
rust-aaeb4dd3a93a6be4cba5eb173f35453803994773.zip
Auto merge of #3222 - RalfJung:waker-noop, r=RalfJung
tests: use Waker::noop instead of defining our own Waker
-rw-r--r--src/tools/miri/tests/pass/async-fn.rs13
-rw-r--r--src/tools/miri/tests/pass/dyn-star.rs18
-rw-r--r--src/tools/miri/tests/pass/future-self-referential.rs18
-rw-r--r--src/tools/miri/tests/pass/issues/issue-miri-2068.rs18
-rw-r--r--src/tools/miri/tests/pass/move-data-across-await-point.rs13
5 files changed, 17 insertions, 63 deletions
diff --git a/src/tools/miri/tests/pass/async-fn.rs b/src/tools/miri/tests/pass/async-fn.rs
index 1d5d9a27cc8..69f35afe86c 100644
--- a/src/tools/miri/tests/pass/async-fn.rs
+++ b/src/tools/miri/tests/pass/async-fn.rs
@@ -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);
diff --git a/src/tools/miri/tests/pass/dyn-star.rs b/src/tools/miri/tests/pass/dyn-star.rs
index 1fac16352a4..8e26c4850fa 100644
--- a/src/tools/miri/tests/pass/dyn-star.rs
+++ b/src/tools/miri/tests/pass/dyn-star.rs
@@ -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 {
diff --git a/src/tools/miri/tests/pass/future-self-referential.rs b/src/tools/miri/tests/pass/future-self-referential.rs
index 763eceeb6f0..38cb700fd58 100644
--- a/src/tools/miri/tests/pass/future-self-referential.rs
+++ b/src/tools/miri/tests/pass/future-self-referential.rs
@@ -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 {
diff --git a/src/tools/miri/tests/pass/issues/issue-miri-2068.rs b/src/tools/miri/tests/pass/issues/issue-miri-2068.rs
index fe4078f7710..f18c4a3a065 100644
--- a/src/tools/miri/tests/pass/issues/issue-miri-2068.rs
+++ b/src/tools/miri/tests/pass/issues/issue-miri-2068.rs
@@ -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,
diff --git a/src/tools/miri/tests/pass/move-data-across-await-point.rs b/src/tools/miri/tests/pass/move-data-across-await-point.rs
index 5990d66fbdd..9bea6ea5742 100644
--- a/src/tools/miri/tests/pass/move-data-across-await-point.rs
+++ b/src/tools/miri/tests/pass/move-data-across-await-point.rs
@@ -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);