r/programming • • Jan 17 '20

A sad day for Rust

https://words.steveklabnik.com/a-sad-day-for-rust
1.1k Upvotes

609 comments sorted by

View all comments

Show parent comments

10

u/[deleted] Jan 18 '20

To my understanding of the controversy, people are angry not so much because of the "unsafe" code itself, but because the maintainer blew off the issue and refused to accept the patch because it wasn't "creative" or whatever. Imagine the uproar that would ensue if Linus refused to accept a security fix because he didn't think the code was clever or artistic enough.

0

u/[deleted] Jan 18 '20

[deleted]

8

u/[deleted] Jan 18 '20

The problem is not the unsafe keyword itself, but that the code in question could trigger undefined behavior. Rust just so happens to explicitly separate safe and so-called "unsafe" code, but the unsafe keyword is a red herring distracting from the underlying issue, the code's correctness. Whether you are programming in Rust or not, you should avoid triggering undefined behavior.

The intended meaning of "unsafe" in Rust is to say that even though the compiler cannot guarantee the code's safety, the programmer has made sure that it is safe. Whether or not a language has an "unsafe block" feature, people should not be writing unsafe code.

0

u/[deleted] Jan 18 '20

[deleted]

8

u/scottmcmrust Jan 18 '20

Multiple mutable references could trigger undefined behavior.

That's not correct. Have two independent ones concurrently is undefined behaviour.

One of the advantages of Rust over C++ is that rule allows rust to tell LLVM more about the actual aliasing in the program than C++ can. But because it does that, there are extra restrictions on things with validity requirements like &mut. That's why things like https://github.com/rust-lang/rfcs/pull/2582 exist: even creating one that you don't use can be unsound.

unsafe's existence is an acknowledgement that there are things that the compiler cannot prove correct which are correct. But once some code is demonstrated incorrect...