Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
estebank opened this issue Aug 14, 2018 · 1 comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@estebank
Copy link
Contributor

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 {
@flip1995 flip1995 added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-suggestion Lint: Improving, adding or fixing lint suggestions labels Aug 14, 2018
@HMPerson1
Copy link
Contributor

It looks like #[derive(..)] attributes are removed duing macro expansion, so it seems that we'd have to keep track of the fact that there was another #[derive(..)] ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

3 participants