Stabilize Poll::is_ready and is_pending as const

Insta-stabilize the methods `is_ready` and `is_pending` of `Poll`.

Possible because of the recent stabilization of const control flow.

Also adds a test for these methods in a const context.
This commit is contained in:
Christiaan Dirkx 2020-09-02 02:35:14 +02:00
parent 130359cb05
commit 9412a898fa
2 changed files with 17 additions and 2 deletions

View File

@ -39,15 +39,17 @@ pub fn map<U, F>(self, f: F) -> Poll<U>
/// 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()
}
}

View File

@ -0,0 +1,13 @@
// run-pass
use std::task::Poll;
fn main() {
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);
}