Skip to content

Commit

Permalink
Merge #120
Browse files Browse the repository at this point in the history
120: Fix support for DSTs on #[pin_project(UnsafeUnpin)] r=taiki-e a=taiki-e

Related: #113

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Oct 9, 2019
2 parents 317b335 + 415a5fb commit bea0ef8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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

0 comments on commit bea0ef8

Please sign in to comment.