rust-lang / rust-lang/rust-clippy
Prevent "soft" memory leaks by suggesting to shrink
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Vecs, Strings, and other heap-allocated types, don't automatically shrink their capacity when the len() is small enough. This lint acts as a reminder to shrink whenever there's a call to remove
Lint Name
remove_without_shrink
Category
perf, restriction
Advantage
- reminds to free unused memory
- good for beginners and experienced devs alike, who are unaware of the lack of auto-shrink, or have too much cognitive load (respectively)
Drawbacks
- too many false positives, unless it's smarter (i.e. only triggering if multiple elements are removed at once)
Example
vector.remove(0);
Could be written as:
vector.remove(0);
vector.shrink_to_fit();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing existing Clippy lints for Vec and String removal and capacity handling. Define when remove_without_shrink should trigger, including how to avoid the false positives noted for single removals. Done means the lint behavior, applicability, and tests cover the agreed cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100