static INVALID_REFERENCE_CASTING: &Lint
Expand description

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

Example

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

{{produces}}

Explanation

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.