Expand description

The invalid_reference_casting lint checks for casts of &T to &mut T without using interior mutability.


fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;



Casting &T to &mut T without using interior mutability is undefined behavior, as it’s a violation of Rust reference aliasing requirements.

UnsafeCell is the only way to obtain aliasable data that is considered mutable.