Skip to content

Erroneous warning about packed struct not implementing Copy #71740

Closed
@ghost

Description

I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7d186291bfe30222d01ed0af2fa28c4c

use serde::{Serialize, Deserialize};



#[repr(C)]
#[repr(packed)]
#[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Debug)]
struct Packed {
    a: u8,
    b: u16,
    c: u8
}

fn main() {}

I expected to see this happen: Compile without any warning or error.

Instead, this happened: The following warning was emitted:

   Compiling playground v0.0.1 (/playground)
warning: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
 --> src/main.rs:8:23
  |
8 | #[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Debug)]
  |                       ^^^^^^^^^
  |
  = note: `#[warn(safe_packed_borrows)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
  = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

    Finished dev [unoptimized + debuginfo] target(s) in 0.65s
     Running `target/debug/playground`

Meta

rustc --version --verbose:

<version>
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-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