Skip to content

Commit

Permalink
Add test of packed struct that cannot be destructured
Browse files Browse the repository at this point in the history
Currently fails:

    error[E0509]: cannot move out of type `RemotePackedNonCopyDef`, which implements the `Drop` trait
       --> test_suite/tests/test_gen.rs:876:10
        |
    876 | #[derive(Deserialize)]
        |          ^^^^^^^^^^^
        |          |
        |          cannot move out of here
        |          data moved here
        |          move occurs because `__v1` has type `std::string::String`, which does not implement the `Copy` trait
        |
        = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
  • Loading branch information
dtolnay committed Aug 23, 2021
1 parent dc0c0dc commit 714c8a5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions test_suite/tests/test_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,36 @@ where

#[repr(packed)]
pub struct RemotePacked {
pub a: u8,
pub b: u16,
pub a: u16,
pub b: u32,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize)]
#[repr(packed)]
#[serde(remote = "RemotePacked")]
pub struct RemotePackedDef {
a: u8,
b: u16,
a: u16,
b: u32,
}

impl Drop for RemotePackedDef {
fn drop(&mut self) {}
}

#[repr(packed)]
pub struct RemotePackedNonCopy {
pub a: u16,
pub b: String,
}

#[derive(Deserialize)]
#[repr(packed)]
#[serde(remote = "RemotePackedNonCopy")]
pub struct RemotePackedNonCopyDef {
a: u16,
b: String,
}

impl Drop for RemotePackedNonCopyDef {
fn drop(&mut self) {}
}

0 comments on commit 714c8a5

Please sign in to comment.