Skip to content

What should we do about #[derive(...)] on #[repr(packed)] structs? #39696

Closed
@solson

Description

@solson

The derived trait instances for packed structs tend to take references to the packed struct fields, which can cause undefined behavior (unaligned loads) and will be detected as unsafe once #27060 is fixed. So, code using these derives on packed structs will stop compiling.

See also #39682 where I fixed impls in a Rust test and #39683 where I fixed an impl in rustc.

Should we:

  1. Make derive detect #[repr(packed)] (can it?) and change the generated code.
  2. Generate the code in a way that always works for packed structs (I somewhat doubt this is possible).
  3. Do nothing. Let the users deal with manually implementing derivable traits for packed structs.
  4. Do something I didn't think of.

cc @Aatch @bluss @retep998 @rust-lang/compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions