Open
Description
For some reason, using a generic T: ?Sized
does not work in a repr(packed)
struct, while a non-generic unsized type is OK.
#[repr(packed)]
struct Bar([u8]); // ok
#[repr(packed)]
struct Foo<T: ?Sized>(T): // err
An non-packed
is also OK:
struct Foo<T: ?Sized>(T); // ok
The full error:
error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
|
5 | struct Foo<T: ?Sized>(T); // err
| ^^ `T` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `T`
= help: consider adding a `where T: std::marker::Sized` bound
= note: only the last field of a struct may have a dynamically sized type
This may be related to #47068?
Meta
$ rust --version --verbose
rustc 1.25.0 (84203cac6 2018-03-25)
binary: rustc
commit-hash: 84203cac67e65ca8640b8392348411098c856985
commit-date: 2018-03-25
host: x86_64-unknown-linux-gnu
release: 1.25.0
LLVM version: 6.0