Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions library/core/src/task/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ impl<T> Poll<T> {

/// Returns `true` if this is `Poll::Ready`
#[inline]
#[rustc_const_stable(feature = "const_poll", since = "1.48.0")]
#[stable(feature = "futures_api", since = "1.36.0")]
pub fn is_ready(&self) -> bool {
pub const fn is_ready(&self) -> bool {
matches!(*self, Poll::Ready(_))
}

/// Returns `true` if this is `Poll::Pending`
#[inline]
#[rustc_const_stable(feature = "const_poll", since = "1.48.0")]
#[stable(feature = "futures_api", since = "1.36.0")]
pub fn is_pending(&self) -> bool {
pub const fn is_pending(&self) -> bool {
!self.is_ready()
}
}
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ mod result;
mod slice;
mod str;
mod str_lossy;
mod task;
mod time;
mod tuple;
14 changes: 14 additions & 0 deletions library/core/tests/task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use core::task::Poll;

#[test]
fn poll_const() {
// test that the methods of `Poll` are usable in a const context

const POLL: Poll<usize> = Poll::Pending;

const IS_READY: bool = POLL.is_ready();
assert!(!IS_READY);

const IS_PENDING: bool = POLL.is_pending();
assert!(IS_PENDING);
}