Skip to content

Commit 604d618

Browse files
Rollup merge of rust-lang#128228 - slanterns:const_waker, r=dtolnay,oli-obk
Stabilize `const_waker` Closes: rust-lang#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 rust-lang#102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.`` ``@rustbot`` label: +T-libs-api r? libs-api
2 parents 2a70839 + d6b6e63 commit 604d618

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
#![feature(const_pin)]
117117
#![feature(const_refs_to_cell)]
118118
#![feature(const_size_of_val)]
119-
#![feature(const_waker)]
120119
#![feature(core_intrinsics)]
121120
#![feature(deprecated_suggestion)]
122121
#![feature(deref_pure_trait)]

core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
#![feature(const_ub_checks)]
163163
#![feature(const_unicode_case_lookup)]
164164
#![feature(const_unsafecell_get_mut)]
165-
#![feature(const_waker)]
166165
#![feature(coverage_attribute)]
167166
#![feature(do_not_recommend)]
168167
#![feature(duration_consts_float)]

core/src/task/wake.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub struct Context<'a> {
251251
impl<'a> Context<'a> {
252252
/// Creates a new `Context` from a [`&Waker`](Waker).
253253
#[stable(feature = "futures_api", since = "1.36.0")]
254-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
254+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
255255
#[must_use]
256256
#[inline]
257257
pub const fn from_waker(waker: &'a Waker) -> Self {
@@ -262,23 +262,23 @@ impl<'a> Context<'a> {
262262
#[inline]
263263
#[must_use]
264264
#[stable(feature = "futures_api", since = "1.36.0")]
265-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
265+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
266266
pub const fn waker(&self) -> &'a Waker {
267267
&self.waker
268268
}
269269

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

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

354354
/// Creates a ContextBuilder from an existing Context.
355355
#[inline]
356-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
357356
#[unstable(feature = "context_ext", issue = "123392")]
357+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
358358
pub const fn from(cx: &'a mut Context<'_>) -> Self {
359359
let ext = match &mut cx.ext.0 {
360360
ExtData::Some(ext) => ExtData::Some(*ext),
@@ -372,31 +372,31 @@ impl<'a> ContextBuilder<'a> {
372372
/// Sets the value for the waker on `Context`.
373373
#[inline]
374374
#[unstable(feature = "context_ext", issue = "123392")]
375-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
375+
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
376376
pub const fn waker(self, waker: &'a Waker) -> Self {
377377
Self { waker, ..self }
378378
}
379379

380380
/// Sets the value for the local waker on `Context`.
381381
#[inline]
382382
#[unstable(feature = "local_waker", issue = "118959")]
383-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
383+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
384384
pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self {
385385
Self { local_waker, ..self }
386386
}
387387

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

396396
/// Builds the `Context`.
397397
#[inline]
398398
#[unstable(feature = "local_waker", issue = "118959")]
399-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
399+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
400400
pub const fn build(self) -> Context<'a> {
401401
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
402402
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
@@ -522,7 +522,7 @@ impl Waker {
522522
#[inline]
523523
#[must_use]
524524
#[stable(feature = "futures_api", since = "1.36.0")]
525-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
525+
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
526526
pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
527527
Waker { waker }
528528
}
@@ -773,7 +773,7 @@ impl LocalWaker {
773773
#[inline]
774774
#[must_use]
775775
#[unstable(feature = "local_waker", issue = "118959")]
776-
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
776+
#[rustc_const_unstable(feature = "local_waker", issue = "118959")]
777777
pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker {
778778
Self { waker }
779779
}

core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
#![feature(const_ipv6)]
8888
#![feature(const_mut_refs)]
8989
#![feature(const_pin)]
90-
#![feature(const_waker)]
9190
#![feature(never_type)]
9291
#![feature(unwrap_infallible)]
9392
#![feature(pointer_is_aligned_to)]

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+
}

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
//

0 commit comments

Comments
 (0)