Skip to content

Commit 3c17514

Browse files
Use the Waker::noop API in tests
1 parent 56d25ba commit 3c17514

5 files changed

+41
-82
lines changed

Diff for: tests/ui/async-await/in-trait/async-default-fn-overridden.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22
// edition:2021
33

4+
#![feature(noop_waker)]
45

56
use std::future::Future;
67

@@ -32,33 +33,18 @@ async fn async_main() {
3233
// ------------------------------------------------------------------------- //
3334
// Implementation Details Below...
3435

35-
use std::pin::Pin;
36+
use std::pin::pin;
3637
use std::task::*;
3738

38-
pub fn noop_waker() -> Waker {
39-
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
40-
41-
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
42-
unsafe { Waker::from_raw(raw) }
43-
}
44-
45-
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
46-
47-
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
48-
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
49-
}
50-
51-
unsafe fn noop(_p: *const ()) {}
52-
5339
fn main() {
54-
let mut fut = async_main();
40+
let mut fut = pin!(async_main());
5541

5642
// Poll loop, just to test the future...
57-
let waker = noop_waker();
43+
let waker = Waker::noop();
5844
let ctx = &mut Context::from_waker(&waker);
5945

6046
loop {
61-
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
47+
match fut.as_mut().poll(ctx) {
6248
Poll::Pending => {}
6349
Poll::Ready(()) => break,
6450
}

Diff for: tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// known-bug: #108309
33

44
#![feature(min_specialization)]
5+
#![feature(noop_waker)]
56

67
struct MyStruct;
78

@@ -35,34 +36,18 @@ async fn indirection<T>(x: T) -> &'static str {
3536
// ------------------------------------------------------------------------- //
3637
// Implementation Details Below...
3738

38-
use std::future::Future;
39-
use std::pin::Pin;
39+
use std::pin::{pin, Pin};
4040
use std::task::*;
4141

42-
pub fn noop_waker() -> Waker {
43-
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
44-
45-
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
46-
unsafe { Waker::from_raw(raw) }
47-
}
48-
49-
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
50-
51-
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
52-
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
53-
}
54-
55-
unsafe fn noop(_p: *const ()) {}
56-
5742
fn main() {
58-
let mut fut = async_main();
43+
let mut fut = pin!(async_main());
5944

6045
// Poll loop, just to test the future...
61-
let waker = noop_waker();
46+
let waker = Waker::noop();
6247
let ctx = &mut Context::from_waker(&waker);
6348

6449
loop {
65-
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
50+
match fut.as_mut().poll(ctx) {
6651
Poll::Pending => {}
6752
Poll::Ready(()) => break,
6853
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
error[E0053]: method `foo` has an incompatible type for trait
2-
--> $DIR/dont-project-to-specializable-projection.rs:13:5
2+
--> $DIR/dont-project-to-specializable-projection.rs:14:5
33
|
44
LL | default async fn foo(_: T) -> &'static str {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found future
66
|
77
note: type in trait
8-
--> $DIR/dont-project-to-specializable-projection.rs:9:5
8+
--> $DIR/dont-project-to-specializable-projection.rs:10:5
99
|
1010
LL | async fn foo(_: T) -> &'static str;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= note: expected signature `fn(_) -> impl Future<Output = &'static str>`
1313
found signature `fn(_) -> impl Future<Output = &'static str>`
1414

1515
error: async associated function in trait cannot be specialized
16-
--> $DIR/dont-project-to-specializable-projection.rs:13:5
16+
--> $DIR/dont-project-to-specializable-projection.rs:14:5
1717
|
1818
LL | default async fn foo(_: T) -> &'static str {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
2121
= note: specialization behaves in inconsistent and surprising ways with async functions in traits, and for now is disallowed
2222

23-
error: aborting due to 2 previous errors
23+
error[E0599]: no method named `poll` found for struct `Pin<&mut impl Future<Output = ()>>` in the current scope
24+
--> $DIR/dont-project-to-specializable-projection.rs:50:28
25+
|
26+
LL | match fut.as_mut().poll(ctx) {
27+
| ^^^^ method not found in `Pin<&mut impl Future<Output = ()>>`
28+
--> $SRC_DIR/core/src/future/future.rs:LL:COL
29+
|
30+
= note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
31+
|
32+
= help: items from traits can only be used if the trait is in scope
33+
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
34+
|
35+
LL + use std::future::Future;
36+
|
37+
38+
error: aborting due to 3 previous errors
2439

25-
For more information about this error, try `rustc --explain E0053`.
40+
Some errors have detailed explanations: E0053, E0599.
41+
For more information about an error, try `rustc --explain E0053`.

Diff for: tests/ui/coroutine/async_gen_fn_iter.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// run-pass
44

55
#![feature(gen_blocks, async_iterator)]
6+
#![feature(noop_waker)]
67

78
// make sure that a ridiculously simple async gen fn works as an iterator.
89

@@ -42,7 +43,7 @@ async fn async_main() {
4243
// ------------------------------------------------------------------------- //
4344
// Implementation Details Below...
4445

45-
use std::pin::Pin;
46+
use std::pin::{Pin, pin};
4647
use std::task::*;
4748
use std::async_iter::AsyncIterator;
4849
use std::future::Future;
@@ -69,30 +70,15 @@ impl<'s, S: AsyncIterator> Future for Next<'s, S> where S: Unpin {
6970
}
7071
}
7172

72-
pub fn noop_waker() -> Waker {
73-
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
74-
75-
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
76-
unsafe { Waker::from_raw(raw) }
77-
}
78-
79-
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
80-
81-
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
82-
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
83-
}
84-
85-
unsafe fn noop(_p: *const ()) {}
86-
8773
fn main() {
88-
let mut fut = async_main();
74+
let mut fut = pin!(async_main());
8975

9076
// Poll loop, just to test the future...
91-
let waker = noop_waker();
77+
let waker = Waker::noop();
9278
let ctx = &mut Context::from_waker(&waker);
9379

9480
loop {
95-
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
81+
match fut.as_mut().poll(ctx) {
9682
Poll::Pending => {}
9783
Poll::Ready(()) => break,
9884
}

Diff for: tests/ui/dyn-star/dispatch-on-pin-mut.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![feature(dyn_star)]
66
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
7+
#![feature(noop_waker)]
78

89
use std::future::Future;
910

@@ -18,33 +19,18 @@ async fn async_main() {
1819
// ------------------------------------------------------------------------- //
1920
// Implementation Details Below...
2021

21-
use std::pin::Pin;
2222
use std::task::*;
23-
24-
pub fn noop_waker() -> Waker {
25-
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
26-
27-
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
28-
unsafe { Waker::from_raw(raw) }
29-
}
30-
31-
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
32-
33-
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
34-
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
35-
}
36-
37-
unsafe fn noop(_p: *const ()) {}
23+
use std::pin::pin;
3824

3925
fn main() {
40-
let mut fut = async_main();
26+
let mut fut = pin!(async_main());
4127

4228
// Poll loop, just to test the future...
43-
let waker = noop_waker();
29+
let waker = Waker::noop();
4430
let ctx = &mut Context::from_waker(&waker);
4531

4632
loop {
47-
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
33+
match fut.as_mut().poll(ctx) {
4834
Poll::Pending => {}
4935
Poll::Ready(()) => break,
5036
}

0 commit comments

Comments
 (0)