Skip to content

Commit bdeace9

Browse files
authored
Rollup merge of #76227 - CDirkx:const-poll, r=KodrAus
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](#76198). Possible because of the recent stabilization of const control flow. Part of #76225.
2 parents 1f034f7 + 5e80c65 commit bdeace9

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-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.49.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.49.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
}

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@ mod result;
9191
mod slice;
9292
mod str;
9393
mod str_lossy;
94+
mod task;
9495
mod time;
9596
mod tuple;

library/core/tests/task.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use core::task::Poll;
2+
3+
#[test]
4+
fn poll_const() {
5+
// test that the methods of `Poll` are usable in a const context
6+
7+
const POLL: Poll<usize> = Poll::Pending;
8+
9+
const IS_READY: bool = POLL.is_ready();
10+
assert!(!IS_READY);
11+
12+
const IS_PENDING: bool = POLL.is_pending();
13+
assert!(IS_PENDING);
14+
}

0 commit comments

Comments
 (0)