From 9412a898fa4ed5065a363bd40ad9401469ed3d54 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Wed, 2 Sep 2020 02:35:14 +0200 Subject: [PATCH 1/3] 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. --- library/core/src/task/poll.rs | 6 ++++-- src/test/ui/consts/std/poll.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/std/poll.rs diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 9383e7c45fa55..a789e4e2593ee 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -39,15 +39,17 @@ impl Poll { /// 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 index 0000000000000..28f2ace6715fe --- /dev/null +++ b/src/test/ui/consts/std/poll.rs @@ -0,0 +1,13 @@ +// run-pass + +use std::task::Poll; + +fn main() { + const POLL : Poll = Poll::Pending; + + const IS_READY : bool = POLL.is_ready(); + assert!(!IS_READY); + + const IS_PENDING : bool = POLL.is_pending(); + assert!(IS_PENDING); +} From ce1d5ed31aff33bbbb116fffabd6107491c464bc Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Fri, 4 Sep 2020 01:04:34 +0200 Subject: [PATCH 2/3] Move const tests for `Poll` to `library\core` Part of #76268 --- library/core/tests/lib.rs | 1 + library/core/tests/task.rs | 14 ++++++++++++++ src/test/ui/consts/std/poll.rs | 13 ------------- 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 library/core/tests/task.rs delete mode 100644 src/test/ui/consts/std/poll.rs diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 81e621318e141..2c20259fc5855 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -76,5 +76,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 0000000000000..d71fef9e5c87d --- /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 = Poll::Pending; + + const IS_READY: bool = POLL.is_ready(); + assert!(!IS_READY); + + const IS_PENDING: bool = POLL.is_pending(); + assert!(IS_PENDING); +} diff --git a/src/test/ui/consts/std/poll.rs b/src/test/ui/consts/std/poll.rs deleted file mode 100644 index 28f2ace6715fe..0000000000000 --- a/src/test/ui/consts/std/poll.rs +++ /dev/null @@ -1,13 +0,0 @@ -// run-pass - -use std::task::Poll; - -fn main() { - const POLL : Poll = Poll::Pending; - - const IS_READY : bool = POLL.is_ready(); - assert!(!IS_READY); - - const IS_PENDING : bool = POLL.is_pending(); - assert!(IS_PENDING); -} From 5e80c65102f85700e1a449847dfa603e589df950 Mon Sep 17 00:00:00 2001 From: CDirkx Date: Fri, 16 Oct 2020 21:29:21 +0200 Subject: [PATCH 3/3] Bump version to 1.49.0 Due to the recent release of 1.47.0, this PR will be stabilized in 1.49.0 instead of 1.48.0. --- library/core/src/task/poll.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index a789e4e2593ee..dc405465f5d36 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -39,7 +39,7 @@ impl Poll { /// Returns `true` if this is `Poll::Ready` #[inline] - #[rustc_const_stable(feature = "const_poll", since = "1.48.0")] + #[rustc_const_stable(feature = "const_poll", since = "1.49.0")] #[stable(feature = "futures_api", since = "1.36.0")] pub const fn is_ready(&self) -> bool { matches!(*self, Poll::Ready(_)) @@ -47,7 +47,7 @@ impl Poll { /// Returns `true` if this is `Poll::Pending` #[inline] - #[rustc_const_stable(feature = "const_poll", since = "1.48.0")] + #[rustc_const_stable(feature = "const_poll", since = "1.49.0")] #[stable(feature = "futures_api", since = "1.36.0")] pub const fn is_pending(&self) -> bool { !self.is_ready()