Closed
Description
Summary
the cmp_null
autofix doesn't take into account the type of comparison, and instead always replaces the statement with a positive comparison on is_null()
.
Reproducer
I tried this code:
fn f(x: *mut i32) {
if x != std::ptr::null_mut() {
unsafe {
*x += 1;
}
}
}
I expected to see this happen:
fn f(x: *mut i32) {
if !x.is_null() {
unsafe {
*x += 1;
}
}
}
Instead, this happened:
fn f(x: *mut i32) {
if x.is_null() {
unsafe {
*x += 1;
}
}
}
Version
clippy 0.1.87 (17067e9ac6 2025-05-09)
Additional Labels
No response