Skip to content

Updating serde breaks Value::into_rust for adjacently tagged enums #508

@nmsv

Description

@nmsv

The conversion of Value into a type fails in the following code snippet:

/*
[dependencies]
serde = { version = "=1.0.181", features = ["derive"] }
ron = "*"
*/

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
enum TheEnum {
    Variant([f32; 3]),
}

fn main() {
    let ron_value: ron::Value = ron::from_str("(type: \"Variant\", value: (0.1, 0.1, 0.1),)").unwrap();
    println!("--- deserialized as ron::Value ---\n{ron_value:#?}\n");
    ron_value.into_rust::<TheEnum>().unwrap();
}

The code panics on any serde version higher than 1.0.180, while it's totally fine on 1.0.180 or lower versions:

 InvalidValueForType { expected: "variant of enum TheEnum", found: "the string \"Variant\"" }

Edit: I also checked serde_json with the same enum and it works with any serde version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions