Skip to content

Commit 49c8d58

Browse files
authored
Rollup merge of rust-lang#40069 - Rufflewind:master, r=steveklabnik
Add Gankro's table to nomicon/src/phantom-data.md Original: rust-lang#30069 (comment) Testing confirms that: - `PhantomData<fn() -> T>` does not actually enable drop checking. - `PhantomData<fn(T) -> T>` is neither variant nor contravariant.
2 parents ecae5bf + 1f75085 commit 49c8d58

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/doc/nomicon/src/phantom-data.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,23 @@ standard library made a utility for itself called `Unique<T>` which:
8282

8383
* wraps a `*const T` for variance
8484
* includes a `PhantomData<T>`
85-
* auto-derives Send/Sync as if T was contained
86-
* marks the pointer as NonZero for the null-pointer optimization
85+
* auto-derives `Send`/`Sync` as if T was contained
86+
* marks the pointer as `NonZero` for the null-pointer optimization
87+
88+
## Table of `PhantomData` patterns
89+
90+
Here’s a table of all the wonderful ways `PhantomData` could be used:
91+
92+
| Phantom type | `'a` | `T` |
93+
|-----------------------------|-----------|---------------------------|
94+
| `PhantomData<T>` | - | variant (with drop check) |
95+
| `PhantomData<&'a T>` | variant | variant |
96+
| `PhantomData<&'a mut T>` | variant | invariant |
97+
| `PhantomData<*const T>` | - | variant |
98+
| `PhantomData<*mut T>` | - | invariant |
99+
| `PhantomData<fn(T)>` | - | contravariant (*) |
100+
| `PhantomData<fn() -> T>` | - | variant |
101+
| `PhantomData<fn(T) -> T>` | - | invariant |
102+
| `PhantomData<Cell<&'a ()>>` | invariant | - |
103+
104+
(*) If contravariance gets scrapped, this would be invariant.

0 commit comments

Comments
 (0)