rust-lang/rust-clippy
在 GitHub 查看Detect creation of new collection when it could be emptied
Open
#16,520 创建于 2026年2月5日
A-lintgood first issue
仓库指标
- Star
- (10,406 star)
- PR 合并指标
- (平均合并 19天 22小时) (30 天内合并 113 个 PR)
描述
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