Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upspecify that CoerceUnsized should ignore PhantomData fields #1234
Conversation
Gankro
referenced this pull request
Aug 3, 2015
Closed
Ignore PhantomData when checking CoerceUnsized implementations #27483
nrc
added
the
T-lang
label
Aug 3, 2015
nrc
self-assigned this
Aug 3, 2015
This comment has been minimized.
This comment has been minimized.
|
+1 Alternatively we could allow this for all ZSTs, and just implement for PhantomData for now. Special casing PhantomData is pretty much an implementation detail. Could we approximate zero-sized == no non-zero-sized fields? Presumably we'd need to wait for the drop flag to disappear. Then just assert that we were right in trans. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I agree with @nrc that the text shouldn't be specific to |
This comment has been minimized.
This comment has been minimized.
|
I guess the question is whether unsizing two fields is forbidden for semantic or implementation (offsets fall over with multiple unsized fields) reasons -- if it's semantic then PhantomData is the only type we really know doesn't matter. If it's implementation then presumably all ZSTs should be fine. |
This comment has been minimized.
This comment has been minimized.
|
if we're going to patch in place, can we make a section at the end entitled something like "Updates since being accepted" and record the changes |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis done. |
This comment has been minimized.
This comment has been minimized.
|
So, regarding the specialization to @eddyb thoughts? |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I would suggest limiting this as much as possible, otherwise it might allow writing |
This comment has been minimized.
This comment has been minimized.
|
@eddyb can you explain what you mean by "allow writing transmute in safe code"? (e.g., maybe give an example) Perhaps I have to refresh my memory of just which traits we're talking about here. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis The transmute remark was about the worst case, where arbitrary types are converted without an actual coercion, e.g: struct Foo<P, T>(Box<P>, T);
impl<P: Unsize<Q>, T, U> CoerceUnsized<Foo<Q, U>> for Foo<P, T> {}Though I doubt you had that in mind. |
aturon
referenced this pull request
Aug 12, 2015
Open
Tracking issue for DST coercions (coerce_unsized, unsize) stabilization #27732
This comment has been minimized.
This comment has been minimized.
|
We discussed this today in the language subteam meeting. The conclusion was that while many of us believe we can generalize DST coercions further (read: @nikomatsakis does, at least), we should not let the perfect be the enemy of the good. Therefore, we should take this RFC, and consider further generalizing the rules another time. |
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye. This RFC is entering final comment period. |
nikomatsakis
added
the
final-comment-period
label
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
Ah, @Gankro, can you amend the RFC to include as an "unresolved question" the extent to which coercion can be generalized to simply permit multiple fields to be coerced? |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis done |
nikomatsakis
merged commit 969912a
into
rust-lang:master
Sep 4, 2015
nikomatsakis
referenced this pull request
Sep 4, 2015
Closed
Tracking issue for PhantomData being permitted by CoerceUnsize (RFC #1234) #28239
This comment has been minimized.
This comment has been minimized.
|
Huzzah. The lang subteam has decided to accept this RFC. Tracking issue rust-lang/rust#28239. |
Gankro commentedAug 3, 2015
Otherwise you can't have a
Smaht<T>(*const T, PhantomData<T>), which is problematic for drop check, which requires this annotation if Smaht owns the referrent (Box, Rc, Vec, etc..).See rust-lang/rust#26905 for some discussion.
You could arguably ignore all zero-sized fields, but it's currently hard for the compiler to do so (size is largely a trans notion, to my knowledge). Also maybe you actually want a generic ZST field that has some meaning beyond PhantomData?
A potential workaround to this problem would be
Smaht(*const u8, PhantomData<T>)but this is entering a fairly degenerate state for the semantics of raw pointers. Although we're already in a bit of a degenerate state in that all Smaht pointers desire some level of mutable access, but are forced to use*constto acquire the correct variance. We paper over that mess via Unique -- we could consider just embracing that and making Unique the only proper way to build Smaht pointers.Of course Unique is incorrect for Rc, but I plan on adding a Shared equivalent for Rc anyway which could have similar magicks.