Skip to content

Commit

Permalink
Unrolled build for rust-lang#128228
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rust-timer authored Jul 28, 2024
2 parents 188ddf4 + 0a6ebba commit 13c6b98
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 19 deletions.
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
24 changes: 12 additions & 12 deletions library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ 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")]
#[rustc_const_stable(feature = "const_waker", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub const fn from_waker(waker: &'a Waker) -> Self {
Expand All @@ -261,23 +261,23 @@ 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
}

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

/// 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?
Expand Down Expand Up @@ -336,8 +336,8 @@ pub struct ContextBuilder<'a> {
impl<'a> ContextBuilder<'a> {
/// Create 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) };
Expand All @@ -352,8 +352,8 @@ impl<'a> ContextBuilder<'a> {

/// Create 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),
Expand All @@ -371,31 +371,31 @@ impl<'a> ContextBuilder<'a> {
/// This method is used to set 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 }
}

/// This method is used to set 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 }
}

/// This method is used to set 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 }
}

/// 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 }
Expand Down Expand Up @@ -521,7 +521,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 }
}
Expand Down Expand Up @@ -772,7 +772,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 }
}
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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)]
Expand Down
32 changes: 32 additions & 0 deletions library/core/tests/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@
#![feature(const_ip)]
#![feature(const_ipv4)]
#![feature(const_ipv6)]
#![feature(const_waker)]
#![feature(thread_local_internals)]
// tidy-alphabetical-end
//
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/for-await-consumes-iter.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/for-await-passthrough.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/for-await.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit 13c6b98

Please sign in to comment.