There are also some usages of `unsafe` for constructs (like linked lists) that the borrow-checker does not support. Those could theoretically be checked, but as far as I know a practical/pragmatic way of doing that has yet to be invented.
In a practical sense, in order to not have “unsafe” code, the language specification would have to contain a full formal specification of every aspect that it’s running on. The hardware, the system software you rely on, everything. That isn’t a good idea, so no language does it. And it doesn’t help you when new hardware comes out.
In a more formal sense, you run into things like Rice’s theorem.
This is a pretty weak argument. "Everyone else does it, so it's not wrong." If using this argument, Rust shouldn't even exist.
Rice's theorem seems handwavy in the real-world limitations of its restrictions. For the sake of argument, even Python is more memory-safe than unsafe Rust.
- Dereference a raw pointer
- Call an extern or unsafe function or method
- Access or modify a mutable static variable
- Implement an unsafe trait
- Access fields of C unions
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
In C the most basic advanced thing you do is LinkedList. In Rust implementing it with pointers is unsafe and splitting it into two parts is unsafe
Most safety critical projects today are written in C and C++, which have very little compile time checks for safety.
I find this debatable. Even if it were still true, such "whataboutism" is always a piss poor argument.
That most projects in these industries are in C and C++? What do you think they use instead?
Or that C and C++ include very little compile time safety checks? I could see one arguing with the specific phrasing around C++, and maybe giving it a bit more credit here, but it’s still objectively less than Rust has.
Ada is of course used here too, but we're talking about the lack of checks at the language level being a problem. My point is that it is not, with languages that have less checking than Rust being used for these sorts of things routinely.
Rust has never advertised itself as a panacea.
I agree that Rust is not the best language that can theoretically ever exist. I do disagree that it is possible to have a 100% compiler checked memory safe language. There will always exist some portion of these systems that need to be verified by hand. And that's okay. The goal here, and how other languages could improve upon what Rust does, is to do what Rust did to other languages: expand on what is expressible within the safe subset.
Rust may not, but random Rust programmers rave about it all the time as if it were a panacea.
> expand on what is expressible within the safe subset
I hope that Rust itself keeps going further in this direction. Even with the residual unsafe code, bounds could be implemented to limit the possible damage, and correct it as soon as feasible.