Re:What Color Is Your Monad
by steveklabnik on Wednesday February 16, 2022 @11:30AM
(#30362057)
I’m not even sure that captures it. You must not void the safety contract in unsafe Rust. The distinction is that with unsafe, you must manually uphold the safety contract.
Ah yes, you’re right that I missed that part. The contract isn’t voided by using unsafe, what changes is that responsibility of enforcing the contract is moved to the developer instead of the compiler.
Citing the documentation:
> To switch to unsafe Rust, use the unsafe keyword and then start a new block that holds the unsafe code. You can take five actions in unsafe Rust, called unsafe superpowers, that you can’t in safe Rust. [...]:
> - Dereference a raw pointer
> - Call an unsafe function or method
> - Access or modify a mutable static variable
> - Implement an unsafe trait
> - Access fields of unions
> It’s important to understand that unsafe doesn’t turn off the borrow checker or disable any other of Rust’s safety checks
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#unsa...