Skip to content

new lint: vec.drain(..) instead of vec.clear() #9339

Closed
@philpax

Description

@philpax

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

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions