Open z33ky opened 6 years ago
The full error has changed in recent years, and now contains a note
which suggests a partial workaround:
= note: the last field of a packed struct may only have a dynamically sized type if it does not need drop to be run
Thus prompted, I discovered that wrapping the DST field in ManuallyDrop
allows compilation to complete successfully:
#[repr(packed)]
- struct Foo<T: ?Sized>(T): // err
+ struct Foo<T: ?Sized>(std::mem::ManuallyDrop<T>); // no err
For some reason, using a generic
T: ?Sized
does not work in arepr(packed)
struct, while a non-generic unsized type is OK.An non-
packed
is also OK:struct Foo<T: ?Sized>(T); // ok
The full error:
This may be related to #47068?
Meta