Skip to content

Commit 5ddcf33

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 5ddcf33

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
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)));

0 commit comments

Comments
 (0)