Skip to content

Commit 9412a89

Browse files
committed
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.
1 parent 130359c commit 9412a89

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

library/core/src/task/poll.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ impl<T> Poll<T> {
3939

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

4748
/// Returns `true` if this is `Poll::Pending`
4849
#[inline]
50+
#[rustc_const_stable(feature = "const_poll", since = "1.48.0")]
4951
#[stable(feature = "futures_api", since = "1.36.0")]
50-
pub fn is_pending(&self) -> bool {
52+
pub const fn is_pending(&self) -> bool {
5153
!self.is_ready()
5254
}
5355
}

src/test/ui/consts/std/poll.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
3+
use std::task::Poll;
4+
5+
fn main() {
6+
const POLL : Poll<usize> = Poll::Pending;
7+
8+
const IS_READY : bool = POLL.is_ready();
9+
assert!(!IS_READY);
10+
11+
const IS_PENDING : bool = POLL.is_pending();
12+
assert!(IS_PENDING);
13+
}

0 commit comments

Comments
 (0)