clippy beta 1.87 lints all pointer comparisons, possibly too much? · Issue #14525 · rust-lang/rust-clippy (original) (raw)
Summary
As of clippy beta 1.87 the ptr_eq
lint seems to be forbidding all pointer equality.
I think this seems like a regression, as far as I can tell the ptr_eq
lint is intended to help in cases where &T
references are being cast to pointers and then compared. Using std::ptr::eq
can coerce those references and conveys intention cleanly.
On the other hand, if you already have pointers, calling std::ptr::eq
doesn't seem necessary to me?
Reproducer
I tried this code:
pub fn foo() -> bool { let a: *const i32 = std::ptr::null(); let b: *const i32 = std::ptr::null();
a == b
}
I expected to see this happen:
Lint ok
Instead, this happened:
Clippy suggests replacing a == b
with a call to std::ptr::eq
.
Version
0.1.87 (2025-04-01 45165c82a4)
Additional Labels
No response