rust-lang / rust-lang/rust-clippy
Lint suggestion: write to raw pointer with drop glue
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
One of the subtle aspects of *ptr = val where ptr is a raw pointer is that this will drop the old contents stored behind that pointer. On the one hand that might not be surprising because this is the same for mutable references, but on the other hand raw pointers are often used to point to invalid/uninitialized data, and then this is an easy way to cause a double-drop or to drop some garbage data. I have made this mistake myself and seen it a few times "out there".
So I think it'd be a good idea to lint against *ptr = val when ptr: *mut T and T has drop glue. The lint should recommend to use ptr.write(val) instead, which does not drop. Code that wants to drop should explicitly do ptr.drop_in_place().
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
The issue names no files, tests, or entry points. Start by locating Clippy's raw-pointer assignment lint infrastructure and its existing test patterns; done means assignments through raw pointers to types with drop glue are diagnosed, with suggestions to use write or drop_in_place as appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100