-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clippy beta 1.87 lints all pointer comparisons, possibly too much? #14525
Comments
cc @samueltardieu @Manishearth My guess is that #14339 introduced this change, which is titled "lint more cases" but the ticket it closed seems to be a bug rather than a proposal to make this lint different. The PR also didn't update the motivation for "why is this bad" at all. In particular this expansion of the lint is going to hit code using raw pointers quite hard, e.g. we noticed this in Maybe this change of behaviour to more aggressively forbid For what it's worth, I'd argue against this change of behaviour. In my opinion (On the other hand, I can completely support the lint as it currently functions on stable to make comparison of references by pointer much clearer.) |
I think the change was intentional: there's a couple footguns in this area, and potentially more with provenance, so encouraging this style overall seems good. That said, perhaps we can make it not lint for simple cases where there is no casting and the types are both raw? @samueltardieu , what do you think cc @rust-lang/clippy on whether we should back this out, do a fix, or leave as is |
See https://github.com/PyO3/pyo3/pull/5032/files for what the difference looks like. Personally I find it a bit too churn-y. |
I'll do some experiments to see how less linting would look like. |
Generally we're careful about churning, but churn in and of itself isn't bad, especially with |
I don't find the churning bad either, but I also understand the rationale of wanting to compare two raw pointers with |
I agree with only linting if we can remove a cast |
If we should change something with this lint, please label the PR with |
To add a counter-argument, in the PyO3 thread it was pointed out to me that using I could accept that motivation for preferring |
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. Usingstd::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:
I expected to see this happen:
Lint ok
Instead, this happened:
Clippy suggests replacing
a == b
with a call tostd::ptr::eq
.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: