Skip to content

Ensure std::mem::Discriminant is Send + Sync - #45095

Merged
bors merged 1 commit into
rust-lang:masterfrom
bluss:discriminant-send-sync
Oct 10, 2017
Merged

Ensure std::mem::Discriminant is Send + Sync#45095
bors merged 1 commit into
rust-lang:masterfrom
bluss:discriminant-send-sync

Conversation

@bluss

@blussbluss commented Oct 7, 2017

Copy link
Copy Markdown
Contributor

PhantomData<*const T> has the implication of Send / Syncness following
the *const T type, but the discriminant should always be Send and Sync.

Use PhantomData<fn() -> T> which has the same variance in T, but is Send + Sync

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @BurntSushi

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss

bluss commented Oct 7, 2017

Copy link
Copy Markdown
ContributorAuthor

Tracking issue #24263

@bluss

bluss commented Oct 7, 2017

Copy link
Copy Markdown
ContributorAuthor

As discussed before on irc, a bit unclear what the correct phantom data really is for this thing.

`PhantomData<*const T>` has the implication of Send / Syncness following
the *const T type, but the discriminant should always be Send and Sync.
Use `PhantomData<fn() -> T>` which has the same variance in T, but is Send + Sync
@bluss
blussforce-pushed the discriminant-send-sync branch from 692a18d to 3fff2d9CompareOctober 7, 2017 23:10
@BurntSushi

Copy link
Copy Markdown
Member

I am throwing this to @aturon. I don't immediately see anything wrong with this, but I'd like someone else to see it! cc @rust-lang/libs

@BurntSushiBurntSushi assigned aturon and unassigned BurntSushiOct 8, 2017

@dtolnaydtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the tradeoffs of using a screwy PhantomData marker vs unsafe impl Send?

@ghost

ghost commented Oct 8, 2017

Copy link
Copy Markdown

Sometimes I wish we had a few additional marker structs so we could do:

_marker: PhantomData<Variant<T>>
_marker: PhantomData<Invariant<T>>
_marker: PhantomData<(T, NotSendSync)>

@alexcrichton

Copy link
Copy Markdown
Member

Looks good to me!

@dtolnay I think the usage of fn() -> T helps avoid the usage of unsafe impl, which seems like a bonus to me!

@carols10centscarols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2017
@carols10cents

Copy link
Copy Markdown
Member

Just a note that @aturon is on PTO this week so isn't likely to get to it, but it looks like this one is worth waiting for him to take a look.

@alexcrichton

Copy link
Copy Markdown
Member

I'm gonna go ahead and approve this as I think there won't be too much opposition, and we'll have a long time on nightly before this reaches stable as well!

@alexcrichtonalexcrichton added the relnotes Marks issues that should be documented in the release notes of the next release. label Oct 9, 2017
@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+

@bors

bors commented Oct 9, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 3fff2d9 has been approved by alexcrichton

@kennytmkennytm mentioned this pull request Oct 10, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Oct 10, 2017
…xcrichton
Ensure std::mem::Discriminant is Send + Sync
`PhantomData<*const T>` has the implication of Send / Syncness following
the *const T type, but the discriminant should always be Send and Sync.
Use `PhantomData<fn() -> T>` which has the same variance in T, but is Send + Sync
bors added a commit that referenced this pull request Oct 10, 2017
Rollup of 9 pull requests
- Successful merges: #44775, #45089, #45095, #45099, #45101, #45108, #45116, #45135, #45146
- Failed merges:
@bors
bors merged commit 3fff2d9 into rust-lang:masterOct 10, 2017
@bluss
bluss deleted the discriminant-send-sync branch October 29, 2017 19:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@bluss@rust-highfive@BurntSushi@alexcrichton@carols10cents@bors@dtolnay@aturon