Static rustc_lint::builtin::DEREF_NULLPTR

source ·
pub static DEREF_NULLPTR: &Lint
Expand description

The deref_nullptr lint detects when an null pointer is dereferenced, which causes undefined behavior.

§Example

use std::ptr;
unsafe {
    let x = &*ptr::null::<i32>();
    let x = ptr::addr_of!(*ptr::null::<i32>());
    let x = *(0 as *const i32);
}

{{produces}}

§Explanation

Dereferencing a null pointer causes undefined behavior even as a place expression, like &*(0 as *const i32) or addr_of!(*(0 as *const i32)).