rust-lang / rust-lang/rust-clippy

Catch use of PhantomData that requires T: Sized

Open
#2,308 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue T-middle
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

In Serde the traits we implement for PhantomData should have worked for T: ?Sized, but as a bug they required T: Sized -- fixed in https://github.com/serde-rs/serde/commit/4751627f1cd14cacdf216188ccbb9ab0831e2b3f. Could Clippy have caught this? I struggle to think of any use of PhantomData<T> where T is an unconstrained type parameter where you would not want to allow ?Sized. As a starting point, maybe we could catch impls of the form:

impl<..., T, ...> Trait<...> for PhantomData<T> { /* ... */ }

where there are no trait bounds on T. In this case you pretty much always want T: ?Sized right?

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

Start by reading the Serde commit linked in the issue and the proposed impl pattern for PhantomData. Determine the intended cases for unconstrained T and define when Clippy should report them; the work is done when the lint reliably catches the described Sized requirement without flagging valid 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.