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

new lint: `vec.drain(..)` instead of `vec.clear()`

Open philpax opened this issue 1 year ago • 3 comments

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();

philpax avatar Aug 16 '22 02:08 philpax

@rustbot claim

carloosaf avatar Aug 18 '22 11:08 carloosaf

@rustbot claim

koka831 avatar Aug 22 '22 14:08 koka831

@rustbot claim

lana99 avatar Sep 07 '22 08:09 lana99

Hi @lana99, are you working on this or is this up for grabs?

czotomo avatar Oct 06 '22 21:10 czotomo

I’ve been busy but I will probably push code for the issue this weekend. @czotomo

lana99 avatar Oct 06 '22 23:10 lana99