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 <#98286 (comment)>.
1 parent 85e449a commit 25c9f50

27 files changed

+32
-37
lines changed

library/alloc/src/task.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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) {

0 commit comments

Comments
 (0)