rust-lang / rust-lang/rust-clippy

[lint request] unnecessary_sized_box_transmute

Open
#3,996 0 comments 0 reactions 0 assignees View on GitHub

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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.