about summary refs log tree commit diff
diff options
context:
space:
mode:
authory86-dev <y86-dev@protonmail.com>2022-09-14 14:15:44 +0200
committery86-dev <y86-dev@protonmail.com>2022-09-14 14:53:16 +0200
commit9a78faba7169dc2cdf6dc08c744a92c36e71e8d0 (patch)
tree5f3ab0eede1fbbaf928d46530bea6d577a84e240
parentc97922dca563cb7f9385b18dbf7ca8c97f8e1597 (diff)
downloadrust-9a78faba7169dc2cdf6dc08c744a92c36e71e8d0.tar.gz
rust-9a78faba7169dc2cdf6dc08c744a92c36e71e8d0.zip
Made from_waker, waker, from_raw const
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/task/wake.rs9
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/task.rs17
-rw-r--r--library/std/src/lib.rs1
6 files changed, 26 insertions, 4 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index e5cf9033c86..2225936b0db 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -109,6 +109,7 @@
 #![feature(core_intrinsics)]
 #![feature(const_eval_select)]
 #![feature(const_pin)]
+#![feature(const_waker)]
 #![feature(cstr_from_bytes_until_nul)]
 #![feature(dispatch_from_dyn)]
 #![cfg_attr(not(bootstrap), feature(error_generic_member_access))]
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 5621d15c1cd..c912b933065 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -145,6 +145,7 @@
 #![feature(const_default_impls)]
 #![feature(const_unicode_case_lookup)]
 #![feature(const_unsafecell_get_mut)]
+#![feature(const_waker)]
 #![feature(core_panic)]
 #![feature(duration_consts_float)]
 #![feature(maybe_uninit_uninit_array)]
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index 60ecc9c0bdb..d3f269d6d96 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -186,17 +186,19 @@ pub struct Context<'a> {
 impl<'a> Context<'a> {
     /// Create a new `Context` from a [`&Waker`](Waker).
     #[stable(feature = "futures_api", since = "1.36.0")]
+    #[rustc_const_unstable(feature = "const_waker", issue = "none")]
     #[must_use]
     #[inline]
-    pub fn from_waker(waker: &'a Waker) -> Self {
+    pub const fn from_waker(waker: &'a Waker) -> Self {
         Context { waker, _marker: PhantomData }
     }
 
     /// Returns a reference to the [`Waker`] for the current task.
     #[stable(feature = "futures_api", since = "1.36.0")]
+    #[rustc_const_unstable(feature = "const_waker", issue = "none")]
     #[must_use]
     #[inline]
-    pub fn waker(&self) -> &'a Waker {
+    pub const fn waker(&self) -> &'a Waker {
         &self.waker
     }
 }
@@ -311,7 +313,8 @@ impl Waker {
     #[inline]
     #[must_use]
     #[stable(feature = "futures_api", since = "1.36.0")]
-    pub unsafe fn from_raw(waker: RawWaker) -> Waker {
+    #[rustc_const_unstable(feature = "const_waker", issue = "none")]
+    pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
         Waker { waker }
     }
 
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 4a0e162bc4a..46f603eaeba 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -74,6 +74,7 @@
 #![feature(iterator_try_reduce)]
 #![feature(const_mut_refs)]
 #![feature(const_pin)]
+#![feature(const_waker)]
 #![feature(never_type)]
 #![feature(unwrap_infallible)]
 #![feature(pointer_byte_offsets)]
diff --git a/library/core/tests/task.rs b/library/core/tests/task.rs
index d71fef9e5c8..56be30e9282 100644
--- a/library/core/tests/task.rs
+++ b/library/core/tests/task.rs
@@ -1,4 +1,4 @@
-use core::task::Poll;
+use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
 
 #[test]
 fn poll_const() {
@@ -12,3 +12,18 @@ fn poll_const() {
     const IS_PENDING: bool = POLL.is_pending();
     assert!(IS_PENDING);
 }
+
+#[test]
+fn waker_const() {
+    const VOID_TABLE: RawWakerVTable = RawWakerVTable::new(|_| VOID_WAKER, |_| {}, |_| {}, |_| {});
+
+    const VOID_WAKER: RawWaker = RawWaker::new(&(), &VOID_TABLE);
+
+    static WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
+
+    static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
+
+    static WAKER_REF: &'static Waker = CONTEXT.waker();
+
+    WAKER_REF.wake_by_ref();
+}
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index f13500de014..2c5ff255589 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -315,6 +315,7 @@
 #![feature(strict_provenance)]
 #![feature(maybe_uninit_uninit_array)]
 #![feature(const_maybe_uninit_uninit_array)]
+#![feature(const_waker)]
 //
 // Library features (alloc):
 #![feature(alloc_layout_extra)]