Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Waker::noop API in tests #118948

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions tests/ui/async-await/in-trait/async-default-fn-overridden.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-pass
// edition:2021

#![feature(noop_waker)]

use std::future::Future;

Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// known-bug: #108309

#![feature(min_specialization)]
#![feature(noop_waker)]

struct MyStruct;

Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected signature `fn(_) -> impl Future<Output = &'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`.
24 changes: 5 additions & 19 deletions tests/ui/coroutine/async_gen_fn_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
Expand All @@ -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,
}
Expand Down
24 changes: 5 additions & 19 deletions tests/ui/dyn-star/dispatch-on-pin-mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
}
Expand Down
Loading