Hacker News new | ask | show | jobs
by afiori 22 days ago
I agree with your point, but for completeness:

> How is not having to mark your unsafe code as unsafe a good thing?

The problem with unsafe code in Rust is that IIRC nobody actually figured out yet the "rules" of unsafe i.e. which invariants you can stretch and which can cause UB. My (not super up to date) understanding is that this is an active area of research and progress is being made and also that in practice there are many well understood usages.

In short unsafe rust is somewhat worse than C++ as the boundaries of UB are less well understood/defined

1 comments

I don’t know what you’re referring to. Unsafe seems pretty well defined for 99% of use cases. Unsafe blocks allow you to dereference raw pointers and call unsafe functions. Thats about it. Remarkably, even in codebases which need a lot of unsafe (eg the kernel), almost all code is safe code.
What I mean is that unsafe code allows you to eg break std invariants (set invalid length to Vec, unlock a locked mutex, etc.) in ways that can be UB, which of these are UB and which can be used "safely" is sort of unknown.

For better or worse they are much more well understood in C as they are front and center of the language semantics