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

Fix type inference failures in PartialOrd/Ord impls #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sfackler
Copy link

@sfackler sfackler commented Feb 7, 2025

Closes #36

@sfackler
Copy link
Author

sfackler commented Feb 7, 2025

Uh, looking at this again, doesn't this comparison assume that the tag is at the start of the enum? I don't think that's guaranteed by anything.

If an enum has opted-in to having a primitive representation for its discriminant, then it’s possible to use pointers to read the memory location storing the discriminant. That cannot be done for enums using the default representation, however, as it’s undefined what layout the discriminant has and where it’s stored — it might not even be stored at all!

https://doc.rust-lang.org/stable/std/mem/fn.discriminant.html#accessing-the-numeric-value-of-the-discriminant

https://doc.rust-lang.org/stable/std/mem/fn.discriminant.html Should be the thing to use here.

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

Successfully merging this pull request may close these issues.

Raw pointer casts in enum Ord impl can cause type inference failures
1 participant