Skip to content

Debug on packed structs causes error on non-Copy fields #117406

Closed
@Super-Pizza

Description

@Super-Pizza

The following code causes a compilation error.

#[repr(packed)]
#[derive(Debug)]
struct B(String);
fn main(){}

Error

error[E0507]: cannot move out of `self` which is behind a shared reference
 --> src/main.rs:4:10
  |
3 | #[derive(Debug)]
  |          ----- in this derive macro expansion
4 | struct B(String);
  |          ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
  |
  = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0507`.

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-compilerRelevant to the compiler 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