Unsound: unsafe { &mut *(&1 as *const _ as *mut _) }
Edit: Importantly, the non-unsafe example I posted also calls a bunch of unsafe code, as is necessary to do anything nontrivial (see https://github.com/rust-lang/rust/blob/master/library/std/sr...). My point is that safe-good unsafe-bad is the wrong way to think about things. This is why you see experts on this (which I'm absolutely not) refer to unsafe code that violates the Rust Memory Model™ as unsound. (You may also find the fact the Rust Memory Model is more of a vibe than a standard surprising. How do you write sound code then? Try reasonable things and hope the compiler agrees with your definition of reasonable).
Re:Cryptographically verifiable code review system for cargo...
by iudqnolq on Friday April 09, 2021 @01:00PM
(#26752994)
I got it from your depiction of the actix kerfuffle. Maybe you didn't mean it, but all the original people involved who said similar things had very simplistic views of unsafe.
Unsafe: unsafe { 1 + 1 }
Unsound: unsafe { &mut *(&1 as *const _ as *mut _) }
Edit: Importantly, the non-unsafe example I posted also calls a bunch of unsafe code, as is necessary to do anything nontrivial (see https://github.com/rust-lang/rust/blob/master/library/std/sr...). My point is that safe-good unsafe-bad is the wrong way to think about things. This is why you see experts on this (which I'm absolutely not) refer to unsafe code that violates the Rust Memory Model™ as unsound. (You may also find the fact the Rust Memory Model is more of a vibe than a standard surprising. How do you write sound code then? Try reasonable things and hope the compiler agrees with your definition of reasonable).