rust-lang / rust-lang/rust-clippy
Lint suggestion: `assume_init_mut` passed to `drop_in_place`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Since I found a few of these while working on rust-lang/rust#129259, this feels like a decent lint.
Assuming that this will be worked on after that PR is merged, it should detect both MaybeUninit::assume_init_mut and <[MaybeUninit<_>]>::assume_init_mut.
Advantage
- Removes need to import
drop_in_placein many cases - Fewer method calls = better codegen
- Probably easier to read due to being shorter
Drawbacks
It could be difficult to detect all cases, e.g. binding the assume_init_mut value to a variable and then calling drop_in_place.
Example
Essentially, it would look for calls of the form:
ptr::drop_in_place(x.assume_init_mut())
and replace them with:
x.assume_init_drop()
We probably also want to cover the simple case of:
let y = x.assume_init_mut();
ptr::drop_in_place(y);
And… well, if y is used after that, this would be UB anyway, so, I'm going to assume that it's okay to replace this with:
x.assume_init_drop()
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 locating Clippy's lint implementation and tests for MaybeUninit-related patterns, then compare how direct and variable-based calls are analyzed. Done means detecting the proposed drop_in_place forms for both assume_init_mut variants and suggesting assume_init_drop where the replacement is valid.
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
- Mostly clear
- Newbie friendliness
- 45/100