Skip to content

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

@estebank

Description

@estebank

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 {

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions