Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for DSTs on #[pin_project(UnsafeUnpin)] #120

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> UnsafeUnpin for Wrapper<'_, T> where T: UnsafeUnpin {}
unsafe impl<T: ?Sized> 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<T>, PhantomData<&'a ()>);
pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData<T>);

impl<T: ?Sized> Unpin for AlwaysUnpin<'_, T> {}
}
20 changes: 20 additions & 0 deletions tests/unsafe_unpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ fn trivial_bounds() {
}
}

#[test]
fn dst() {
#[pin_project(UnsafeUnpin)]
pub struct A<T: ?Sized> {
x: T,
}

#[pin_project(UnsafeUnpin)]
pub struct B<T: ?Sized> {
#[pin]
x: T,
}

#[pin_project(UnsafeUnpin)]
pub struct C<T: ?Sized>(T);

#[pin_project(UnsafeUnpin)]
pub struct D<T: ?Sized>(#[pin] T);
}

#[test]
fn test() {
let mut x = OverlappingLifetimeNames { field1: 0, field2: 1, field3: &() };
Expand Down