You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, while resolving the memory safety issue of #28 that you pointed out in #27, I had a pause while reaching the implementation of Abomonation for PhantomData.
Currently, abomonation provides an impl of Abomonation for PhantomData<T> even if T is not abomonable. This is by design, as there is a test checking that this impl is available. And it is certainly technically correct to the first order of approximation: since PhantomData contains no data, it is trivially serializable.
Where I get uneasy, though, is when I consider how PhantomData<T> is typically used. By and large, the main use for this marker type in the wild is in container classes like Box and Vec, where you get types which only hold a *mut T, NonNull<T>, or index into some kind of arena of T, but need to tell rustc that they "logically own" one or more Ts, so that Send, Sync, Drop and other stuff that gets automatically implemented works as expected.
From this perspective, if a type contains a PhantomData<T>, it should almost certainly be regarded as containing a T by abomonation too. In which case we should require that this T be abomonable.
What do you think about this train of thought?
The text was updated successfully, but these errors were encountered:
So, while resolving the memory safety issue of #28 that you pointed out in #27, I had a pause while reaching the implementation of
Abomonation
forPhantomData
.Currently, abomonation provides an impl of
Abomonation
forPhantomData<T>
even if T is not abomonable. This is by design, as there is a test checking that this impl is available. And it is certainly technically correct to the first order of approximation: sincePhantomData
contains no data, it is trivially serializable.Where I get uneasy, though, is when I consider how
PhantomData<T>
is typically used. By and large, the main use for this marker type in the wild is in container classes likeBox
andVec
, where you get types which only hold a*mut T
,NonNull<T>
, or index into some kind of arena ofT
, but need to tellrustc
that they "logically own" one or moreT
s, so thatSend
,Sync
,Drop
and other stuff that gets automatically implemented works as expected.From this perspective, if a type contains a
PhantomData<T>
, it should almost certainly be regarded as containing aT
by abomonation too. In which case we should require that thisT
be abomonable.What do you think about this train of thought?
The text was updated successfully, but these errors were encountered: