From 714c8a558688e496bbdec080fb0c96d3623c61fd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 23 Aug 2021 10:49:32 -0700 Subject: [PATCH] Add test of packed struct that cannot be destructured 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) --- test_suite/tests/test_gen.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index 3e19d3c4b..53a1bfe37 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -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) {} }