Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In normal safe code, the compiler ensures your code has no UB. In an unsafe block, the programmer ensures the code has no UB.

Safe abstractions are created out of unsafe operations by making sure it's impossible to violate the operations' preconditions. Either by checking at runtime and returning an error or aborting the program if they're violated, or by using the type system and borrow checker to verify them at compile time (writing the code such that any program that could violate the preconditions must have a type error.)

If Rust didn't have unsafe, the only way to access the underlying unsafe operations would be dropping down to C/C++/Assembly, or hardcoding them in the compiler. This is what other languages do, and it's ergonomically worse because the barrier to adding a whole new language and build system to your project is quite high.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: