Lint for fold
closure that never moves the accumulator
#6053
Labels
A-lint
Area: New lints
good-first-issue
These issues are a good way to get started with Clippy
L-perf
Lint: Belongs in the perf lint group
What it does
Lint when a
fold
closure always returns the accumulator from the input, having only used it by reference. (As opposed to consuming the accumulator, or returning something else.)Categories (optional)
perf
The compiler currently cannot always optimize away passing along the accumulator every time (see rust-lang/rust#76725), so it's better to not do that if it's actually the same thing every time anyway.
Drawbacks
None.
(Well, it leaves something
mut
, but that's easily fixable withlet v = v;
.)Example
Could be written as:
The text was updated successfully, but these errors were encountered: