Skip to content

Commit 25c9f50

Browse files
committed
Replace unstable Waker::noop() with Waker::NOOP.
As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Associated.20constants.20vs.2E.20functions.20in.20std.20API>, across `std`, outside of argumentless `new()` constructor functions, stable constant values are generally provided using `const` items rather than `const fn`s. Therefore, this change is more consistent API design. WG-async approves of making this change, per <rust-lang#98286 (comment)>.
1 parent 85e449a commit 25c9f50

27 files changed

+32
-37
lines changed

library/alloc/src/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
247247
/// // cast the Rc<Task> into a `LocalWaker`
248248
/// let local_waker: LocalWaker = task.clone().into();
249249
/// // Build the context using `ContextBuilder`
250-
/// let mut cx = ContextBuilder::from_waker(Waker::noop())
250+
/// let mut cx = ContextBuilder::from_waker(Waker::NOOP)
251251
/// .local_waker(&local_waker)
252252
/// .build();
253253
///

library/core/src/task/wake.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl fmt::Debug for Context<'_> {
284284
/// use std::future::Future;
285285
///
286286
/// let local_waker = LocalWaker::noop();
287-
/// let waker = Waker::noop();
287+
/// let waker = Waker::NOOP;
288288
///
289289
/// let mut cx = ContextBuilder::from_waker(&waker)
290290
/// .local_waker(&local_waker)
@@ -465,7 +465,7 @@ impl Waker {
465465
Waker { waker }
466466
}
467467

468-
/// Returns a reference to a `Waker` that does nothing when used.
468+
/// A reference to a `Waker` that does nothing when used.
469469
///
470470
/// This is mostly useful for writing tests that need a [`Context`] to poll
471471
/// some futures, but are not expecting those futures to wake the waker or
@@ -481,18 +481,13 @@ impl Waker {
481481
/// use std::future::Future;
482482
/// use std::task;
483483
///
484-
/// let mut cx = task::Context::from_waker(task::Waker::noop());
484+
/// let mut cx = task::Context::from_waker(task::Waker::NOOP);
485485
///
486486
/// let mut future = Box::pin(async { 10 });
487487
/// assert_eq!(future.as_mut().poll(&mut cx), task::Poll::Ready(10));
488488
/// ```
489-
#[inline]
490-
#[must_use]
491489
#[unstable(feature = "noop_waker", issue = "98286")]
492-
pub const fn noop() -> &'static Waker {
493-
const WAKER: &Waker = &Waker { waker: RawWaker::NOOP };
494-
WAKER
495-
}
490+
pub const NOOP: &'static Waker = &Waker { waker: RawWaker::NOOP };
496491

