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

Possible to catch conflicting renames? #2851

Open
iamthad opened this issue Oct 30, 2024 · 2 comments
Open

Possible to catch conflicting renames? #2851

iamthad opened this issue Oct 30, 2024 · 2 comments

Comments

@iamthad
Copy link

iamthad commented Oct 30, 2024

I recently found that I had made a typo and gave two different variants of an enum the same name using #[serde(rename=...)].

The code was something like,

#[derive(Deserialize, Serialize)]
pub enum Foo {
    #[serde(rename = "bar")]
    Bar { qux: int, },
    // oops! meant to type "baz"
    #[serde(rename = "bar")]
    Baz { qux: int, },
}

I was surprised that I didn't encounter any error when compiling, serializing, or deserializing.

A complicating factor is that (like in the example above) both variants have the same fields. Perhaps if this weren't the case, I would have encountered some errors while deserializing.

I can't think of any reason off-hand why it would be desirable to allow conflicting names. It seems like it would always cause loss of data.

Would it be possible to catch this type of conflict? Is there some reason I am not thinking of that allowing conflicting names is desired?

@Mingun
Copy link
Contributor

Mingun commented Oct 30, 2024

Probably #2562 fixes that, but need to check. I got an impression that renames already was checked for uniquenesses.

@Mingun
Copy link
Contributor

Mingun commented Oct 30, 2024

Although no, here it is assumed that all names are already unique, and if they are not, they silently collapse into one entry in the BTreeSet

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

No branches or pull requests

2 participants