Skip to content

Commit

Permalink
Rollup merge of #95985 - jihiggins:issue-66481, r=dtolnay
Browse files Browse the repository at this point in the history
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 #66481 (comment), 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)
  • Loading branch information
compiler-errors authored Jan 2, 2023
2 parents d6f99e5 + 257e766 commit 722bc0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 4 additions & 1 deletion library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions library/core/tests/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use core::task::{Poll, RawWaker, RawWakerVTable, Waker};

#[test]
fn poll_const() {
Expand All @@ -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();
}

0 comments on commit 722bc0c

Please sign in to comment.