Skip to content

repr(packed) structs #112

@BennoLossin

Description

@BennoLossin

packed structs worked before db96c51, which is unsound. After that commit, packed structs stopped working, because the field accessors are references and they resulted in an error by the compiler. 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:

  1. 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)
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions