rust-lang / rust-lang/rust-clippy
Add lint for suggesting deriving given traits wherever they're missing and could be applied
Nobody has claimed this yet.
- 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
Copyis included insuggestable_derives, care must be taken to not give conflicting advice with thecopy_iteratorlint.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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