1#![warn(rust_2018_idioms, single_use_lifetimes)]
2#![allow(dead_code)]
3
4#[macro_use]
5mod auxiliary;
6
7pub mod default {
8 use std::marker::PhantomPinned;
9
10 use pin_project::pin_project;
11
12 struct Inner<T> {
13 f: T,
14 }
15
16 assert_unpin!(Inner<()>);
17 assert_not_unpin!(Inner<PhantomPinned>);
18
19 #[pin_project]
20 struct Struct<T, U> {
21 #[pin]
22 f1: Inner<T>,
23 f2: U,
24 }
25
26 assert_unpin!(Struct<(), ()>);
27 assert_unpin!(Struct<(), PhantomPinned>);
28 assert_not_unpin!(Struct<PhantomPinned, ()>);
29 assert_not_unpin!(Struct<PhantomPinned, PhantomPinned>);
30
31 #[pin_project(project = EnumProj, project_ref = EnumProjRef)]
32 enum Enum<T, U> {
33 V1 {
34 #[pin]
35 f1: Inner<T>,
36 f2: U,
37 },
38 }
39
40 assert_unpin!(Enum<(), ()>);
41 assert_unpin!(Enum<(), PhantomPinned>);
42 assert_not_unpin!(Enum<PhantomPinned, ()>);
43 assert_not_unpin!(Enum<PhantomPinned, PhantomPinned>);
44
45 #[pin_project]
46 struct TrivialBounds {
47 #[pin]
48 f: PhantomPinned,
49 }
50
51 assert_not_unpin!(TrivialBounds);
52
53 #[pin_project]
54 struct PinRef<'a, T, U> {
55 #[pin]
56 f1: &'a mut Inner<T>,
57 f2: U,
58 }
59
60 assert_unpin!(PinRef<'_, PhantomPinned, PhantomPinned>);
61}
62
63pub mod cfg {
64 use std::marker::PhantomPinned;
65
66 use pin_project::pin_project;
67
68 #[pin_project]
69 struct Foo<T> {
70 #[cfg(any())]
71 #[pin]
72 f: T,
73 #[cfg(not(any()))]
74 f: T,
75 }
76
77 assert_unpin!(Foo<PhantomPinned>);
78
79 #[pin_project]
80 struct Bar<T> {
81 #[cfg(any())]
82 f: T,
83 #[cfg(not(any()))]
84 #[pin]
85 f: T,
86 }
87
88 assert_unpin!(Bar<()>);
89 assert_not_unpin!(Bar<PhantomPinned>);
90}
91
92pub mod cfg_attr {
93 use std::marker::PhantomPinned;
94
95 use pin_project::pin_project;
96
97 #[cfg_attr(any(), pin_project)]
98 struct Foo<T> {
99 f: T,
100 }
101
102 assert_unpin!(Foo<()>);
103 assert_not_unpin!(Foo<PhantomPinned>);
104
105 #[cfg_attr(not(any()), pin_project)]
106 struct Bar<T> {
107 #[cfg_attr(not(any()), pin)]
108 f: T,
109 }
110
111 assert_unpin!(Bar<()>);
112 assert_not_unpin!(Bar<PhantomPinned>);
113}
114
115// pin_project(!Unpin)
116pub mod not_unpin {
117 use std::marker::PhantomPinned;
118
119 use pin_project::pin_project;
120
121 struct Inner<T> {
122 f: T,
123 }
124
125 #[pin_project(!Unpin)]
126 struct Struct<T, U> {
127 #[pin]
128 inner: Inner<T>,
129 other: U,
130 }
131
132 assert_not_unpin!(Struct<(), ()>);
133 assert_not_unpin!(Struct<(), PhantomPinned>);
134 assert_not_unpin!(Struct<PhantomPinned, ()>);
135 assert_not_unpin!(Struct<PhantomPinned, PhantomPinned>);
136
137 #[pin_project(!Unpin)]
138 struct TrivialBounds {
139 #[pin]
140 f: PhantomPinned,
141 }
142
143 assert_not_unpin!(TrivialBounds);
144
145 #[pin_project(!Unpin)]
146 struct PinRef<'a, T, U> {
147 #[pin]
148 inner: &'a mut Inner<T>,
149 other: U,
150 }
151
152 assert_not_unpin!(PinRef<'_, (), ()>);
153}
154