Skip to content

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.

@matthewbayer
Copy link

@magiclen do you have a chance to look at this? Experiencing breaks from this bug.

@jpcorreia99
Copy link

+1 also experiencing bugs from this

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

3 participants