1 // Original code (./enum-default.rs):
2 //
3 // ```rust
4 // #![allow(dead_code)]
5 //
6 // use pin_project::pin_project;
7 //
8 // #[pin_project]
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)]
18 
19 use pin_project::pin_project;
20 
21 enum Enum<T, U> {
22     Pinned(/* #[pin] */ T),
23     Unpinned(U),
24 }
25 
26 #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
27 #[allow(dead_code)] // This lint warns unused fields/variants.
28 enum __EnumProjection<'pin, T, U> {
29     Pinned(::core::pin::Pin<&'pin mut (T)>),
30     Unpinned(&'pin mut (U)),
31 }
32 
33 #[allow(dead_code)] // This lint warns unused fields/variants.
34 enum __EnumProjectionRef<'pin, T, U> {
35     Pinned(::core::pin::Pin<&'pin (T)>),
36     Unpinned(&'pin (U)),
37 }
38 
39 impl<T, U> Enum<T, U> {
project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __EnumProjection<'pin, T, U>40     fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __EnumProjection<'pin, T, U> {
41         unsafe {
42             match self.get_unchecked_mut() {
43                 Enum::Pinned(_0) => __EnumProjection::Pinned(::core::pin::Pin::new_unchecked(_0)),
44                 Enum::Unpinned(_0) => __EnumProjection::Unpinned(_0),
45             }
46         }
47     }
project_ref<'pin>(self: ::core::pin::Pin<&'pin Self>) -> __EnumProjectionRef<'pin, T, U>48     fn project_ref<'pin>(self: ::core::pin::Pin<&'pin Self>) -> __EnumProjectionRef<'pin, T, U> {
49         unsafe {
50             match self.get_ref() {
51                 Enum::Pinned(_0) => {
52                     __EnumProjectionRef::Pinned(::core::pin::Pin::new_unchecked(_0))
53                 }
54                 Enum::Unpinned(_0) => __EnumProjectionRef::Unpinned(_0),
55             }
56         }
57     }
58 }
59 
60 // Automatically create the appropriate conditional `Unpin` implementation.
61 //
62 // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
63 // for details.
64 #[allow(non_snake_case)]
__unpin_scope_Enum()65 fn __unpin_scope_Enum() {
66     struct __Enum<'pin, T, U> {
67         __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
68         __field0: T,
69     }
70     impl<'pin, T, U> ::core::marker::Unpin for Enum<T, U> where __Enum<'pin, T, U>: ::core::marker::Unpin
71     {}
72 }
73 
74 // Ensure that enum does not implement `Drop`.
75 //
76 // See ./struct-default-expanded.rs for details.
77 trait EnumMustNotImplDrop {}
78 #[allow(clippy::drop_bounds)]
79 impl<T: ::core::ops::Drop> EnumMustNotImplDrop for T {}
80 #[allow(single_use_lifetimes)]
81 impl<T, U> EnumMustNotImplDrop for Enum<T, U> {}
82 
83 // We don't need to check for '#[repr(packed)]',
84 // since it does not apply to enums.
85 
main()86 fn main() {}
87