diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-02-25 14:13:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-25 14:13:42 +0200 |
| commit | 49c8d58662a7fc5ac608cdc0f80a8bcc4c9ee790 (patch) | |
| tree | 0239dc40904c85fc5354a6cb173b7a36188c30ba | |
| parent | ecae5bf785f8f018f7dd5a991912f18d818d2317 (diff) | |
| parent | 1f75085ae510d0786da6200172e9b3193b0fa090 (diff) | |
Rollup merge of #40069 - Rufflewind:master, r=steveklabnik
Add Gankro's table to nomicon/src/phantom-data.md Original: https://github.com/rust-lang/rust/issues/30069#issuecomment-159928136 Testing confirms that: - `PhantomData<fn() -> T>` does not actually enable drop checking. - `PhantomData<fn(T) -> T>` is neither variant nor contravariant.
| -rw-r--r-- | src/doc/nomicon/src/phantom-data.md | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/doc/nomicon/src/phantom-data.md b/src/doc/nomicon/src/phantom-data.md index 72fa2e2a777..32539c2d01f 100644 --- a/src/doc/nomicon/src/phantom-data.md +++ b/src/doc/nomicon/src/phantom-data.md @@ -82,5 +82,23 @@ standard library made a utility for itself called `Unique<T>` which: * wraps a `*const T` for variance * includes a `PhantomData<T>` -* auto-derives Send/Sync as if T was contained -* marks the pointer as NonZero for the null-pointer optimization +* auto-derives `Send`/`Sync` as if T was contained +* marks the pointer as `NonZero` for the null-pointer optimization + +## Table of `PhantomData` patterns + +Here’s a table of all the wonderful ways `PhantomData` could be used: + +| Phantom type | `'a` | `T` | +|-----------------------------|-----------|---------------------------| +| `PhantomData<T>` | - | variant (with drop check) | +| `PhantomData<&'a T>` | variant | variant | +| `PhantomData<&'a mut T>` | variant | invariant | +| `PhantomData<*const T>` | - | variant | +| `PhantomData<*mut T>` | - | invariant | +| `PhantomData<fn(T)>` | - | contravariant (*) | +| `PhantomData<fn() -> T>` | - | variant | +| `PhantomData<fn(T) -> T>` | - | invariant | +| `PhantomData<Cell<&'a ()>>` | invariant | - | + +(*) If contravariance gets scrapped, this would be invariant. |
