News for hackers. Stuff that matters.
Re:What Color Is Your Monad by steinuil on Wednesday February 16, 2022 @10:27AM (#30361173)
You can only dereference raw pointers from within an unsafe block so they're only useful inside unsafe blocks. IMO Unsafe Rust != Rust, unsafe is an extension to the language that is clearly separated from safe code, and using it essentially means voiding Rust's safety contract.
Re:What Color Is Your Monad by dgellow on Wednesday February 16, 2022 @10:54AM (#30361614)
Not that you're incorrect but to be even more precise, and for the readers who do not know about Rust, I would say "voiding *parts* of Rust's safety contract".

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...

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.
Re:What Color Is Your Monad by dgellow on Wednesday February 16, 2022 @02:22PM (#30364493)
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.