mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
stabilize const_waker
This commit is contained in:
parent
6ef11b81c2
commit
0a6ebbaf2e
@ -117,7 +117,6 @@
|
|||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_refs_to_cell)]
|
#![feature(const_refs_to_cell)]
|
||||||
#![feature(const_size_of_val)]
|
#![feature(const_size_of_val)]
|
||||||
#![feature(const_waker)]
|
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(deprecated_suggestion)]
|
#![feature(deprecated_suggestion)]
|
||||||
#![feature(deref_pure_trait)]
|
#![feature(deref_pure_trait)]
|
||||||
|
@ -163,7 +163,6 @@
|
|||||||
#![feature(const_ub_checks)]
|
#![feature(const_ub_checks)]
|
||||||
#![feature(const_unicode_case_lookup)]
|
#![feature(const_unicode_case_lookup)]
|
||||||
#![feature(const_unsafecell_get_mut)]
|
#![feature(const_unsafecell_get_mut)]
|
||||||
#![feature(const_waker)]
|
|
||||||
#![feature(coverage_attribute)]
|
#![feature(coverage_attribute)]
|
||||||
#![feature(do_not_recommend)]
|
#![feature(do_not_recommend)]
|
||||||
#![feature(duration_consts_float)]
|
#![feature(duration_consts_float)]
|
||||||
|
@ -250,7 +250,7 @@ pub struct Context<'a> {
|
|||||||
impl<'a> Context<'a> {
|
impl<'a> Context<'a> {
|
||||||
/// Create a new `Context` from a [`&Waker`](Waker).
|
/// Create a new `Context` from a [`&Waker`](Waker).
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[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]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_waker(waker: &'a Waker) -> Self {
|
pub const fn from_waker(waker: &'a Waker) -> Self {
|
||||||
@ -261,7 +261,7 @@ impl<'a> Context<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[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 {
|
pub const fn waker(&self) -> &'a Waker {
|
||||||
&self.waker
|
&self.waker
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ impl<'a> Context<'a> {
|
|||||||
/// Returns a reference to the [`LocalWaker`] for the current task.
|
/// Returns a reference to the [`LocalWaker`] for the current task.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "local_waker", issue = "118959")]
|
#[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 {
|
pub const fn local_waker(&self) -> &'a LocalWaker {
|
||||||
&self.local_waker
|
&self.local_waker
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ impl<'a> Context<'a> {
|
|||||||
/// Returns a reference to the extension data for the current task.
|
/// Returns a reference to the extension data for the current task.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "context_ext", issue = "123392")]
|
#[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 {
|
pub const fn ext(&mut self) -> &mut dyn Any {
|
||||||
// FIXME: this field makes Context extra-weird about unwind safety
|
// FIXME: this field makes Context extra-weird about unwind safety
|
||||||
// can we justify AssertUnwindSafe if we stabilize this? do we care?
|
// can we justify AssertUnwindSafe if we stabilize this? do we care?
|
||||||
@ -336,8 +336,8 @@ pub struct ContextBuilder<'a> {
|
|||||||
impl<'a> ContextBuilder<'a> {
|
impl<'a> ContextBuilder<'a> {
|
||||||
/// Create a ContextBuilder from a Waker.
|
/// Create a ContextBuilder from a Waker.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
|
|
||||||
#[unstable(feature = "local_waker", issue = "118959")]
|
#[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 {
|
pub const fn from_waker(waker: &'a Waker) -> Self {
|
||||||
// SAFETY: LocalWaker is just Waker without thread safety
|
// SAFETY: LocalWaker is just Waker without thread safety
|
||||||
let local_waker = unsafe { transmute(waker) };
|
let local_waker = unsafe { transmute(waker) };
|
||||||
@ -352,8 +352,8 @@ impl<'a> ContextBuilder<'a> {
|
|||||||
|
|
||||||
/// Create a ContextBuilder from an existing Context.
|
/// Create a ContextBuilder from an existing Context.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
|
|
||||||
#[unstable(feature = "context_ext", issue = "123392")]
|
#[unstable(feature = "context_ext", issue = "123392")]
|
||||||
|
#[rustc_const_unstable(feature = "context_ext", issue = "123392")]
|
||||||
pub const fn from(cx: &'a mut Context<'_>) -> Self {
|
pub const fn from(cx: &'a mut Context<'_>) -> Self {
|
||||||
let ext = match &mut cx.ext.0 {
|
let ext = match &mut cx.ext.0 {
|
||||||
ExtData::Some(ext) => ExtData::Some(*ext),
|
ExtData::Some(ext) => ExtData::Some(*ext),
|
||||||
@ -371,7 +371,7 @@ impl<'a> ContextBuilder<'a> {
|
|||||||
/// This method is used to set the value for the waker on `Context`.
|
/// This method is used to set the value for the waker on `Context`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "context_ext", issue = "123392")]
|
#[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 {
|
pub const fn waker(self, waker: &'a Waker) -> Self {
|
||||||
Self { waker, ..self }
|
Self { waker, ..self }
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ impl<'a> ContextBuilder<'a> {
|
|||||||
/// This method is used to set the value for the local waker on `Context`.
|
/// This method is used to set the value for the local waker on `Context`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "local_waker", issue = "118959")]
|
#[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 {
|
pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self {
|
||||||
Self { local_waker, ..self }
|
Self { local_waker, ..self }
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ impl<'a> ContextBuilder<'a> {
|
|||||||
/// This method is used to set the value for the extension data on `Context`.
|
/// This method is used to set the value for the extension data on `Context`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "context_ext", issue = "123392")]
|
#[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 {
|
pub const fn ext(self, data: &'a mut dyn Any) -> Self {
|
||||||
Self { ext: ExtData::Some(data), ..self }
|
Self { ext: ExtData::Some(data), ..self }
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ impl<'a> ContextBuilder<'a> {
|
|||||||
/// Builds the `Context`.
|
/// Builds the `Context`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "local_waker", issue = "118959")]
|
#[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> {
|
pub const fn build(self) -> Context<'a> {
|
||||||
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
|
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
|
||||||
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
|
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
|
||||||
@ -521,7 +521,7 @@ impl Waker {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[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 {
|
pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
|
||||||
Waker { waker }
|
Waker { waker }
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ impl LocalWaker {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "local_waker", issue = "118959")]
|
#[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 {
|
pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker {
|
||||||
Self { waker }
|
Self { waker }
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@
|
|||||||
#![feature(const_ipv6)]
|
#![feature(const_ipv6)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_waker)]
|
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(unwrap_infallible)]
|
#![feature(unwrap_infallible)]
|
||||||
#![feature(pointer_is_aligned_to)]
|
#![feature(pointer_is_aligned_to)]
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -407,7 +407,6 @@
|
|||||||
#![feature(const_ip)]
|
#![feature(const_ip)]
|
||||||
#![feature(const_ipv4)]
|
#![feature(const_ipv4)]
|
||||||
#![feature(const_ipv6)]
|
#![feature(const_ipv6)]
|
||||||
#![feature(const_waker)]
|
|
||||||
#![feature(thread_local_internals)]
|
#![feature(thread_local_internals)]
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
//
|
//
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//@ edition: 2021
|
//@ 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;
|
use std::future::Future;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//@ run-pass
|
//@ run-pass
|
||||||
//@ edition: 2024
|
//@ edition: 2024
|
||||||
//@ compile-flags: -Zunstable-options
|
//@ 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)]
|
gen_blocks)]
|
||||||
|
|
||||||
async gen fn async_iter() -> i32 {
|
async gen fn async_iter() -> i32 {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//@ run-pass
|
//@ run-pass
|
||||||
//@ edition: 2021
|
//@ 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;
|
use std::future::Future;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user