nrc / derive-new

derive simple constructor functions for Rust structs
MIT License
525 stars 35 forks source link

Suppress clippy's too many arguments from the generated ctor #13

Open Arnavion opened 7 years ago

Arnavion commented 7 years ago

If a struct has too many members, cargo clippy will complain that the ctor has too many parameters:

warning: this function has too many arguments (16/7), #[warn(too_many_arguments)] on by default
  --> src\search.rs:10:37
   |
10 | #[derive(Clone, Debug, Deserialize, new, getters)]
   |                                     ^^^
   |
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#too_many_arguments

Emitting a #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] on the ctor should do it, I think.

dtolnay commented 7 years ago

I don't agree with this. A function can have too many arguments whether it is handwritten or generated code. (Of course if it is only called from generated code, that is a different story.)

The lint is saying maybe you shouldn't put #[derive(new)] on a struct with that many members. If the user wants to ignore that lint, the allow(too_many_arguments) should go in their code not in derive-new.

Arnavion commented 7 years ago

That's fine, then the codegen will need to inherit the #[allow] from the original struct (which core Rust attributes do as well).