Skip to content

Conversation

@moses7054
Copy link

@moses7054 moses7054 commented Feb 6, 2026

This PR adds a new lint, unnecessary_dedup_by, which suggests using Vec::dedup_by_key instead of Vec::dedup_by,
when the comparison is equivalent to a simple key extraction.

The implementation is adapted from unnecessary_sort_by and copies the same helper logic.

changelog: [unnecessary_dedup_by]: add new lint

fixes #16481

@rustbot rustbot added needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Feb 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Lintcheck changes for a7f59a8

Lint Added Removed Changed
clippy::unnecessary_dedup_by 1 0 0

This comment will be updated if you push new changes

@ada4a
Copy link
Contributor

ada4a commented Feb 9, 2026

It's a bit concerning that the lint doesn't actually reuse the logic, but rather copy-pastes it...

But more generally, I think this would warrant creating a more general lint that looks at every instance of "x_by could be replaced with x_by_key" -- maybe call it needless_x_by or manual_by_key

@moses7054
Copy link
Author

moses7054 commented Feb 10, 2026

@ada4a yeah, my initial intent with the copy-paste was to keep the lint self-contained and avoid a hard dependency on unnecessary_sort_by, so that all logic related to this lint lives in one place.

I thought of extracting the common logic into a common utility and make a generic lint( as mentioned in the issue's description) but I am just starting to contribute to clippy 😅 so thought of keeping it simple and see what the maintainers say.
I am happy to modify the pr as required.

I changed the wording to "copy" in the pr description so that it will be more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New lint unnecessary_dedup_by

4 participants