Skip to content

New lint: Recommend using ptr::eq when possible#4596

Closed
tesuji wants to merge 1 commit into
rust-lang:masterfrom
tesuji:lint-ptr-eq
Closed

New lint: Recommend using ptr::eq when possible#4596
tesuji wants to merge 1 commit into
rust-lang:masterfrom
tesuji:lint-ptr-eq

Conversation

@tesuji

@tesuji tesuji commented Sep 28, 2019

Copy link
Copy Markdown
Contributor

changelog: Recommend using ptr::eq when possible

Closes #3661

@JohnTitor JohnTitor added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 28, 2019
@bors

bors commented Oct 8, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4592) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

bors commented Oct 9, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4615) made this pull request unmergeable. Please resolve the merge conflicts.

@tesuji

tesuji commented Oct 9, 2019

Copy link
Copy Markdown
Contributor Author

Network errors in mac builder.

@bors

bors commented Oct 14, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4560) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

bors commented Oct 18, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4683) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

bors commented Oct 18, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4657) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

bors commented Nov 7, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

bors commented Nov 23, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4839) made this pull request unmergeable. Please resolve the merge conflicts.

Comment thread tests/ui/ptr_eq.fixed
@flip1995 flip1995 added the A-lint Area: New lints label Nov 25, 2019
@tesuji tesuji closed this Nov 28, 2019
@tesuji tesuji reopened this Nov 28, 2019
LINT_MSG,
"try",
sugg,
Applicability::MachineApplicable,

Copy link
Copy Markdown
Member

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 MachineApplicableility? I'M asking because of the formulation of

static LINT_MSG: &str = "use `std::ptr::eq` when applicable";

Copy link
Copy Markdown
Contributor Author

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.

@phansch phansch left a comment

Copy link
Copy Markdown
Contributor

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 🙇‍♂️

Comment thread 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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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?

Comment thread clippy_lints/src/ptr_eq.rs Outdated
Comment thread clippy_lints/src/ptr_eq.rs Outdated
Comment thread clippy_lints/src/ptr_eq.rs Outdated
Comment thread clippy_lints/src/ptr_eq.rs Outdated
@phansch phansch added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 5, 2019
@bors

bors commented Dec 8, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4889) made this pull request unmergeable. Please resolve the merge conflicts.

@tesuji

tesuji commented Dec 8, 2019

Copy link
Copy Markdown
Contributor Author

Unfortunately, I don't think this lint is very useful.
cc @matthiaskrgr for #4596 (comment) ?

@phansch

phansch commented Dec 9, 2019

Copy link
Copy Markdown
Contributor

@lzutao I think this could still fit as a style lint, no?

@tesuji tesuji force-pushed the lint-ptr-eq branch 3 times, most recently from 6fc0670 to b5a9c82 Compare December 10, 2019 04:31
Co-Authored-By: Phil Hansch <dev@phansch.net>
@flip1995 flip1995 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 11, 2019
@bors

bors commented Dec 22, 2019

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #4930) made this pull request unmergeable. Please resolve the merge conflicts.

@tesuji

tesuji commented Dec 22, 2019

Copy link
Copy Markdown
Contributor Author

Closed as inactive.

@tesuji tesuji closed this Dec 22, 2019
@tesuji tesuji deleted the lint-ptr-eq branch December 22, 2019 10:13
@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 22, 2019
bors added a commit that referenced this pull request Oct 9, 2020
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
@hkalbasi

Copy link
Copy Markdown
Member

finished in #6130
@rustbot label -S-inactive-closed

@rustbot rustbot removed the S-inactive-closed Status: Closed due to inactivity label Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lint Area: New lints

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new lint: suggest ptr::eq() instead of "x as *const _ as usize == y as *const as usize"

7 participants