Expand description

The writes_through_immutable_pointer lint detects writes through pointers derived from shared references.


const WRITE_AFTER_CAST: () = unsafe {
    let mut x = 0;
    let ptr = &x as *const i32 as *mut i32;
    *ptr = 0;



Shared references are immutable (when there is no UnsafeCell involved), and writing through them or through pointers derived from them is Undefined Behavior. The compiler recently learned to detect such Undefined Behavior during compile-time evaluation, and in the future this will raise a hard error.