diff options
| author | Christiaan Dirkx <christiaan@dirkx.email> | 2020-09-02 02:35:14 +0200 | 
|---|---|---|
| committer | Christiaan Dirkx <christiaan@dirkx.email> | 2020-09-02 02:35:14 +0200 | 
| commit | 9412a898fa4ed5065a363bd40ad9401469ed3d54 (patch) | |
| tree | bda053f636a5fd8bd4c46549869c34e770c60b28 | |
| parent | 130359cb05246fcacdde61baa2613419ef6570c7 (diff) | |
| download | rust-9412a898fa4ed5065a363bd40ad9401469ed3d54.tar.gz rust-9412a898fa4ed5065a363bd40ad9401469ed3d54.zip  | |
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.
| -rw-r--r-- | library/core/src/task/poll.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/consts/std/poll.rs | 13 | 
2 files changed, 17 insertions, 2 deletions
diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 9383e7c45fa..a789e4e2593 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.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 00000000000..28f2ace6715 --- /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<usize> = Poll::Pending; + + const IS_READY : bool = POLL.is_ready(); + assert!(!IS_READY); + + const IS_PENDING : bool = POLL.is_pending(); + assert!(IS_PENDING); +}  | 
