From d08fe97d12b41c1ed8cc7701e545864132783941 Mon Sep 17 00:00:00 2001 From: Phil Ruffwind Date: Thu, 23 Feb 2017 19:19:25 -0500 Subject: [PATCH] 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 T> does not actually enable drop checking. - PhantomData T> is neither variant nor contravariant. --- src/phantom-data.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/phantom-data.md b/src/phantom-data.md index 72fa2e2..32539c2 100644 --- a/src/phantom-data.md +++ b/src/phantom-data.md @@ -82,5 +82,23 @@ standard library made a utility for itself called `Unique` which: * wraps a `*const T` for variance * includes a `PhantomData` -* 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` | - | variant (with drop check) | +| `PhantomData<&'a T>` | variant | variant | +| `PhantomData<&'a mut T>` | variant | invariant | +| `PhantomData<*const T>` | - | variant | +| `PhantomData<*mut T>` | - | invariant | +| `PhantomData` | - | contravariant (*) | +| `PhantomData T>` | - | variant | +| `PhantomData T>` | - | invariant | +| `PhantomData>` | invariant | - | + +(*) If contravariance gets scrapped, this would be invariant.