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(rename)] and #[serde(alias)] should be forbidden on variants of untagged enums #2787

Open
Mingun opened this issue Aug 6, 2024 · 0 comments · May be fixed by #2797
Open

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

Mingun opened this issue Aug 6, 2024 · 0 comments · May be fixed by #2797

Comments

@Mingun
Copy link
Contributor

Mingun commented Aug 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant