rust-clippy
rust-clippy copied to clipboard
new lint: `vec.drain(..)` instead of `vec.clear()`
What it does
Checks for usage of vec.drain(..)
(iterator dropped immediately) which can be replaced with vec.clear()
Lint Name
unnecessary_vec_drain
Category
style
Advantage
- Makes intent clearer
- Marginally more efficient, especially in debug builds
Drawbacks
No response
Example
vec.drain(..);
Could be written as:
vec.clear();
@rustbot claim
@rustbot claim
@rustbot claim
Hi @lana99, are you working on this or is this up for grabs?
I’ve been busy but I will probably push code for the issue this weekend. @czotomo