about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-12-14 18:34:29 +0000
committerMichael Goulet <michael@errs.io>2023-12-14 18:34:29 +0000
commit3c17514ae98f758bee1eb2578297a3bc16137875 (patch)
tree756fbb10ddaabb1002391d08337e046d4ae169f9
parent56d25ba5ea3515ba2b361b6c4636373734eb27cc (diff)
downloadrust-3c17514ae98f758bee1eb2578297a3bc16137875.tar.gz
rust-3c17514ae98f758bee1eb2578297a3bc16137875.zip
Use the Waker::noop API in tests
-rw-r--r--tests/ui/async-await/in-trait/async-default-fn-overridden.rs24
-rw-r--r--tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs25
-rw-r--r--tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr26
-rw-r--r--tests/ui/coroutine/async_gen_fn_iter.rs24
-rw-r--r--tests/ui/dyn-star/dispatch-on-pin-mut.rs24
5 files changed, 41 insertions, 82 deletions
diff --git a/tests/ui/async-await/in-trait/async-default-fn-overridden.rs b/tests/ui/async-await/in-trait/async-default-fn-overridden.rs
index c8fd2d8f6c2..491dfcc6ae0 100644
--- a/tests/ui/async-await/in-trait/async-default-fn-overridden.rs
+++ b/tests/ui/async-await/in-trait/async-default-fn-overridden.rs
@@ -1,6 +1,7 @@
 // run-pass
 // edition:2021
 
+#![feature(noop_waker)]
 
 use std::future::Future;
 
@@ -32,33 +33,18 @@ async fn async_main() {
 // ------------------------------------------------------------------------- //
 // Implementation Details Below...
 
-use std::pin::Pin;
+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 ()) {}
-
 fn main() {
-    let mut fut = async_main();
+    let mut fut = pin!(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 {
-        match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
+        match fut.as_mut().poll(ctx) {
             Poll::Pending => {}
             Poll::Ready(()) => break,
         }
diff --git a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs
index 18b0fa4856d..f21abf012ba 100644
--- a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs
+++ b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs
@@ -2,6 +2,7 @@
 // known-bug: #108309
 
 #![feature(min_specialization)]
+#![feature(noop_waker)]
 
 struct MyStruct;
 
@@ -35,34 +36,18 @@ async fn indirection<T>(x: T) -> &'static str {
 // ------------------------------------------------------------------------- //
 // Implementation Details Below...
 
-use std::future::Future;
-use std::pin::Pin;
+use std::pin::{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 ()) {}
-
 fn main() {
-    let mut fut = async_main();
+    let mut fut = pin!(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 {
-        match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
+        match fut.as_mut().poll(ctx) {
             Poll::Pending => {}
             Poll::Ready(()) => break,
         }
diff --git a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr
index 5e2be08623b..0560cd9c5fe 100644
--- a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr
+++ b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr
@@ -1,11 +1,11 @@
 error[E0053]: method `foo` has an incompatible type for trait
-  --> $DIR/dont-project-to-specializable-projection.rs:13:5
+  --> $DIR/dont-project-to-specializable-projection.rs:14:5
    |
 LL |     default async fn foo(_: T) -> &'static str {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found future
    |
 note: type in trait
-  --> $DIR/dont-project-to-specializable-projection.rs:9:5
+  --> $DIR/dont-project-to-specializable-projection.rs:10:5
    |
 LL |     async fn foo(_: T) -> &'static str;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,13 +13,29 @@ LL |     async fn foo(_: T) -> &'static str;
               found signature `fn(_) -> impl Future<Output = &'static str>`
 
 error: async associated function in trait cannot be specialized
-  --> $DIR/dont-project-to-specializable-projection.rs:13:5
+  --> $DIR/dont-project-to-specializable-projection.rs:14:5
    |
 LL |     default async fn foo(_: T) -> &'static str {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: specialization behaves in inconsistent and surprising ways with async functions in traits, and for now is disallowed
 
-error: aborting due to 2 previous errors
+error[E0599]: no method named `poll` found for struct `Pin<&mut impl Future<Output = ()>>` in the current scope
+  --> $DIR/dont-project-to-specializable-projection.rs:50:28
+   |
+LL |         match fut.as_mut().poll(ctx) {
+   |                            ^^^^ method not found in `Pin<&mut impl Future<Output = ()>>`
+  --> $SRC_DIR/core/src/future/future.rs:LL:COL
+   |
+   = note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
+   |
+   = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+   |
+LL + use std::future::Future;
+   |
+
+error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0053`.
+Some errors have detailed explanations: E0053, E0599.
+For more information about an error, try `rustc --explain E0053`.
diff --git a/tests/ui/coroutine/async_gen_fn_iter.rs b/tests/ui/coroutine/async_gen_fn_iter.rs
index 4fa29e1095a..ec6464d0048 100644
--- a/tests/ui/coroutine/async_gen_fn_iter.rs
+++ b/tests/ui/coroutine/async_gen_fn_iter.rs
@@ -3,6 +3,7 @@
 // run-pass
 
 #![feature(gen_blocks, async_iterator)]
+#![feature(noop_waker)]
 
 // make sure that a ridiculously simple async gen fn works as an iterator.
 
@@ -42,7 +43,7 @@ async fn async_main() {
 // ------------------------------------------------------------------------- //
 // Implementation Details Below...
 
-use std::pin::Pin;
+use std::pin::{Pin, pin};
 use std::task::*;
 use std::async_iter::AsyncIterator;
 use std::future::Future;
@@ -69,30 +70,15 @@ impl<'s, S: AsyncIterator> Future for Next<'s, S> where S: Unpin {
     }
 }
 
-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 ()) {}
-
 fn main() {
-    let mut fut = async_main();
+    let mut fut = pin!(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 {
-        match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
+        match fut.as_mut().poll(ctx) {
             Poll::Pending => {}
             Poll::Ready(()) => break,
         }
diff --git a/tests/ui/dyn-star/dispatch-on-pin-mut.rs b/tests/ui/dyn-star/dispatch-on-pin-mut.rs
index 5774c8b2a67..c4ae279e6c1 100644
--- a/tests/ui/dyn-star/dispatch-on-pin-mut.rs
+++ b/tests/ui/dyn-star/dispatch-on-pin-mut.rs
@@ -4,6 +4,7 @@
 
 #![feature(dyn_star)]
 //~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+#![feature(noop_waker)]
 
 use std::future::Future;
 
@@ -18,33 +19,18 @@ async fn async_main() {
 // ------------------------------------------------------------------------- //
 // Implementation Details Below...
 
-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 ()) {}
+use std::pin::pin;
 
 fn main() {
-    let mut fut = async_main();
+    let mut fut = pin!(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 {
-        match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
+        match fut.as_mut().poll(ctx) {
             Poll::Pending => {}
             Poll::Ready(()) => break,
         }