about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-08 13:35:58 +0100
committerGitHub <noreply@github.com>2020-11-08 13:35:58 +0100
commitbdeace9f4edd2f8c1f06d147940a07550f133f42 (patch)
treec44f8dff555b2fbff3d34131312685bcb74a1b6f
parent1f034f77bc7cd5814cb341a1028f8955dc4262a5 (diff)
parent5e80c65102f85700e1a449847dfa603e589df950 (diff)
downloadrust-bdeace9f4edd2f8c1f06d147940a07550f133f42.tar.gz
rust-bdeace9f4edd2f8c1f06d147940a07550f133f42.zip
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](https://github.com/rust-lang/rust/pull/76198).

Possible because of the recent stabilization of const control flow.

Part of #76225.
-rw-r--r--library/core/src/task/poll.rs6
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/task.rs14
3 files changed, 19 insertions, 2 deletions
diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs
index 4e987a53b2c..6851f3fcd2f 100644
--- a/library/core/src/task/poll.rs
+++ b/library/core/src/task/poll.rs
@@ -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()
     }
 }
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 0c4ce867f54..4d1080ccef0 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -91,5 +91,6 @@ mod result;
 mod slice;
 mod str;
 mod str_lossy;
+mod task;
 mod time;
 mod tuple;
diff --git a/library/core/tests/task.rs b/library/core/tests/task.rs
new file mode 100644
index 00000000000..d71fef9e5c8
--- /dev/null
+++ b/library/core/tests/task.rs
@@ -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);
+}