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:
parent
130359cb05
commit
9412a898fa
@ -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()
|
||||
}
|
||||
}
|
||||
|
13
src/test/ui/consts/std/poll.rs
Normal file
13
src/test/ui/consts/std/poll.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user