rust-lang / rust-lang/rust-clippy

Add lint for suggesting deriving given traits wherever they're missing and could be applied

Open
#16,136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What it does

Suggestion: Add a lint (let's call it suggest_derive) and configuration option (let's call it suggestable_derives). The user sets suggestable_derives to a list of derivable traits, and then whenever clippy finds a type that could derive one of those traits but doesn't, a warning is emitted.

Advantage

No response

Drawbacks
  • If Copy is included in suggestable_derives, care must be taken to not give conflicting advice with the copy_iterator lint.
Example

With the following config:

suggestable_derives = ["Clone", "Debug", "Eq", "PartialEq"]

This code:

#[derive(Debug)]
struct Foo {
    name: String,
    size: usize,
}

Could be written as:

#[derive(Clone, Debug, Eq, PartialEq)]
struct Foo {
    name: String,
    size: usize,
}
Comparison with existing lints

No response

Additional Context

No response

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.

Research direction

Start by reviewing the proposed suggest_derive lint and the suggestable_derives configuration described in this issue. Check how the requested traits, including Copy, should interact with the existing copy_iterator lint. Done means the configured derivable traits produce appropriate suggestions without conflicting advice.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.