Closed
Description
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:
- Make derive detect
#[repr(packed)]
(can it?) and change the generated code. - Generate the code in a way that always works for packed structs (I somewhat doubt this is possible).
- Do nothing. Let the users deal with manually implementing derivable traits for packed structs.
- Do something I didn't think of.