Skip to content

Making unaligned_references a hard error broke derives on packed structs without warning #110645

Closed as not planned
@LegionMammal978

Description

@LegionMammal978

I tried this code:

#[derive(Clone)]
pub struct Foo;

#[derive(Clone)]
#[repr(packed)]
pub struct Bar(Foo);

I expected to see this happen: A deny-by-default unaligned_references lint (or similar) in Rust 1.68.2, and a hard error in Rust 1.69.0.

Instead, this happened: No lint in Rust 1.68.2, and a hard error in Rust 1.69.0:

error[E0507]: cannot move out of `self` which is behind a shared reference
 --> src/lib.rs:6:16
  |
4 | #[derive(Clone)]
  |          ----- in this derive macro expansion
5 | #[repr(packed)]
6 | pub struct Bar(Foo);
  |                ^^^ move occurs because `self.0` has type `Foo`, which does not implement the `Copy` trait
  |
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

(This issue was originally reported by @UncombedCoconut, who found that the bbchallenge decider-finite-automata-reduction crate no longer compiles in 1.69.0, due to the use of derive macros on a packed struct.)

Meta

rustc --version --verbose:

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions