diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2017-10-07 21:33:36 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2017-10-08 01:09:55 +0200 |
| commit | 3fff2d95bf90514e66892ca9be666c35eeae9165 (patch) | |
| tree | 51c40561542c0e085dea45a93c5198eb2fe9f3ef /src/libcore | |
| parent | 2146c613d12de8dc44bc26e50af55251fc7e4f9c (diff) | |
| download | rust-3fff2d95bf90514e66892ca9be666c35eeae9165.tar.gz rust-3fff2d95bf90514e66892ca9be666c35eeae9165.zip | |
core: Ensure std::mem::Discriminant is Send + Sync
`PhantomData<*const T>` has the implication of Send / Syncness following the *const T type, but the discriminant should always be Send and Sync. Use `PhantomData<fn() -> T>` which has the same variance in T, but is Send + Sync
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/mem.rs | 2 | ||||
| -rw-r--r-- | src/libcore/tests/mem.rs | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index e085d427b8c..680a0f5b2c0 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -836,7 +836,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U { /// /// See the `discriminant` function in this module for more information. #[stable(feature = "discriminant_value", since = "1.21.0")] -pub struct Discriminant<T>(u64, PhantomData<*const T>); +pub struct Discriminant<T>(u64, PhantomData<fn() -> T>); // N.B. These trait implementations cannot be derived because we don't want any bounds on T. diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index 86e59c736ba..f55a1c81463 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -121,3 +121,19 @@ fn test_transmute() { } } +#[test] +#[allow(dead_code)] +fn test_discriminant_send_sync() { + enum Regular { + A, + B(i32) + } + enum NotSendSync { + A(*const i32) + } + + fn is_send_sync<T: Send + Sync>() { } + + is_send_sync::<Discriminant<Regular>>(); + is_send_sync::<Discriminant<NotSendSync>>(); +} |
