rust-lang / rust-lang/rust-clippy

When `derive` is already applied to struct, suggest extending it, not replacing it

Open
#3,053 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement L-suggestion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

The following suggestion to add derive(Debug) does not take into consideration that line 170 already has another derive. It should suggest extending the existing derive instead of a new line:

warning: you should consider deriving a `Default` implementation for `policy::Attributes`
   -->
    |
176 | /   pub fn new() -> Attributes {
177 | |     Attributes {
178 | |       map: HashMap::new(),
179 | |     }
180 | |   }
    | |___^
    |
    = note: #[warn(new_without_default_derive)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#new_without_default_derive
help: try this
    |
170 | #[derive(Default)]
    |

Which when applying leads to having the following code:

169 | #[derive(Debug)]
170 | #[derive(Default)]
171 | struct Attributes {

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 locating the new_without_default_derive lint and the code that builds its help suggestion. Check how an existing #[derive(...)] is represented and find the related suggestion tests, if present. Done means the suggestion extends an existing derive instead of adding a separate derive attribute.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.