Re:Things you can’t do in Rust (and what to do instead)
by tialaramex on Saturday May 15, 2021 @12:26PM
(#27166589)
Unsafe 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.
Re:Things you can’t do in Rust (and what to do instead)
by monoideism on Sunday May 16, 2021 @09:27PM
(#27179119)
That's what I thought, or at least suspected, so not sure why "UB" was listed as a Rust selling point.
Re:Things you can’t do in Rust (and what to do instead)
by tialaramex on Sunday May 16, 2021 @10:47PM
(#27179609)
I 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.
Undefined behavior? As in, you can confine it to `unsafe`?