TedDriggs / darling

A Rust proc-macro attribute parser
MIT License
1.02k stars 66 forks source link

Emit unwrap_or_default when appropriate for default fields #292

Closed novafacing closed 4 months ago

novafacing commented 5 months ago

Clippy has recently started emitting error messages like:

warning: if let can be simplified with `.unwrap_or_default()`
  --> simics-macro/src/init/mod.rs:16:15
   |
16 |     #[darling(default)]
   |               ^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
help: replace it with
   |
16 ~     #[darling(default)]
17 +     /// The name of the module, used in the `MOD:NAME` expression
18 ~     pub name.unwrap_or_default())]

This PR just uses unwrap_or_default as Clippy wants and the error message goes away.

TedDriggs commented 5 months ago

@novafacing it appears that this change has broken one of the compile tests. I'm not thrilled with the change in the compiler diagnostic - maybe adding an #[allow(clippy::...)] is the better move?

novafacing commented 5 months ago

That works for me, I don't really like this diagnostic either. I updated the PR to just add that allow, if you're cool with that.

martin-g commented 4 months ago

Related to https://github.com/rust-lang/rust-clippy/issues/12643

TedDriggs commented 4 months ago

This is being superseded by #296, which puts the allow on the generated trait impl rather than trying to hunt down each place where it appears.