Skip to content

Commit ad05195

Browse files
committed
stabilize const_waker
1 parent 6ef11b8 commit ad05195

File tree

9 files changed

+49
-19
lines changed

9 files changed

+49
-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-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)]
@@ -226,6 +225,7 @@
226225
#![feature(lang_items)]
227226
#![feature(let_chains)]
228227
#![feature(link_llvm_intrinsics)]
228+
#![feature(local_waker)]
229229
#![feature(macro_metavar_expr)]
230230
#![feature(marker_trait_attr)]
231231
#![feature(min_exhaustive_patterns)]

library/core/src/task/wake.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ 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")]
254+
#[rustc_allow_const_fn_unstable(local_waker)]
254255
#[must_use]
255256
#[inline]
256257
pub const fn from_waker(waker: &'a Waker) -> Self {
@@ -261,23 +262,23 @@ impl<'a> Context<'a> {
261262
#[inline]
262263
#[must_use]
263264
#[stable(feature = "futures_api", since = "1.36.0")]
264-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
265+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
265266
pub const fn waker(&self) -> &'a Waker {
266267
&self.waker
267268
}
268269

269270
/// Returns a reference to the [`LocalWaker`] for the current task.
270271
#[inline]
271272
#[unstable(feature = "local_waker", issue = "118959")]
272-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
273+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
273274
pub const fn local_waker(&self) -> &'a LocalWaker {
274275
&self.local_waker
275276
}
276277

277278
/// Returns a reference to the extension data for the current task.
278279
#[inline]
279280
#[unstable(feature = "context_ext", issue = "123392")]
280-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
281+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
281282
pub const fn ext(&mut self) -> &mut dyn Any {
282283
// FIXME: this field makes Context extra-weird about unwind safety
283284
// can we justify AssertUnwindSafe if we stabilize this? do we care?
@@ -336,8 +337,8 @@ pub struct ContextBuilder<'a> {
336337
impl<'a> ContextBuilder<'a> {
337338
/// Create a ContextBuilder from a Waker.
338339
#[inline]
339-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
340340
#[unstable(feature = "local_waker", issue = "118959")]
341+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
341342
pub const fn from_waker(waker: &'a Waker) -> Self {
342343
// SAFETY: LocalWaker is just Waker without thread safety
343344
let local_waker = unsafe { transmute(waker) };
@@ -352,8 +353,8 @@ impl<'a> ContextBuilder<'a> {
352353

353354
/// Create a ContextBuilder from an existing Context.
354355
#[inline]
355-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
356356
#[unstable(feature = "context_ext", issue = "123392")]
357+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
357358
pub const fn from(cx: &'a mut Context<'_>) -> Self {
358359
let ext = match &mut cx.ext.0 {
359360
ExtData::Some(ext) => ExtData::Some(*ext),
@@ -371,31 +372,31 @@ impl<'a> ContextBuilder<'a> {
371372
/// This method is used to set the value for the waker on `Context`.
372373
#[inline]
373374
#[unstable(feature = "context_ext", issue = "123392")]
374-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
375+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
375376
pub const fn waker(self, waker: &'a Waker) -> Self {
376377
Self { waker, ..self }
377378
}
378379

379380
/// This method is used to set the value for the local waker on `Context`.
380381
#[inline]
381382
#[unstable(feature = "local_waker", issue = "118959")]
382-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
383+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
383384
pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self {
384385
Self { local_waker, ..self }
385386
}
386387

387388
/// This method is used to set the value for the extension data on `Context`.
388389
#[inline]
389390
#[unstable(feature = "context_ext", issue = "123392")]
390-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
391+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
391392
pub const fn ext(self, data: &'a mut dyn Any) -> Self {
392393
Self { ext: ExtData::Some(data), ..self }
393394
}
394395

395396
/// Builds the `Context`.
396397
#[inline]
397398
#[unstable(feature = "local_waker", issue = "118959")]
398-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
399+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
399400
pub const fn build(self) -> Context<'a> {
400401
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
401402
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
@@ -521,7 +522,7 @@ impl Waker {
521522
#[inline]
522523
#[must_use]
523524
#[stable(feature = "futures_api", since = "1.36.0")]
524-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
525+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
525526
pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
526527
Waker { waker }
527528
}
@@ -772,7 +773,7 @@ impl LocalWaker {
772773
#[inline]
773774
#[must_use]
774775
#[unstable(feature = "local_waker", issue = "118959")]
775-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
776+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
776777
pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker {
777778
Self { waker }
778779
}

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)