-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Derived PartialOrd
implementations don't match originals
#97
Comments
Please, clarify how this bug affects library users. Thank you! |
Sure! I'll break this up so anyone who runs across this one can see the big picture: Explanation of the problemHere's a rust playground link, select Tools > Expand macros. This will show the builtin derive for The builtin implementation of When calculating the How it interacts with rkyvThe Because archived types are supposed to be perfectly interchangeable with their unarchived counterparts, we need to guarantee that the To match the builtin implementation, we need to compare the discriminants of the enums first. This isn't great, but we can bound the What it means for library usersRight now, rkyv produces implementations of It's important to note that this problem only applies to enums, and using rkyv to generate |
Partially mitigated by bc5b2f4. This uses the generated tag enum as a stand-in for the discriminant value for the archived enum. There's no guarantee that this tag will have the same relationships between its enum variants as the discriminants of the archived enum, but it should be the same in all the cases I can think of. |
The language may be providing a way to fix this soon: rust-lang/rfcs#3607 |
This is a nasty one.
The builtin
PartialOrd
implementation compares enums by discriminant first, and uses that to determine whether entire variants are greater or less than each other. This is a problem because the discriminants for the original and archived enums may not be ordered the same way, so even if we could compare the discriminants of the two, they wouldn't be guaranteed to provide the same ordering between original and archived values.Right now we manually assign a new discriminant that may not be the same as the true discriminant, and use that to determine whether two enums are greater or less. This still doesn't provide the same orderings between original and archived values, but it's what we can do.
The text was updated successfully, but these errors were encountered: