Skip to content

Deserialize failed to derive on enums with tuple variant and flatten struct variant #1904

@Mingun

Description

@Mingun

Instead of thousand of words

This code is failed to compile due to panic in serde derive:

#[derive(Deserialize)]
enum Failed {
    Tuple(f64, String),
    Flatten {
        #[serde(flatten)]
        nested: Nested,
    },
}

Output:

   Compiling playground v0.0.1 (/playground)
error: proc-macro derive panicked
  --> src/lib.rs:30:10
   |
30 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Each variant individually and Serialize derive works well, problem is only in combination of tuple variant and struct variant, when struct variant contains flattened field.

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