slow_vector_initialization
should recommend removing Vec::resize()
calls in addition to adding the size to the macro
#13781
Labels
C-bug
Category: Clippy is not doing the correct thing
Summary
slow_vector_initialization
is very useful, but its suggestion when handling an emptyvec![]
followed by a call toVec::resize()
does not recommend removing the call toVec::resize()
. This oversight will typically be caught in code review but when fixing many places the lint is triggered it might be missed.When missed, the resize call will typically not be a very big hit to performance because it won't allocate, but there are some cases where the suggestion guides users to copy a complicated expression from resize to the macro invocation. One hopes that the optimizer would be able to deduplicate the resulting calls but they might have side effects or be missed when optimizing for other reasons.
Reproducer
I tried this code:
I expected to see this happen: a suggestion that replaces the
vec![]
call withvec![0; 10]
and suggests removing the call tov.resize(10, 0);
Instead, this happened:
playground
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: