1 #![warn(rust_2018_idioms, single_use_lifetimes)]
2 #![allow(dead_code)]
3 
4 use pin_project::{pin_project, UnsafeUnpin};
5 use std::{marker::PhantomPinned, pin::Pin};
6 
is_unpin<T: Unpin>()7 fn is_unpin<T: Unpin>() {}
8 
9 #[pin_project(UnsafeUnpin)]
10 pub struct Blah<T, U> {
11     field1: U,
12     #[pin]
13     field2: T,
14 }
15 
16 unsafe impl<T: Unpin, U> UnsafeUnpin for Blah<T, U> {}
17 
18 #[pin_project(UnsafeUnpin)]
19 pub struct OverlappingLifetimeNames<'pin, T, U> {
20     #[pin]
21     field1: T,
22     field2: U,
23     field3: &'pin (),
24 }
25 
26 unsafe impl<T: Unpin, U> UnsafeUnpin for OverlappingLifetimeNames<'_, T, U> {}
27 
28 #[test]
unsafe_unpin()29 fn unsafe_unpin() {
30     is_unpin::<Blah<(), PhantomPinned>>();
31     is_unpin::<OverlappingLifetimeNames<'_, (), ()>>();
32 }
33 
34 #[test]
trivial_bounds()35 fn trivial_bounds() {
36     #[pin_project(UnsafeUnpin)]
37     pub struct NotImplementUnsafUnpin {
38         #[pin]
39         field: PhantomPinned,
40     }
41 }
42 
43 #[test]
test()44 fn test() {
45     let mut x = OverlappingLifetimeNames { field1: 0, field2: 1, field3: &() };
46     let x = Pin::new(&mut x);
47     let y = x.as_ref().project_ref();
48     let _: Pin<&u8> = y.field1;
49     let _: &u8 = y.field2;
50     let y = x.project();
51     let _: Pin<&mut u8> = y.field1;
52     let _: &mut u8 = y.field2;
53 }
54