rust-lang/rust-clippy

Detect creation of new collection when it could be emptied

Aberta

#16.520 aberto em 5 de fev. de 2026

 (5 comentários) (0 reação) (1 responsável)Rust (1.391 forks)batch import
A-lintgood first issue

Métricas do repositório

Stars
 (10.406 estrelas)
Métricas de merge de PR
 (Mesclagem média 19d 22h) (113 fundiu PRs em 30d)

Description

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

Guia do colaborador