summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-07-28 20:07:46 +0200
committerGitHub <noreply@github.com>2024-07-28 20:07:46 +0200
commitee5956fd8a49fc1abcae4f206b5f86f90ac9612b (patch)
treec7add01bf0d2e1b5d1242f0a8adbe503e736f9b1
parent0e45047e81603f0b9d666dcc74d4f8915fea31cc (diff)
parent0a6ebbaf2e58097439f66fb870b4973a62dfe999 (diff)
downloadrust-ee5956fd8a49fc1abcae4f206b5f86f90ac9612b.tar.gz
rust-ee5956fd8a49fc1abcae4f206b5f86f90ac9612b.zip
Rollup merge of #128228 - slanterns:const_waker, r=dtolnay,oli-obk
Stabilize `const_waker`

Closes: https://github.com/rust-lang/rust/issues/102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under https://github.com/rust-lang/rust/issues/102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.``

``@rustbot`` label: +T-libs-api

r? libs-api
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/task/wake.rs24
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/waker.rs32
-rw-r--r--library/std/src/lib.rs1
-rw-r--r--tests/ui/async-await/for-await-consumes-iter.rs2
-rw-r--r--tests/ui/async-await/for-await-passthrough.rs2
-rw-r--r--tests/ui/async-await/for-await.rs2
9 files changed, 47 insertions, 19 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 49036077e2e..3b039786eb5 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -116,7 +116,6 @@
 #![feature(const_pin)]
 #![feature(const_refs_to_cell)]
 #![feature(const_size_of_val)]
-#![feature(const_waker)]
 #![feature(core_intrinsics)]
 #![feature(deprecated_suggestion)]
 #![feature(deref_pure_trait)]
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 9f0055d1911..e8f08db9416 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -162,7 +162,6 @@
 #![feature(const_ub_checks)]
 #![feature(const_unicode_case_lookup)]
 #![feature(const_unsafecell_get_mut)]
