rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

add lint for recreation of an entire struct

Open phi-gamma opened this issue 3 months ago • 7 comments

This lint makes Clippy warn about situations where an owned struct is essentially recreated by moving all its fields into a new instance of the struct. The lint is not machine-applicable because the source struct may have been partially moved.

This lint originated in something I spotted during peer review. While working on their branch a colleague ended up with a commit where a function returned a struct that 1:1 replicated one of its owned inputs from its members. Initially I suspected they hadn’t run their code through Clippy but AFAICS there is no lint for this situation yet.

changelog: new lint: [redundant_owned_struct_recreation]

New lint checklist

  • [+] Followed [lint naming conventions][lint_naming]
  • [+] Added passing UI tests (including committed .stderr file)
  • [+] cargo test passes locally
  • [+] Executed cargo dev update_lints
  • [+] Added lint documentation
  • [+] Run cargo dev fmt

phi-gamma avatar May 07 '24 08:05 phi-gamma