mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Rollup merge of #101798 - y86-dev:const_waker, r=lcnr
Make `from_waker`, `waker` and `from_raw` unstably `const` Make - `Context::from_waker` - `Context::waker` - `Waker::from_raw` `const`. Also added a small test.
This commit is contained in:
commit
ea076a4f9f
@ -109,6 +109,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_eval_select)]
|
||||
#![feature(const_pin)]
|
||||
#![feature(const_waker)]
|
||||
#![feature(cstr_from_bytes_until_nul)]
|
||||
#![feature(dispatch_from_dyn)]
|
||||
#![cfg_attr(not(bootstrap), feature(error_generic_member_access))]
|
||||
|
@ -145,6 +145,7 @@
|
||||
#![feature(const_default_impls)]
|
||||
#![feature(const_unicode_case_lookup)]
|
||||
#![feature(const_unsafecell_get_mut)]
|
||||
#![feature(const_waker)]
|
||||
#![feature(core_panic)]
|
||||
#![feature(duration_consts_float)]
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
|
@ -186,17 +186,19 @@ 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")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn from_waker(waker: &'a Waker) -> Self {
|
||||
pub const fn from_waker(waker: &'a Waker) -> Self {
|
||||
Context { waker, _marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Returns a reference to the [`Waker`] for the current task.
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn waker(&self) -> &'a Waker {
|
||||
pub const fn waker(&self) -> &'a Waker {
|
||||
&self.waker
|
||||
}
|
||||
}
|
||||
@ -311,7 +313,8 @@ impl Waker {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
pub unsafe fn from_raw(waker: RawWaker) -> Waker {
|
||||
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
|
||||
pub const unsafe fn from_raw(waker: RawWaker) -> Waker {
|
||||
Waker { waker }
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@
|
||||
#![feature(iterator_try_reduce)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_pin)]
|
||||
#![feature(const_waker)]
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(pointer_byte_offsets)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use core::task::Poll;
|
||||
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
|
||||
|
||||
#[test]
|
||||
fn poll_const() {
|
||||
@ -12,3 +12,18 @@ fn poll_const() {
|
||||
const IS_PENDING: bool = POLL.is_pending();
|
||||
assert!(IS_PENDING);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn waker_const() {
|
||||
const VOID_TABLE: RawWakerVTable = RawWakerVTable::new(|_| VOID_WAKER, |_| {}, |_| {}, |_| {});
|
||||
|
||||
const VOID_WAKER: RawWaker = RawWaker::new(&(), &VOID_TABLE);
|
||||
|
||||
static WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
|
||||
|
||||
static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
|
||||
|
||||
static WAKER_REF: &'static Waker = CONTEXT.waker();
|
||||
|
||||
WAKER_REF.wake_by_ref();
|
||||
}
|
||||
|
@ -315,6 +315,7 @@
|
||||
#![feature(strict_provenance)]
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
#![feature(const_maybe_uninit_uninit_array)]
|
||||
#![feature(const_waker)]
|
||||
//
|
||||
// Library features (alloc):
|
||||
#![feature(alloc_layout_extra)]
|
||||
|
Loading…
Reference in New Issue
Block a user