From 415a5fb9302a7019c233acf982607f3104a911e1 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 10 Oct 2019 07:12:17 +0900 Subject: [PATCH] Fix support for DSTs on #[pin_project(UnsafeUnpin)] --- src/lib.rs | 6 +++--- tests/unsafe_unpin.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 736b06b0..20e40f0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -194,16 +194,16 @@ pub mod __private { // to making the type never implement Unpin), or provide an impl of `UnsafeUnpin`. // It is impossible for them to provide an impl of `Unpin` #[doc(hidden)] - pub struct Wrapper<'a, T>(T, PhantomData<&'a ()>); + pub struct Wrapper<'a, T: ?Sized>(PhantomData<&'a ()>, T); #[allow(unsafe_code)] - unsafe impl UnsafeUnpin for Wrapper<'_, T> where T: UnsafeUnpin {} + unsafe impl UnsafeUnpin for Wrapper<'_, T> where T: UnsafeUnpin {} // This is an internal helper struct used by `pin-project-internal`. // // See https://github.com/taiki-e/pin-project/pull/53 for more details. #[doc(hidden)] - pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData, PhantomData<&'a ()>); + pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData); impl Unpin for AlwaysUnpin<'_, T> {} } diff --git a/tests/unsafe_unpin.rs b/tests/unsafe_unpin.rs index caa17d24..74c46c92 100644 --- a/tests/unsafe_unpin.rs +++ b/tests/unsafe_unpin.rs @@ -43,6 +43,26 @@ fn trivial_bounds() { } } +#[test] +fn dst() { + #[pin_project(UnsafeUnpin)] + pub struct A { + x: T, + } + + #[pin_project(UnsafeUnpin)] + pub struct B { + #[pin] + x: T, + } + + #[pin_project(UnsafeUnpin)] + pub struct C(T); + + #[pin_project(UnsafeUnpin)] + pub struct D(#[pin] T); +} + #[test] fn test() { let mut x = OverlappingLifetimeNames { field1: 0, field2: 1, field3: &() };