-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Add checks for conflicts for aliases #2562
Conversation
- Check that alias is not the same as name of other field (it still can be the name of owning field/variant) - Check that aliases are unique, i. e. two different fields does not use the same alias
Annoying that we can't crater it first, but this also catches really subtly broken code, so I guess we can Yolo it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this can be released as is. This is a pretty blatant breaking change in existing working code.
I would recommend emitting something like a unreachable_patterns
warning on duplicated names.
The code would never have worked correctly. I don't think anyone would ship this for long without users complaining. If we were shipping such a breaking change in rustc, this would be the equivalent of adding an error for unsound code that we know has almost no real world usage |
I do not agree that this PR is analogous to rustc emitting a new error on an unsound code pattern. It is analogous to rustc deciding that unreachable patterns are a hard error now, because their previous behavior cannot possibly be what the person who wrote the unreachable pattern intended. For code in which deserializing to the first variant with the same alias was the desired behavior (hence users not complaining) I don't understand why it's better for a new version of serde to break them as opposed to a warning that says to remove the irrelevant alias. |
It would be better, if error points to corresponding alias, but currently alias spans are not stored anywhere, so I left this to another PR.
Fixes #2308, fixes #2551