-
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
New lint: Recommend using ptr::eq
when possible
#4596
Conversation
☔ The latest upstream changes (presumably #4592) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4615) made this pull request unmergeable. Please resolve the merge conflicts. |
Network errors in mac builder. |
☔ The latest upstream changes (presumably #4560) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4683) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4657) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4839) made this pull request unmergeable. Please resolve the merge conflicts. |
LINT_MSG, | ||
"try", | ||
sugg, | ||
Applicability::MachineApplicable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How confident are you with the MachineApplicable
ility? I'M asking because of the formulation of
static LINT_MSG: &str = "use `std::ptr::eq` when applicable";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just added a macro check. But maybe there are more cases that I can't think of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just learning about raw pointers, as I've never really used FFI before. Apologies if it sounds a bit pedantic but I genuinely don't know most of this yet 🙇♂️
clippy_lints/src/ptr_eq.rs
Outdated
declare_clippy_lint! { | ||
/// **What it does:** Use `std::ptr::eq` when applicable | ||
/// | ||
/// **Why is this bad?** This can be used to compare `&T` references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's This
, the first word, meant to reference? ptr::eq
? If yes, I think it would read better as ptr::eq can be used to ...
/// | ||
/// **Why is this bad?** This can be used to compare `&T` references | ||
/// (which coerce to `*const T` implicitly) by their address rather than | ||
/// comparing the values they point to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there another benefit in using ptr::eq
, apart from being shorter?
☔ The latest upstream changes (presumably #4889) made this pull request unmergeable. Please resolve the merge conflicts. |
Unfortunately, I don't think this lint is very useful. |
@lzutao I think this could still fit as a style lint, no? |
6fc0670
to
b5a9c82
Compare
Co-Authored-By: Phil Hansch <[email protected]>
☔ The latest upstream changes (presumably #4930) made this pull request unmergeable. Please resolve the merge conflicts. |
Closed as inactive. |
New lint: Recommend using `ptr::eq` when possible This is based almost entirely on the code available in the previous PR #4596. I merely updated the code to make it compile. Fixes #3661. - [ ] I'm not sure about the lint name, but it was the one used in the original PR. - [X] Added passing UI tests (including committed `.stderr` file) - [X] `cargo test` passes locally - [X] Executed `cargo dev update_lints` - [X] Added lint documentation - [X] Run `cargo dev fmt` --- changelog: none
changelog: Recommend using
ptr::eq
when possibleCloses #3661