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

Serde 1.0.172 with derive trait fails compilation on stable-x86_64-unknown-linux-gnu toolchain #2516

Closed
ShakenCodes opened this issue Jul 19, 2023 · 2 comments
Labels

Comments

@ShakenCodes
Copy link

Serde 1.0.172 introduces a compilation failure issue when compiling on stable-x86_64-unknown-linux-gnu toolchain, but compiles successfully on stable-aarch64-apple-darwin toolchain. Same code compiles correctly on both toolchains when serde depencency set to 1.0.171.

Serde dependency in Cargo.toml is: serde = { version = "=1.0.172", default-features = false, features = ["derive"] }

Code failing is similar to:
#[derive(Clone, Copy, Debug, Eq, Deserialize, PartialEq, Serialize)]
#[serde(transparent)]
pub struct MyStruct...

This is then used in another struct that also derives Deserialize and Serialize, and that code fails compilation on the Linux system. (Note this fails on a local test machine, and on a GitHub Actions container.)

Compilation reports (3 times for Deserialize, on the same line; once for Serialize at the original declaration):
error[E0277]: the trait bound MyStruct: Deserialize<'_> is not satisfied
--> my_usage.rs:134:24
|
134 | pub system_status: MyStruct,
| ^^^^^^^^^^^^^^^^^ the trait Deserialize<'_> is not implemented for MyStruct

error[E0277]: the trait bound SystemStatusFlags: Serialize is not satisfied
--> my_struct.rs:129:48
|
129 | #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
| ^^^^^^^^^ the trait Serialize is not implemented for MyStruct

@dtolnay
Copy link
Member

dtolnay commented Jul 19, 2023

I was able to reproduce this using the SystemStatusFlags definition you shared by email. Sorry about the breakage! I have published a fix in serde_derive 1.0.173.

// [dependencies]
// bitflags = { version = "2", features = ["serde"] }
// serde = { version = "1", default-features = false, features = ["derive"] }

use bitflags::bitflags;
use serde::{Serialize, Deserialize};

bitflags! {
    #[derive(Clone, Copy, Debug, Eq, Deserialize, PartialEq, Serialize)]
    #[serde(transparent)]
    pub struct SystemStatusFlags: u32 {
        const NO_ISSUES = 0x0000_0000;
        // ...
    }
}

@dtolnay dtolnay added the bug label Jul 19, 2023
@dtolnay dtolnay closed this as completed Jul 19, 2023
@ShakenCodes
Copy link
Author

Thank you for the remarkably fast resolution of this issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants