rust-lang/rust-clippy

Detect creation of new collection when it could be emptied

Open

#16.520 aperta il 5 feb 2026

Vedi su GitHub
 (5 commenti) (0 reazioni) (1 assegnatario)Rust (1391 fork)batch import
A-lintgood first issue

Metriche repository

Star
 (10.406 star)
Metriche merge PR
 (Merge medio 16g 6h) (79 PR mergiate in 30 g)

Descrizione

Description

See https://github.com/uutils/coreutils/pull/10695

When a variable holding a collection (such as Vec/VecDeque/HashMap/BTreeMap) is replaced by a new empty instance, it can be more efficient to instead clear the existing one to be able to reuse the allocated memory.

For example, x = Vec::new() can be replaced by x.clear(): x will be an empty vector, except that the storage (and capacity) will be inherited from the previous instance.

Version

Additional Labels

No response

Guida contributor