3 ms·
> UB Undefined behavior? As in, you can confine it to `unsafe`?
by monoideism 5y ago
> UB
Undefined behavior? As in, you can confine it to `unsafe`?
- tialaramex 5y agoUnsafe Code isn't allowed to have Undefined Behaviour either. What unsafe does, is it says to the compiler: "Hey, I know you're just a dumb machine, and you couldn't prove this code obeys all the rules that keep Rust safe, but I am very smart and I promise it actually is safe". You're also encouraged to explain yourself (to other humans, not the compiler, this isn't Wuffs) so that anybody else maintaining the code can see why exactly you believed this was OK. Over the years, some code which was once unsafe in Rust no longer needed an unsafe block, because Rust's compiler got smarter, "Oh, I see why this is OK". But if your unsafe code has Undefined Behaviour that's actually a serious bug, it's not what unsafe is for at all.
- monoideism 5y agoThat's what I thought, or at least suspected, so not sure why "UB" was listed as a Rust selling point.
- tialaramex 5y agoI am not the poster in question, but I assume that they meant Rust avoids Undefined Behaviour and this is indeed a notable selling point, compared to low-level languages.