about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-09-19 17:55:19 +0200
committerGitHub <noreply@github.com>2022-09-19 17:55:19 +0200
commitea076a4f9fef9f9d799530aaa6bef70d6fb435eb (patch)
treefa667cc9f526440d29c1753bae8ffbdae2ecac0e /library/core/src
parent27b1b04065edbb2c33f3790defc9f93fb4cefd02 (diff)
parent8e848dc23f7c5e809553dc81072178c34066cc77 (diff)
downloadrust-ea076a4f9fef9f9d799530aaa6bef70d6fb435eb.tar.gz
rust-ea076a4f9fef9f9d799530aaa6bef70d6fb435eb.zip
Rollup merge of #101798 - y86-dev:const_waker, r=lcnr
Make `from_waker`, `waker` and `from_raw` unstably `const`

Make
- `Context::from_waker`
- `Context::waker`
- `Waker::from_raw`

`const`.

Also added a small test.
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/task/wake.rs9
2 files changed, 7 insertions, 3 deletions
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..0cff972df3a 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 = "102012")]
     #[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 = "102012")]
     #[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 = "102012")]
+    pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
         Waker { waker }
     }