Stream: t-lang/wg-unsafe-code-guidelines

Topic: Guarantees about layout of generic aggregates


gnzlbg (Dec 19 2019 at 14:09, on Zulip):

Given:

struct S<T, U, V>(T, U, PhantomData<V>);

is transmute::<&S<A, B, C>, &S<A, B, D>() sound?

(notice that for<T> PhantomData<T> is a 1-ZST and is therefore ignored for layout purposes)

rkruppe (Dec 19 2019 at 14:45, on Zulip):

I'm quite sure that transmute doesn't follow from our current guarantees for struct layout. It's not one of the special cases where we say anything other than "nothing is guaranteed, not even determinism"

rkruppe (Dec 19 2019 at 14:47, on Zulip):

But clearly this kind of transmute is extremly useful for some uses of phantom types and requiring repr(C) on those aggregates has big downsides so IMO we eventually need some way to make this work while still getting e.g. automatic struct reordering for reducing padding

Last update: May 26 2020 at 08:45UTC