• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![warn(rust_2018_idioms, single_use_lifetimes)]
2 #![allow(dead_code)]
3 
4 #[macro_use]
5 mod auxiliary;
6 
7 use std::marker::PhantomPinned;
8 
9 use pin_project::{pin_project, UnsafeUnpin};
10 
11 #[pin_project(UnsafeUnpin)]
12 pub struct Blah<T, U> {
13     f1: U,
14     #[pin]
15     f2: T,
16 }
17 
18 unsafe impl<T: Unpin, U> UnsafeUnpin for Blah<T, U> {}
19 
20 assert_unpin!(Blah<(), ()>);
21 assert_unpin!(Blah<(), PhantomPinned>);
22 assert_not_unpin!(Blah<PhantomPinned, ()>);
23 assert_not_unpin!(Blah<PhantomPinned, PhantomPinned>);
24 
25 #[pin_project(UnsafeUnpin)]
26 struct OverlappingLifetimeNames<'pin, T, U> {
27     #[pin]
28     f1: U,
29     #[pin]
30     f2: Option<T>,
31     f3: &'pin (),
32 }
33 
34 unsafe impl<T: Unpin, U: Unpin> UnsafeUnpin for OverlappingLifetimeNames<'_, T, U> {}
35 
36 assert_unpin!(OverlappingLifetimeNames<'_, (), ()>);
37 assert_not_unpin!(OverlappingLifetimeNames<'_, PhantomPinned, ()>);
38 assert_not_unpin!(OverlappingLifetimeNames<'_, (), PhantomPinned>);
39 assert_not_unpin!(OverlappingLifetimeNames<'_, PhantomPinned, PhantomPinned>);
40 
41 #[test]
trivial_bounds()42 fn trivial_bounds() {
43     #[pin_project(UnsafeUnpin)]
44     pub struct NotImplementUnsafUnpin {
45         #[pin]
46         f: PhantomPinned,
47     }
48 
49     assert_not_unpin!(NotImplementUnsafUnpin);
50 }
51