Rust

Rust

By DeepSource

Found manual implementation of std::ptr::null() RS-W1078

Anti-pattern
Autofix

Casting 0 as *const is the same as std::ptr::null(), which is more idiomatic and readable. Similarly 0 as *mut is same as std::ptr::null_mut().

Consider replacing std::ptr::null() with 0 as *const.

Bad practice

unsafe_function(0 as *const _);
let foo = 0 as *const u32;

unsafe_function_mut(0 as *mut _);
let bar = 0 as *mut u32;

Recommended

unsafe_function(std::ptr::null());
let foo = std::ptr::null::<u32>();

unsafe_function_mut(std::ptr::null_mut());
let bar = std::ptr::null_mut::<u32>();