3 ms·
I've written lots of `forbid(unsafe_code)` in Rust; it depends on where in the stack you are and what you're doing. But as the adjacent commenter notes: having
by woodruffw 11mo ago
I've written lots of `forbid(unsafe_code)` in Rust; it depends on where in the stack you are and what you're doing.
But as the adjacent commenter notes: having unsafe is not inherently a problem. You need unsafe Rust to interact with C and C++, because they're not safe by construction. This is a good thing!
- informa23 11mo ago[flagged]
- woodruffw 11mo agoI think unsafe Rust is harder to write than C. However, that's because unsafe Rust makes you think about the invariants that you'd need to preserve in a correct C program, so it's no harder to write than correct C. In other words: unsafe Rust is harder, but only in an apples-and-oranges sense. If you compare it to the same diligence you'd need to exercise in writing safer C, it would be about the same.
- jackrabbit1997 11mo agoHow would you describe the aliasing requirements of C and Rust, and do you consider them the same, as well as equally difficult?
- woodruffw 11mo agoSafe Rust has more strict aliasing requirements than C, so to write sound unsafe Rust that interoperates with safe Rust you need to do more work than the equivalent C code would involve. But per above, this is the apples-and-oranges comparison: the equivalent C code will compile, but is statistically more likely to be incorrect. Moreover, it's going to be incorrect in a way that isn't localizable.