static CAST_REF_TO_MUT: &Lint
Expand description

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