Structs with unaligned fields (through the repr(packed) attribute) were allowed before db96c51, which is unsound. After that commit, they stopped working, because initialized fields accessors create references to those fields; the compiler rejects creating references to unaligned fields. We then added explicit support for packed structs in 71988db by providing a way to not emit these field accessors. This is unsound, since the entire architecture of pin-init relies on aligned pointers. We thus removed the support again in #111.
To support packed structs there are two possibilities:
- Extend the current trait infrastructure with new ones:
- Add new traits
Unaligned[Pin]Init that relax the alignment requirement of their pointer
- Add an attribute to
init! to make it emit such an initializer instead (taking care of field accessors, only using ptr::write_unaligned and also expecting unaligned initializers)
- Extend the current
[Pin]Init traits:
- Extend the
Init trait with an associated boolean constant that specifies if the pointer must be aligned or not
- Make the
init! macro propagate this constant & ensure correct behavior based on it
Both of these seem quite invasive. So I'd like to wait and see for a real use-case of packed structs with pin-init that cannot easily work around it.
Structs with unaligned fields (through the
repr(packed)attribute) were allowed before db96c51, which is unsound. After that commit, they stopped working, because initialized fields accessors create references to those fields; the compiler rejects creating references to unaligned fields. We then added explicit support for packed structs in 71988db by providing a way to not emit these field accessors. This is unsound, since the entire architecture ofpin-initrelies on aligned pointers. We thus removed the support again in #111.To support packed structs there are two possibilities:
Unaligned[Pin]Initthat relax the alignment requirement of their pointerinit!to make it emit such an initializer instead (taking care of field accessors, only usingptr::write_unalignedand also expecting unaligned initializers)[Pin]Inittraits:Inittrait with an associated boolean constant that specifies if the pointer must be aligned or notinit!macro propagate this constant & ensure correct behavior based on itBoth of these seem quite invasive. So I'd like to wait and see for a real use-case of packed structs with pin-init that cannot easily work around it.