rust-lang / rust-lang/rust-clippy
`unused_phantomdata`
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
I just wrote this odd code in a test:
use std::marker::PhantomData;
#[repr(transparent)]
struct H<T> {
h: Box<Option<T>>,
_m: (),
__m: PhantomData<T>,
}
I think if the type parameter is used elsewhere, or the lifetime, there should be a lint suggesting to remove it (the PhantomData).
Not sure if there are any cases where this is necessary, though. This section in the docs is a bit worrying: https://doc.rust-lang.org/nightly/std/marker/struct.PhantomData.html#ownership-and-the-drop-check
Advantage
- Removes an unnecessary
PhantomDatasince it already owns/uses the type parameter/lifetime
Drawbacks
No response
Example
use std::marker::PhantomData;
#[repr(transparent)]
struct H<T> {
h: Box<Option<T>>,
_m: (),
__m: PhantomData<T>,
}
Could be written as:
use std::marker::PhantomData;
#[repr(transparent)]
struct H<T> {
h: Box<Option<T>>,
_m: (),
}
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 studying the example and the linked PhantomData ownership and drop-check documentation; done means establishing when PhantomData is unnecessary and defining a lint that suggests its removal without affecting required semantics.
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