this post was submitted on 15 Nov 2023
226 points (97.5% liked)

Programmer Humor

18970 readers
393 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 12 points 9 months ago (1 children)

Since all of the expressions just wrap a None, I wouldn't be surprised if the transmutes basically get compiled to 0, making the assertion at the end assert_eq!(0 * 0, 0).

[–] [email protected] 9 points 9 months ago* (last edited 9 months ago) (1 children)

Nah these are the actual integer representations. Otherwise you would have Some(None) == Some(Some(None)) which is way too Javascripty for Rust folks.

[–] [email protected] 2 points 9 months ago (1 children)

That's kind of wild, I double-checked and it's true.

Although I disagree with the second part, the Rust folks wouldn't care about the in-memory representation as long as the compilation is on point.

Looking closer at the final enum, I guess it's because there are nine possible cases for it, making the compiler pack it into 4 bits, with one number representing each? I checked and None is represented as 8, while 7 Somes containing a None is 0 and the full 8 Somes is represented by 1.

[–] [email protected] 6 points 9 months ago

the Rust folks wouldn’t care about the in-memory representation as long as the compilation is on point.

Well I can't speak for everyone, but Rust is very intentional about supporting things like repr(C). At least some of us care a lot.