rust-lang / rust-lang/rust-clippy
[lint request] unnecessary_sized_box_transmute
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
People transmute raw pointers, or... references (yeah, really), into Box<T: Sized>s...
We should catch these, telling people to properly casts their pointers and/or references and to use Box::from_raw and Box::into_raw methods (note: we probably want a different lint for T: ?Sized since trait objects have a different layout, and right now there isn't really a stable way to do that, so this might not be worth warning for now).
If this happens inside a macro, I don't know if we should still warn. The only case in which this could ever be wrong is if Box<T, A: Alloc> is monomorphized with a stateful allocator (non-ZST), but the transmute should catch that because the size would differ, so... maybe if this happens inside a macro, we should just not lint it (who knows what else the macro might be transmuting).
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
No files, tests, or entry points are named in the issue. Start by resolving the proposed lint's scope, including T: Sized, macro expansion, and stateful allocators; done means raw-pointer or reference transmutes into Box<T> are diagnosed with guidance toward proper casts and Box::from_raw/Box::into_raw.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100