Skip to content

Commit 0a6ebba

Browse files
committed
stabilize const_waker
1 parent 6ef11b8 commit 0a6ebba

File tree

9 files changed

+47
-19
lines changed

9 files changed

+47
-19
lines changed

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
#![feature(const_pin)]
118118
#![feature(const_refs_to_cell)]
119119
#![feature(const_size_of_val)]
120-
#![feature(const_waker)]
121120
#![feature(core_intrinsics)]
122121
#![feature(deprecated_suggestion)]
123122
#![feature(deref_pure_trait)]

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
#![feature(const_ub_checks)]
164164
#![feature(const_unicode_case_lookup)]
165165
#![feature(const_unsafecell_get_mut)]
166-
#![feature(const_waker)]
167166
#![feature(coverage_attribute)]
168167
#![feature(do_not_recommend)]
169168
#![feature(duration_consts_float)]

library/core/src/task/wake.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub struct Context<'a> {
250250
impl<'a> Context<'a> {
251251
/// Create a new `Context` from a [`&Waker`](Waker).
252252
#[stable(feature = "futures_api", since = "1.36.0")]
253-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
253+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
254254
#[must_use]
255255
#[inline]
256256
pub const fn from_waker(waker: &'a Waker) -> Self {
@@ -261,23 +261,23 @@ impl<'a> Context<'a> {
261261
#[inline]
262262
#[must_use]
263263
#[stable(feature = "futures_api", since = "1.36.0")]
264-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
264+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
265265
pub const fn waker(&self) -> &'a Waker {
266266
&self.waker
267267
}
268268

269269
/// Returns a reference to the [`LocalWaker`] for the current task.
270270
#[inline]
271271
#[unstable(feature = "local_waker", issue = "118959")]
272-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
272+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
273273
pub const fn local_waker(&self) -> &'a LocalWaker {
274274
&self.local_waker
275275
}
276276

277277
/// Returns a reference to the extension data for the current task.
278278
#[inline]
279279
#[unstable(feature = "context_ext", issue = "123392")]
280-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
280+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
281281
pub const fn ext(&mut self) -> &mut dyn Any {
282282
// FIXME: this field makes Context extra-weird about unwind safety
283283
// can we justify AssertUnwindSafe if we stabilize this? do we care?
@@ -336,8 +336,8 @@ pub struct ContextBuilder<'a> {
336336
impl<'a> ContextBuilder<'a> {
337337
/// Create a ContextBuilder from a Waker.
338338
#[inline]
339-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
340339
#[unstable(feature = "local_waker", issue = "118959")]
340+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
341341
pub const fn from_waker(waker: &'a Waker) -> Self {
342342
// SAFETY: LocalWaker is just Waker without thread safety
343343
let local_waker = unsafe { transmute(waker) };
@@ -352,8 +352,8 @@ impl<'a> ContextBuilder<'a> {
352352

353353
/// Create a ContextBuilder from an existing Context.
354354
#[inline]
355-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
356355
#[unstable(feature = "context_ext", issue = "123392")]
356+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
357357
pub const fn from(cx: &'a mut Context<'_>) -> Self {
358358
let ext = match &mut cx.ext.0 {
359359
ExtData::Some(ext) => ExtData::Some(*ext),
@@ -371,31 +371,31 @@ impl<'a> ContextBuilder<'a> {
371371
/// This method is used to set the value for the waker on `Context`.
372372
#[inline]
373373
#[unstable(feature = "context_ext", issue = "123392")]
374-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
374+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
375375
pub const fn waker(self, waker: &'a Waker) -> Self {
376376
Self { waker, ..self }
377377
}
378378

379379
/// This method is used to set the value for the local waker on `Context`.
380380
#[inline]
381381
#[unstable(feature = "local_waker", issue = "118959")]
382-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
382+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
383383
pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self {
384384
Self { local_waker, ..self }
385385
}
386386

387387
/// This method is used to set the value for the extension data on `Context`.
388388
#[inline]
389389
#[unstable(feature = "context_ext", issue = "123392")]
390-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
390+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
391391
pub const fn ext(self, data: &'a mut dyn Any) -> Self {
392392
Self { ext: ExtData::Some(data), ..self }
393393
}
394394

395395
/// Builds the `Context`.
396396
#[inline]
397397
#[unstable(feature = "local_waker", issue = "118959")]
398-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
398+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
399399
pub const fn build(self) -> Context<'a> {
400400
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
401401
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
@@ -521,7 +521,7 @@ impl Waker {
521521
#[inline]
522522
#[must_use]
523523
#[stable(feature = "futures_api", since = "1.36.0")]
524-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
524+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
525525
pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
526526
Waker { waker }
527527
}
@@ -772,7 +772,7 @@ impl LocalWaker {
772772
#[inline]
773773
#[must_use]
774774
#[unstable(feature = "local_waker", issue = "118959")]
775-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
775+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
776776
pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker {
777777
Self { waker }
778778
}

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
#![feature(const_ipv6)]
8989
#![feature(const_mut_refs)]
9090
#![feature(const_pin)]
91-
#![feature(const_waker)]
9291
#![feature(never_type)]
9392
#![feature(unwrap_infallible)]
9493
#![feature(pointer_is_aligned_to)]

library/core/tests/waker.rs

+32
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,35 @@ static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
2020
|_| {},
2121
|_| {},
2222
);
23+
24+
// https://github.com/rust-lang/rust/issues/102012#issuecomment-1915282956
25+
mod nop_waker {
26+
use core::{
27+
future::{ready, Future},
28+
pin::Pin,
29+
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
30+
};
31+
32+
const NOP_RAWWAKER: RawWaker = {
33+
fn nop(_: *const ()) {}
34+
const VTAB: RawWakerVTable = RawWakerVTable::new(|_| NOP_RAWWAKER, nop, nop, nop);
35+
RawWaker::new(&() as *const (), &VTAB)
36+
};
37+
38+
const NOP_WAKER: &Waker = &unsafe { Waker::from_raw(NOP_RAWWAKER) };
39+
40+
const NOP_CONTEXT: Context<'static> = Context::from_waker(NOP_WAKER);
41+
42+
fn poll_once<T, F>(f: &mut F) -> Poll<T>
43+
where
44+
F: Future<Output = T> + ?Sized + Unpin,
45+
{
46+
let mut cx = NOP_CONTEXT;
47+
Pin::new(f).as_mut().poll(&mut cx)
48+
}
49+
50+
#[test]
51+
fn test_const_waker() {
52+
assert_eq!(poll_once(&mut ready(1)), Poll::Ready(1));
53+
}
54+
}

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@
407407
#![feature(const_ip)]
408408
#![feature(const_ipv4)]
409409
#![feature(const_ipv6)]
410-
#![feature(const_waker)]
411410
#![feature(thread_local_internals)]
412411
// tidy-alphabetical-end
413412
//

tests/ui/async-await/for-await-consumes-iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ edition: 2021
2-
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)]
2+
#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker)]
33

44
use std::future::Future;
55

tests/ui/async-await/for-await-passthrough.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
//@ edition: 2024
33
//@ compile-flags: -Zunstable-options
4-
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker,
4+
#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker,
55
gen_blocks)]
66

77
async gen fn async_iter() -> i32 {

tests/ui/async-await/for-await.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
//@ edition: 2021
3-
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)]
3+
#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker)]
44

55
use std::future::Future;
66

0 commit comments

Comments
 (0)