497492
/// Get a reference to the underlying [`RawWaker`].
498493
#[inline]
@@ -697,7 +692,7 @@ impl LocalWaker {
697692
/// use std::future::Future;
698693
/// use std::task::{ContextBuilder, LocalWaker, Waker, Poll};
699694
///
700-
/// let mut cx = ContextBuilder::from_waker(Waker::noop())
695+
/// let mut cx = ContextBuilder::from_waker(Waker::NOOP)
701696
/// .local_waker(LocalWaker::noop())
702697
/// .build();
703698
///

library/core/tests/async_iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn into_async_iter() {
77
let async_iter = async_iter::from_iter(0..3);
88
let mut async_iter = pin!(async_iter.into_async_iter());
99

10-
let mut cx = &mut core::task::Context::from_waker(core::task::Waker::noop());
10+
let mut cx = &mut core::task::Context::from_waker(core::task::Waker::NOOP);
1111

1212
assert_eq!(async_iter.as_mut().poll_next(&mut cx), Poll::Ready(Some(0)));
1313
assert_eq!(async_iter.as_mut().poll_next(&mut cx), Poll::Ready(Some(1)));

src/tools/miri/tests/pass/async-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::task::*;
66

77
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
88
let mut fut = pin!(fut);
9-
let ctx = &mut Context::from_waker(Waker::noop());
9+
let ctx = &mut Context::from_waker(Waker::NOOP);
1010

1111
loop {
1212
match fut.as_mut().poll(ctx) {

src/tools/miri/tests/pass/async-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async fn uninhabited_variant() {
7676
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
7777
use std::task::{Context, Poll, Waker};
7878

79-
let mut context = Context::from_waker(Waker::noop());
79+
let mut context = Context::from_waker(Waker::NOOP);
8080

8181
let mut pinned = Box::pin(fut);
8282
loop {

src/tools/miri/tests/pass/dyn-star.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn dispatch_on_pin_mut() {
9393
let mut fut = async_main();
9494

9595
// Poll loop, just to test the future...
96-
let ctx = &mut Context::from_waker(Waker::noop());
96+
let ctx = &mut Context::from_waker(Waker::NOOP);
9797

9898
loop {
9999
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {

src/tools/miri/tests/pass/future-self-referential.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Future for DoStuff {
7777
}
7878

7979
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
80-
let mut context = Context::from_waker(Waker::noop());
80+
let mut context = Context::from_waker(Waker::NOOP);
8181

8282
let mut pinned = pin!(fut);
8383
loop {
@@ -89,7 +89,7 @@ fn run_fut<T>(fut: impl Future<Output = T>) -> T {
8989
}
9090

9191
fn self_referential_box() {
92-
let cx = &mut Context::from_waker(Waker::noop());
92+
let cx = &mut Context::from_waker(Waker::NOOP);
9393

9494
async fn my_fut() -> i32 {
9595
let val = 10;

src/tools/miri/tests/pass/issues/issue-miri-2068.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::task::{Context, Poll, Waker};
66

77
pub fn fuzzing_block_on<O, F: Future<Output = O>>(fut: F) -> O {
88
let mut fut = std::pin::pin!(fut);
9-
let mut context = Context::from_waker(Waker::noop());
9+
let mut context = Context::from_waker(Waker::NOOP);
1010
loop {
1111
match fut.as_mut().poll(&mut context) {
1212
Poll::Ready(v) => return v,

src/tools/miri/tests/pass/move-data-across-await-point.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn data_moved() {
5656
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
5757
use std::task::{Context, Poll, Waker};
5858

59-
let mut context = Context::from_waker(Waker::noop());
59+
let mut context = Context::from_waker(Waker::NOOP);
6060

6161
let mut pinned = Box::pin(fut);
6262
loop {

tests/coverage/async.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
LL| | #[coverage(off)]
120120
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
121121
LL| | let mut future = pin!(future);
122-
LL| | let mut context = Context::from_waker(Waker::noop());
122+
LL| | let mut context = Context::from_waker(Waker::NOOP);
123123
LL| |
124124
LL| | loop {
125125
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod executor {
112112
#[coverage(off)]
113113
pub fn block_on<F: Future>(mut future: F) -> F::Output {
114114
let mut future = pin!(future);
115-
let mut context = Context::from_waker(Waker::noop());
115+
let mut context = Context::from_waker(Waker::NOOP);
116116

117117
loop {
118118
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/async2.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
LL| | #[coverage(off)]
4242
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
4343
LL| | let mut future = pin!(future);
44-
LL| | let mut context = Context::from_waker(Waker::noop());
44+
LL| | let mut context = Context::from_waker(Waker::NOOP);
4545
LL| |
4646
LL| | loop {
4747
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/async2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod executor {
3939
#[coverage(off)]
4040
pub fn block_on<F: Future>(mut future: F) -> F::Output {
4141
let mut future = pin!(future);
42-
let mut context = Context::from_waker(Waker::noop());
42+
let mut context = Context::from_waker(Waker::NOOP);
4343

4444
loop {
4545
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/async_block.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LL| | #[coverage(off)]
2525
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
2626
LL| | let mut future = pin!(future);
27-
LL| | let mut context = Context::from_waker(Waker::noop());
27+
LL| | let mut context = Context::from_waker(Waker::NOOP);
2828
LL| |
2929
LL| | loop {
3030
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/async_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod executor {
2323
#[coverage(off)]
2424
pub fn block_on<F: Future>(mut future: F) -> F::Output {
2525
let mut future = pin!(future);
26-
let mut context = Context::from_waker(Waker::noop());
26+
let mut context = Context::from_waker(Waker::NOOP);
2727

2828
loop {
2929
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/closure_macro_async.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
LL| | #[coverage(off)]
5656
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
5757
LL| | let mut future = pin!(future);
58-
LL| | let mut context = Context::from_waker(Waker::noop());
58+
LL| | let mut context = Context::from_waker(Waker::NOOP);
5959
LL| |
6060
LL| | loop {
6161
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/coverage/closure_macro_async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod executor {
5454
#[coverage(off)]
5555
pub fn block_on<F: Future>(mut future: F) -> F::Output {
5656
let mut future = pin!(future);
57-
let mut context = Context::from_waker(Waker::noop());
57+
let mut context = Context::from_waker(Waker::NOOP);
5858

5959
loop {
6060
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {

tests/mir-opt/async_closure_shims.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::task::*;
1111

1212
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1313
let mut fut = pin!(fut);
14-
let ctx = &mut Context::from_waker(Waker::noop());
14+
let ctx = &mut Context::from_waker(Waker::NOOP);
1515

1616
loop {
1717
match fut.as_mut().poll(ctx) {

tests/ui/async-await/async-closures/auxiliary/block-on.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::task::*;
99
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1010
let mut fut = pin!(fut);
1111
// Poll loop, just to test the future...
12-
let ctx = &mut Context::from_waker(Waker::noop());
12+
let ctx = &mut Context::from_waker(Waker::NOOP);
1313

1414
loop {
1515
match unsafe { fut.as_mut().poll(ctx) } {

tests/ui/async-await/async-fn/auxiliary/block-on.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::task::*;
99
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1010
let mut fut = pin!(fut);
1111
// Poll loop, just to test the future...
12-
let ctx = &mut Context::from_waker(Waker::noop());
12+
let ctx = &mut Context::from_waker(Waker::NOOP);
1313

1414
loop {
1515
match unsafe { fut.as_mut().poll(ctx) } {

tests/ui/async-await/for-await-passthrough.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async fn real_main() {
2323

2424
fn main() {
2525
let future = real_main();
26-
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::noop());
26+
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::NOOP);
2727
let mut future = core::pin::pin!(future);
2828
while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {}
2929
}

tests/ui/async-await/for-await.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn real_main() {
1717

1818
fn main() {
1919
let future = real_main();
20-
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::noop());
20+
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::NOOP);
2121
let mut future = core::pin::pin!(future);
2222
while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {}
2323
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
let mut fut = pin!(async_main());
4141

4242
// Poll loop, just to test the future...
43-
let ctx = &mut Context::from_waker(Waker::noop());
43+
let ctx = &mut Context::from_waker(Waker::NOOP);
4444

4545
loop {
4646
match fut.as_mut().poll(ctx) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn main() {
4343
let mut fut = pin!(async_main());
4444

4545
// Poll loop, just to test the future...
46-
let ctx = &mut Context::from_waker(Waker::noop());
46+
let ctx = &mut Context::from_waker(Waker::NOOP);
4747

4848
loop {
4949
match fut.as_mut().poll(ctx) {

tests/ui/coroutine/async-gen-yield-ty-is-unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ async gen fn gen_fn() -> &'static str {
1111

1212
pub fn main() {
1313
let async_iterator = pin!(gen_fn());
14-
let ctx = &mut Context::from_waker(Waker::noop());
14+
let ctx = &mut Context::from_waker(Waker::NOOP);
1515
async_iterator.poll_next(ctx);
1616
}

tests/ui/coroutine/async_gen_fn_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn main() {
7373
let mut fut = pin!(async_main());
7474

7575
// Poll loop, just to test the future...
76-
let ctx = &mut Context::from_waker(Waker::noop());
76+
let ctx = &mut Context::from_waker(Waker::NOOP);
7777

7878
loop {
7979
match fut.as_mut().poll(ctx) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
let mut fut = pin!(async_main());
2727

2828
// Poll loop, just to test the future...
29-
let ctx = &mut Context::from_waker(Waker::noop());
29+
let ctx = &mut Context::from_waker(Waker::NOOP);
3030

3131
loop {
3232
match fut.as_mut().poll(ctx) {

0 commit comments

Comments
 (0)