1 // Original code (./enum-default.rs):
2 //
3 // ```rust
4 // #![allow(dead_code)]
5 //
6 // use pin_project::pin_project;
7 //
8 // #[pin_project(project = EnumProj)]
9 // enum Enum<T, U> {
10 //     Pinned(#[pin] T),
11 //     Unpinned(U),
12 // }
13 //
14 // fn main() {}
15 // ```
16 
17 #![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
18 #![allow(
19     clippy::needless_lifetimes,
20     clippy::just_underscores_and_digits,
21     clippy::used_underscore_binding
22 )]
23 
24 use pin_project::pin_project;
25 
26 // #[pin_project(project = EnumProj)]
27 enum Enum<T, U> {
28     Pinned(/* #[pin] */ T),
29     Unpinned(U),
30 }
31 
32 enum EnumProj<'pin, T, U>
33 where
34     Enum<T, U>: 'pin,
35 {
36     Pinned(::pin_project::__private::Pin<&'pin mut (T)>),
37     Unpinned(&'pin mut (U)),
38 }
39 
40 const _: () = {
41     // When `#[pin_project]` is used on enums, only named projection types and
42     // methods are generated because there is no way to access variants of
43     // projected types without naming it.
44     // (When `#[pin_project]` is used on structs, both methods are always generated.)
45 
46     impl<T, U> Enum<T, U> {
project<'pin>( self: ::pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U>47         fn project<'pin>(
48             self: ::pin_project::__private::Pin<&'pin mut Self>,
49         ) -> EnumProj<'pin, T, U> {
50             unsafe {
51                 match self.get_unchecked_mut() {
52                     Self::Pinned(_0) => {
53                         EnumProj::Pinned(::pin_project::__private::Pin::new_unchecked(_0))
54                     }
55                     Self::Unpinned(_0) => EnumProj::Unpinned(_0),
56                 }
57             }
58         }
59     }
60 
61     // Automatically create the appropriate conditional `Unpin` implementation.
62     //
63     // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
64     // for details.
65     struct __Enum<'pin, T, U> {
66         __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
67             'pin,
68             (::pin_project::__private::PhantomData<T>, ::pin_project::__private::PhantomData<U>),
69         >,
70         __field0: T,
71     }
72     impl<'pin, T, U> ::pin_project::__private::Unpin for Enum<T, U> where
73         __Enum<'pin, T, U>: ::pin_project::__private::Unpin
74     {
75     }
76     // A dummy impl of `UnsafeUnpin`, to ensure that the user cannot implement it.
77     #[doc(hidden)]
78     unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum<T, U> where
79         __Enum<'pin, T, U>: ::pin_project::__private::Unpin
80     {
81     }
82 
83     // Ensure that enum does not implement `Drop`.
84     //
85     // See ./struct-default-expanded.rs for details.
86     trait EnumMustNotImplDrop {}
87     #[allow(clippy::drop_bounds, drop_bounds)]
88     impl<T: ::pin_project::__private::Drop> EnumMustNotImplDrop for T {}
89     impl<T, U> EnumMustNotImplDrop for Enum<T, U> {}
90     // A dummy impl of `PinnedDrop`, to ensure that users don't accidentally
91     // write a non-functional `PinnedDrop` impls.
92     #[doc(hidden)]
93     impl<T, U> ::pin_project::__private::PinnedDrop for Enum<T, U> {
drop(self: ::pin_project::__private::Pin<&mut Self>)94         unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
95     }
96 
97     // We don't need to check for `#[repr(packed)]`,
98     // since it does not apply to enums.
99 };
100 
main()101 fn main() {}
102