]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize `Poll::is_ready` and `is_pending` as const
authorChristiaan Dirkx <christiaan@dirkx.email>
Wed, 2 Sep 2020 00:35:14 +0000 (02:35 +0200)
committerChristiaan Dirkx <christiaan@dirkx.email>
Wed, 2 Sep 2020 00:35:14 +0000 (02:35 +0200)
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.

library/core/src/task/poll.rs
src/test/ui/consts/std/poll.rs [new file with mode: 0644]

index 9383e7c45fa55b6c29b1ebd56346842b4b844b09..a789e4e2593ee24469dd3d90a483bf288ea97665 100644 (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()
     }
 }
diff --git a/src/test/ui/consts/std/poll.rs b/src/test/ui/consts/std/poll.rs
new file mode 100644 (file)
index 0000000..28f2ace
--- /dev/null
@@ -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);
+}