Skip to content

#[serde(rename)] and #[serde(alias)] should be forbidden on variants of untagged enums #2787

@Mingun

Description

@Mingun

Both attributes does nothing and just confuse users:

#[derive(serde::Deserialize)]
#[serde(untagged)]
pub enum Untagged {
    #[serde(rename = "unit", alias = "_1")]
    Unit,

    #[serde(rename = "newtype", alias = "_2")]
    Newtype(u32),

    #[serde(rename = "tuple", alias = "_3")]
    Tuple(u32, u32),

    #[serde(rename = "struct", alias = "_4")]
    Struct { a: u32 },
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bc78b6a4d132a2c255db120036d7fa42

Instead an error should be emitted that such attributes (maybe some other too!) does nothing and not allowed for untagged enums.

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