Skip to content

lint suggestion: manual_clear #16615

@xtqqczze

Description

@xtqqczze

What it does

Checks for .truncate(0) calls on standard library types like Vec, VecDeque, String, and OsString where it can be replaced with .clear().

Advantage

clear() expresses the intent better and is likely to be more efficient than truncate(0).

Drawbacks

No response

Example

let mut v = vec![1, 2, 3];
v.truncate(0);

Could be written as:

let mut v = vec![1, 2, 3];
v.clear();

Comparison with existing lints

No response

Additional Context

rust-lang/rust@9c59d04

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions