Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support packed remote struct without destructuring #2080

Merged
merged 2 commits into from Aug 23, 2021

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Aug 23, 2021

The destructuring-based implementation from #2079 is potentially problematic because not all objects can be destructured by value. For example:

#[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) {}
}
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)

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)
@dtolnay dtolnay merged commit c1c0ede into serde-rs:master Aug 23, 2021
@dtolnay dtolnay deleted the packeddrop branch August 23, 2021 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant