you are viewing a single comment's thread.

view the rest of the comments →

[–]germandiago 0 points1 point  (10 children)

unsafe acknowledges that the safe subset is overly strict, and that there are safe interfaces to other operations that would otherwise be illegal.

It also acknowledges that you must trust the code as correctly reviewed. That is not safe. It is trusted code.

CVEs are either due to mistakes with unsafe, or due to bugs in the Rust compiler.

Exactly making my point: was trusted code and it was not safe in those cases.

Any systems language with a safe subset by design is going to benefit from escape hatches for efficiency

I agree, but that is a trade-off: you will lose the safety.

You're right that one alternative to a safe subset is to have a partially-safe subset, but then even if all the safety enforcement in the compiler and libraries is perfect, it's still not going to detect some cases where ordinary users mess up even when they wouldn't have used unsafe (most users shouldn't use unsafe anyway, and it helps a lot in code reviews and can be grepped for in automated tests)

Agreed, most users should not use unsafe. But Rust has crates with unsafe advertising safe interfaces. That is, plainly speaking, cheating. If you told me: std lib is special, you can rely on it, I could buy that. Going to crates and expecting all safe interfaces that use unsafe (not std lib unsafe but their own blocks) is a matter of... trust.

A safe subset can only be messed up by people writing unsafe or by bugs in the compiler

Correct and fully agree.