Re:Understanding Rust futures by going way too deep
by Subsentient on Tuesday July 27, 2021 @12:31PM
(#27974368)
Yeah that's a whole nother can of worms for me with Rust, something that pisses me off a lot. By enforcing strict aliasing with no way to disable, Rust is making unsafe code intrinsically more unsafe, because you can't get predictable behavior. I'd rather it be called UB and work as intended anyways. But no, rustc devs in their infinite wisdom decided not to provide what is to me a core compiler flag.
Re:Understanding Rust futures by going way too deep
by nyanpasu64 on Tuesday July 27, 2021 @02:37PM
(#27975882)
> I'd rather it be called UB and work as intended anyways.
Personally I disagree. If you want to write freely aliasing code, I think it's better to use &UnsafeCell or &Cell or &RefCell, perhaps with an Arc (or my AliasPtr crate) instead of trying to convince rustc that &mut isn't exclusive.
Even though C++ code in the wild is filled with standard violations, I like having a standard explaining what rules exist, so developers can reason about them, and I can use them to tell other developers to change their code because their code is invalid. (In practice I don't know if violating strict aliasing through reinterpret_cast rather than bit_cast can lead to compilation errors, and sadly std::variant can miscompile due to broken aliasing optimizations in library code even with valid user code: https://www.reddit.com/r/cpp/comments/j7gn2d/stdvariant_is_b....) Currently, not all unsafe Rust can be classified as either valid (make sure the compiler doesn't break it) or invalid (change the code until it's valid), though there are some cases where unsafe Rust is clearly invalid.
Maybe it's a temporary state while the language team makes decisions based on how the unsafe library ecosystem progresses. Maybe the language team has no plans to put the language on a firm groundwork defining exactly what is legal or not, which I find uncomfortable (though maybe others feel more comfortable with it). In any case, there's not that much practical impact on the quality of code being written and binaries being produced, but it still hurts to see people building castles on uncertain foundations.