Skip to content

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

@jwodder

Description

@jwodder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions