| ▲ | jandrewrogers 10 hours ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||
> starting playing around with std::launder and std::byte and strict aliasing rules and lifetime rules, and you'll yearn for the simplicity of Rust Annotations like std::launder, lifetime manipulation, etc solve a class of problems that exist in every systems language. They inform the compiler of properties that cannot be known by analyzing the code. Rust isn't special in this regard, it has the same issues. Without these features, we either relied on unofficial compiler-specific behavior or used unnecessarily conservative code that was safe but slower. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | tialaramex 7 hours ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
> Rust isn't special in this regard, it has the same issues. This is both fundamentally true and misleading. Rust has to solve the same issues but isn't obliged to make all the same bad choices to do that and so the results are much better. For example C++ dare not perform compile time transmutations so, it just forbids them and a whole bunch of extra stuff landed to work around that, but in Rust they're actually fine and so you can just:
That blows up at compile time because we claimed the bit pattern for the integer 2 is a valid boolean and it isn't. If we choose instead 0 (or 1) this works and we get the expected false (or true) boolean instead of a compiler diagnostic.C++ could allow this but it doesn't, rather than figure out all the tricky edge cases they just said no, use this other new thing we made. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||