Definitely looks unsafe
to me.
Programmer Humor
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
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
If you think that's good, then you're gonna love this "simplified" real code posted as a real issue on one of my Github repos.
Edit: updated link to address the stack-trace comment
That's not actual code though, it looks like some kind of trace. Notice the filenames at the end of each line.
The actual solution the issue opener there might be looking for is to disable C++ parsing, since it's not actually C++ code, it's just some text they pasted into VSCode and they're wondering why their editor can't handle it.
Without thinking about it much, my understanding was that each line of the stack trace referred to a real line, even though the block as a whole wasn't a program.
But! because of this comment I went and checked the lines of those stack traces. And in fact, they're not real lines, just the C++ type expansion.
That said I've got a another half as bad example that is real so Ive edited the comment to point to that example instead.
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)
.
Nah these are the actual integer representations. Otherwise you would have Some(None) == Some(Some(None))
which is way too Javascripty for Rust folks.
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 Some
s containing a None
is 0 and the full 8 Some
s is represented by 1
.
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.
Peano arithmetic moment
Is that a Peano Axioms reference ?
https://en.wikipedia.org/wiki/Natural_number#Peano_axioms
It's somehow inverted. If it was Peano, two would be represented by two Somes, not by six. I have no idea how this one works.