rust-lang / rust-lang/rust-clippy

New lint unnecessary_dedup_by

Open
#16,481 1 comment 0 reactions 1 assignee View on GitHub

@moses7054 is already working on this.

Since Jan 29, 2026.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Like unnecessary_sort_by but for Vec::dedup_by instead of Vec::sort_by.

This lint detects cases where dedup_by is used with a comparison that is equivalent to a simple key extraction and could be written more idiomatically using dedup_by_key.

Example
pub fn m1(mut v: Vec<(i64, i64)>) -> Vec<(i64, i64)> {
    v.dedup_by(|(sym1, _), (sym2, _)| sym1 == sym2);
    v
}

Could be written as:

pub fn m2(mut v: Vec<(i64, i64)>) -> Vec<(i64, i64)> {
    v.dedup_by_key(|(sym, _)| *sym);
    v
}
Alternatives

This functionality could instead be folded into unnecessary_sort_by, with the lint renamed or generalized to cover both sorting and deduplication cases.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.