Skip to content

Deserializing internally-tagged enums fails on nightly Rust #579

@jwodder

Description

@jwodder

The following code:

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(tag = "type")]
enum Message {
    Request {
        id: u32,
        resource: String,
        operation: String,
    },
    Response {
        id: u32,
        value: String,
    },
}

fn main() {
    let value = Message::Response {
        id: 60069,
        value: "Foobar".into(),
    };
    let serialized = ron::to_string(&value).unwrap();
    println!("Serialized:");
    println!("{serialized}");
    println!();
    let deserialized: Message = ron::from_str(&serialized).unwrap();
    println!("Deserialized:");
    println!("{deserialized:#?}");
}

with the following dependencies:

[dependencies]
ron = "0.10.1"
serde = { version = "1.0.219", features = ["derive"] }

succeeds when run on Rust 1.89, but when rustc 1.91.0-nightly (425a9c0a0 2025-08-17) — the first version on which I have observed this problem — is used instead, the program fails with:

Serialized:
(type:"Response",id:60069,value:"Foobar")


thread 'main' (5637368) panicked at src/main.rs:35:60:
called `Result::unwrap()` on an `Err` value: SpannedError { code: ExpectedIdentifier, position: Position { line: 1, col: 7 } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions