diff options
| author | Michael Goulet <michael@errs.io> | 2023-01-02 15:39:16 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-02 15:39:16 -0800 |
| commit | 722bc0c8ee92b391ddf6bd77f43fae1432d9234f (patch) | |
| tree | 77a4027bd7c35a6a61acba1232d495f6198b5140 | |
| parent | d6f99e535a301a421dfee52a7c25bb4bdf420344 (diff) | |
| parent | 257e766c0c17c1a3561a509c931cf89bce27dcf5 (diff) | |
Rollup merge of #95985 - jihiggins:issue-66481, r=dtolnay
Add PhantomData marker to Context to make Context !Send and !Sync Adds `PhantomData<*mut ()>` to `Context` in order to allow for future `!Send` or `!Sync` additions to `Context`'s fields. This would allow for things like future single threaded async executor optimizations, or (re)adding `LocalWaker`, etc. Closes #66481. Per https://github.com/rust-lang/rust/issues/66481#issuecomment-561289725, this is a breaking change that needs a Crater run as the next step. (So far have tested the change locally with `cargotest` on WSL)
| -rw-r--r-- | library/core/src/task/wake.rs | 5 | ||||
| -rw-r--r-- | library/core/tests/task.rs | 8 |
2 files changed, 6 insertions, 7 deletions
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 1b7578376b4..a4425fd234a 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -181,6 +181,9 @@ pub struct Context<'a> { // are contravariant while return-position lifetimes are // covariant). _marker: PhantomData<fn(&'a ()) -> &'a ()>, + // Ensure `Context` is `!Send` and `!Sync` in order to allow + // for future `!Send` and / or `!Sync` fields. + _marker2: PhantomData<*mut ()>, } impl<'a> Context<'a> { @@ -190,7 +193,7 @@ impl<'a> Context<'a> { #[must_use] #[inline] pub const fn from_waker(waker: &'a Waker) -> Self { - Context { waker, _marker: PhantomData } + Context { waker, _marker: PhantomData, _marker2: PhantomData } } /// Returns a reference to the [`Waker`] for the current task. diff --git a/library/core/tests/task.rs b/library/core/tests/task.rs index 56be30e9282..163b34c9648 100644 --- a/library/core/tests/task.rs +++ b/library/core/tests/task.rs @@ -1,4 +1,4 @@ -use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; +use core::task::{Poll, RawWaker, RawWakerVTable, Waker}; #[test] fn poll_const() { @@ -21,9 +21,5 @@ fn waker_const() { 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(); + WAKER.wake_by_ref(); } |