-#![feature(const_waker)]
 #![feature(coverage_attribute)]
 #![feature(do_not_recommend)]
 #![feature(duration_consts_float)]
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index adfd4d182e9..3342fedd926 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -251,7 +251,7 @@ pub struct Context<'a> {
 impl<'a> Context<'a> {
     /// Creates a new `Context` from a [`&Waker`](Waker).
     #[stable(feature = "futures_api", since = "1.36.0")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
     #[must_use]
     #[inline]
     pub const fn from_waker(waker: &'a Waker) -> Self {
@@ -262,7 +262,7 @@ impl<'a> Context<'a> {
     #[inline]
     #[must_use]
     #[stable(feature = "futures_api", since = "1.36.0")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
     pub const fn waker(&self) -> &'a Waker {
         &self.waker
     }
@@ -270,7 +270,7 @@ impl<'a> Context<'a> {
     /// Returns a reference to the [`LocalWaker`] for the current task.
     #[inline]
     #[unstable(feature = "local_waker", issue = "118959")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "local_waker", issue = "118959")]
     pub const fn local_waker(&self) -> &'a LocalWaker {
         &self.local_waker
     }
@@ -278,7 +278,7 @@ impl<'a> Context<'a> {
     /// Returns a reference to the extension data for the current task.
     #[inline]
     #[unstable(feature = "context_ext", issue = "123392")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "context_ext", issue = "123392")]
     pub const fn ext(&mut self) -> &mut dyn Any {
         // FIXME: this field makes Context extra-weird about unwind safety
         // can we justify AssertUnwindSafe if we stabilize this? do we care?
@@ -337,8 +337,8 @@ pub struct ContextBuilder<'a> {
 impl<'a> ContextBuilder<'a> {
     /// Creates a ContextBuilder from a Waker.
     #[inline]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
     #[unstable(feature = "local_waker", issue = "118959")]
+    #[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
     pub const fn from_waker(waker: &'a Waker) -> Self {
         // SAFETY: LocalWaker is just Waker without thread safety
         let local_waker = unsafe { transmute(waker) };
@@ -353,8 +353,8 @@ impl<'a> ContextBuilder<'a> {
 
     /// Creates a ContextBuilder from an existing Context.
     #[inline]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
     #[unstable(feature = "context_ext", issue = "123392")]
+    #[rustc_const_unstable(feature = "context_ext", issue = "123392")]
     pub const fn from(cx: &'a mut Context<'_>) -> Self {
         let ext = match &mut cx.ext.0 {
             ExtData::Some(ext) => ExtData::Some(*ext),
@@ -372,7 +372,7 @@ impl<'a> ContextBuilder<'a> {
     /// Sets the value for the waker on `Context`.
     #[inline]
     #[unstable(feature = "context_ext", issue = "123392")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "context_ext", issue = "123392")]
     pub const fn waker(self, waker: &'a Waker) -> Self {
         Self { waker, ..self }
     }
@@ -380,7 +380,7 @@ impl<'a> ContextBuilder<'a> {
     /// Sets the value for the local waker on `Context`.
     #[inline]
     #[unstable(feature = "local_waker", issue = "118959")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "local_waker", issue = "118959")]
     pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self {
         Self { local_waker, ..self }
     }
@@ -388,7 +388,7 @@ impl<'a> ContextBuilder<'a> {
     /// Sets the value for the extension data on `Context`.
     #[inline]
     #[unstable(feature = "context_ext", issue = "123392")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "context_ext", issue = "123392")]
     pub const fn ext(self, data: &'a mut dyn Any) -> Self {
         Self { ext: ExtData::Some(data), ..self }
     }
@@ -396,7 +396,7 @@ impl<'a> ContextBuilder<'a> {
     /// Builds the `Context`.
     #[inline]
     #[unstable(feature = "local_waker", issue = "118959")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
     pub const fn build(self) -> Context<'a> {
         let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
         Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
@@ -522,7 +522,7 @@ impl Waker {
     #[inline]
     #[must_use]
     #[stable(feature = "futures_api", since = "1.36.0")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
     pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
         Waker { waker }
     }
@@ -773,7 +773,7 @@ impl LocalWaker {
     #[inline]
     #[must_use]
     #[unstable(feature = "local_waker", issue = "118959")]
-    #[rustc_const_unstable(feature = "const_waker", issue = "102012")]
+    #[rustc_const_unstable(feature = "local_waker", issue = "118959")]
     pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker {
         Self { waker }
     }
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 2e4daad1e93..5dad5937a60 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -87,7 +87,6 @@
 #![feature(const_ipv6)]
 #![feature(const_mut_refs)]
 #![feature(const_pin)]
-#![feature(const_waker)]
 #![feature(never_type)]
 #![feature(unwrap_infallible)]
 #![feature(pointer_is_aligned_to)]
diff --git a/library/core/tests/waker.rs b/library/core/tests/waker.rs
index 2c66e0d7ad3..f8c91a72593 100644
--- a/library/core/tests/waker.rs
+++ b/library/core/tests/waker.rs
@@ -20,3 +20,35 @@ static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
     |_| {},
     |_| {},
 );
+
+// https://github.com/rust-lang/rust/issues/102012#issuecomment-1915282956
+mod nop_waker {
+    use core::{
+        future::{ready, Future},
+        pin::Pin,
+        task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
+    };
+
+    const NOP_RAWWAKER: RawWaker = {
+        fn nop(_: *const ()) {}
+        const VTAB: RawWakerVTable = RawWakerVTable::new(|_| NOP_RAWWAKER, nop, nop, nop);
+        RawWaker::new(&() as *const (), &VTAB)
+    };
+
+    const NOP_WAKER: &Waker = &unsafe { Waker::from_raw(NOP_RAWWAKER) };
+
+    const NOP_CONTEXT: Context<'static> = Context::from_waker(NOP_WAKER);
+
+    fn poll_once<T, F>(f: &mut F) -> Poll<T>
+    where
+        F: Future<Output = T> + ?Sized + Unpin,
+    {
+        let mut cx = NOP_CONTEXT;
+        Pin::new(f).as_mut().poll(&mut cx)
+    }
+
+    #[test]
+    fn test_const_waker() {
+        assert_eq!(poll_once(&mut ready(1)), Poll::Ready(1));
+    }
+}
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 9fba657d116..353fd8d2de8 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -407,7 +407,6 @@
 #![feature(const_ip)]
 #![feature(const_ipv4)]
 #![feature(const_ipv6)]
-#![feature(const_waker)]
 #![feature(thread_local_internals)]
 // tidy-alphabetical-end
 //
diff --git a/tests/ui/async-await/for-await-consumes-iter.rs b/tests/ui/async-await/for-await-consumes-iter.rs
index 38dfe46c814..7ea88c14cb5 100644
--- a/tests/ui/async-await/for-await-consumes-iter.rs
+++ b/tests/ui/async-await/for-await-consumes-iter.rs
@@ -1,5 +1,5 @@
 //@ edition: 2021
-#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)]
+#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker)]
 
 use std::future::Future;
 
diff --git a/tests/ui/async-await/for-await-passthrough.rs b/tests/ui/async-await/for-await-passthrough.rs
index e09e843332e..b4fba6b2f76 100644
--- a/tests/ui/async-await/for-await-passthrough.rs
+++ b/tests/ui/async-await/for-await-passthrough.rs
@@ -1,7 +1,7 @@
 //@ run-pass
 //@ edition: 2024
 //@ compile-flags: -Zunstable-options
-#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker,
+#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker,
            gen_blocks)]
 
 async gen fn async_iter() -> i32 {
diff --git a/tests/ui/async-await/for-await.rs b/tests/ui/async-await/for-await.rs
index acd9f01640a..b4af38a82b3 100644
--- a/tests/ui/async-await/for-await.rs
+++ b/tests/ui/async-await/for-await.rs
@@ -1,6 +1,6 @@
 //@ run-pass
 //@ edition: 2021
-#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)]
+#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker)]
 
 use std::future::Future;