News for hackers. Stuff that matters.
Re:The Value of Undefined Behavior by arcticbull on Saturday July 21, 2018 @03:14PM (#17583351)
Definitely, but at least when you see unsafe {} you know all bets are off instead of having to assume all bets are off all the time. I do see what you mean though. The transmute thing is pretty funny imo.
Re:The Value of Undefined Behavior by cwzwarich on Saturday July 21, 2018 @03:38PM (#17583464)
Since any Rust function may use unsafe code, you don't know whether bets are off for any particular function call.
Re:The Value of Undefined Behavior by kibwen on Saturday July 21, 2018 @04:02PM (#17583577)
Any public API using `unsafe` code that can't enforce its own unsafe invariants should (and in practice does) get marked as `unsafe` itself in order to force callers to use `unsafe` when calling that function. Of course it's something that, by definition, the compiler cannot enforce on its own and hence requires social norms and social pressure to enforce, and it's therefore fortunate that the Rust community takes it very seriously.
Re:The Value of Undefined Behavior by dbaupp on Saturday July 21, 2018 @10:57PM (#17585059)
Any Python function may use ctypes, any Haskell function may use unsafePerformIO, ..., so all bets are off all the time.

I don't think that's a particularly useful point, as is.

Re:The Value of Undefined Behavior by lomnakkus on Sunday July 22, 2018 @02:56AM (#17585591)
Not that this "makes the point", necessarily, but GHC Haskell does have the whole Safe/Unsafe Haskell module inference/guarantee, so it may be a bit easier to avoid unexpectedly unsafe behavior entirely.

I have no idea whether any equivalent exists for Rust.

Re:The Value of Undefined Behavior by dbaupp on Sunday July 22, 2018 @09:34PM (#17589910)
There's not a module-level Safe/Trustworthy/Unsafe division, but as steveklabnik1 says, any potentially-dangerous code has to be placed into an `unsafe` block.

One can also forbid the use of any `unsafe` blocks for a crate/module (with the #[forbid(unsafe_code)] attribute), but this is slightly different to the {-# LANGUAGE Safe #-} pragma in that it does consider imports at all. However, since "unsafety" is modeled in the language in Rust, and is granular, people are encouraged to have every module be "Trustworthy" (in Safe Haskell terms): if an individual function could cause undefined behaviour if misused, it should be marked "unsafe", and a "Safe" module (i.e. one using the forbid above) won't be able to use it.

Re:The Value of Undefined Behavior by steveklabnik on Sunday July 22, 2018 @04:09AM (#17585787)
Rust requires you to to explicitly mark individual blocks of code as unsafe, and you can only do unsafe operations inside of them.
Re:The Value of Undefined Behavior by Retra on Saturday July 21, 2018 @06:42PM (#17584238)
Yeah, in theory. In practice, if someone writes code that is throwing away compiler checks for no reason, you simply don't use it.
Re:The Value of Undefined Behavior by paulddraper on Saturday July 21, 2018 @09:01PM (#17584708)
But very many pieces of code, even such pedestrian things as data structures require unsafe code.

So the attitude of "only unsafe programs have UB by the Rust spec" effectively means "all programs have UB by the Rust spec"