Skip to content

Commit

Permalink
Rollup merge of rust-lang#76227 - CDirkx:const-poll, r=KodrAus
Browse files Browse the repository at this point in the history
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](rust-lang#76198).

Possible because of the recent stabilization of const control flow.

Part of rust-lang#76225.
  • Loading branch information
m-ou-se authored Nov 7, 2020
2 parents 8a27822 + 5e80c65 commit e8c698b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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.49.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.49.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 @@ -91,5 +91,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);
}

0 comments on commit e8c698b

Please sign in to comment.