Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 1 | // Original code (./enum-default.rs): |
| 2 | // |
| 3 | // ```rust |
| 4 | // #![allow(dead_code)] |
| 5 | // |
| 6 | // use pin_project::pin_project; |
| 7 | // |
Haibo Huang | 2960bb3 | 2020-05-18 15:51:06 -0700 | [diff] [blame] | 8 | // #[pin_project(project = EnumProj)] |
Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 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 | #![allow(clippy::no_effect, clippy::just_underscores_and_digits)] |
| 19 | |
| 20 | use pin_project::pin_project; |
| 21 | |
| 22 | enum Enum<T, U> { |
| 23 | Pinned(/* #[pin] */ T), |
| 24 | Unpinned(U), |
| 25 | } |
| 26 | |
Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 27 | #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. |
| 28 | #[allow(dead_code)] // This lint warns unused fields/variants. |
| 29 | #[allow(single_use_lifetimes)] |
Haibo Huang | 2960bb3 | 2020-05-18 15:51:06 -0700 | [diff] [blame] | 30 | enum EnumProj<'pin, T, U> |
Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 31 | where |
| 32 | Enum<T, U>: 'pin, |
| 33 | { |
| 34 | Pinned(::pin_project::__reexport::pin::Pin<&'pin mut (T)>), |
| 35 | Unpinned(&'pin mut (U)), |
| 36 | } |
| 37 | #[doc(hidden)] |
| 38 | #[allow(dead_code)] // This lint warns unused fields/variants. |
| 39 | #[allow(single_use_lifetimes)] |
| 40 | enum __EnumProjectionRef<'pin, T, U> |
| 41 | where |
| 42 | Enum<T, U>: 'pin, |
| 43 | { |
| 44 | Pinned(::pin_project::__reexport::pin::Pin<&'pin (T)>), |
| 45 | Unpinned(&'pin (U)), |
| 46 | } |
| 47 | |
| 48 | #[doc(hidden)] |
| 49 | #[allow(non_upper_case_globals)] |
| 50 | #[allow(single_use_lifetimes)] |
| 51 | const __SCOPE_Enum: () = { |
| 52 | impl<T, U> Enum<T, U> { |
| 53 | fn project<'pin>( |
| 54 | self: ::pin_project::__reexport::pin::Pin<&'pin mut Self>, |
Haibo Huang | 2960bb3 | 2020-05-18 15:51:06 -0700 | [diff] [blame] | 55 | ) -> EnumProj<'pin, T, U> { |
Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 56 | unsafe { |
| 57 | match self.get_unchecked_mut() { |
Haibo Huang | 2960bb3 | 2020-05-18 15:51:06 -0700 | [diff] [blame] | 58 | Enum::Pinned(_0) => { |
| 59 | EnumProj::Pinned(::pin_project::__reexport::pin::Pin::new_unchecked(_0)) |
| 60 | } |
| 61 | Enum::Unpinned(_0) => EnumProj::Unpinned(_0), |
Chih-Hung Hsieh | 6f3e927 | 2020-05-13 16:08:03 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
| 65 | fn project_ref<'pin>( |
| 66 | self: ::pin_project::__reexport::pin::Pin<&'pin Self>, |
| 67 | ) -> __EnumProjectionRef<'pin, T, U> { |
| 68 | unsafe { |
| 69 | match self.get_ref() { |
| 70 | Enum::Pinned(_0) => __EnumProjectionRef::Pinned( |
| 71 | ::pin_project::__reexport::pin::Pin::new_unchecked(_0), |
| 72 | ), |
| 73 | Enum::Unpinned(_0) => __EnumProjectionRef::Unpinned(_0), |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Automatically create the appropriate conditional `Unpin` implementation. |
| 80 | // |
| 81 | // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53. |
| 82 | // for details. |
| 83 | struct __Enum<'pin, T, U> { |
| 84 | __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>, |
| 85 | __field0: T, |
| 86 | } |
| 87 | impl<'pin, T, U> ::pin_project::__reexport::marker::Unpin for Enum<T, U> where |
| 88 | __Enum<'pin, T, U>: ::pin_project::__reexport::marker::Unpin |
| 89 | { |
| 90 | } |
| 91 | unsafe impl<T, U> ::pin_project::UnsafeUnpin for Enum<T, U> {} |
| 92 | |
| 93 | // Ensure that enum does not implement `Drop`. |
| 94 | // |
| 95 | // See ./struct-default-expanded.rs for details. |
| 96 | trait EnumMustNotImplDrop {} |
| 97 | #[allow(clippy::drop_bounds)] |
| 98 | impl<T: ::pin_project::__reexport::ops::Drop> EnumMustNotImplDrop for T {} |
| 99 | impl<T, U> EnumMustNotImplDrop for Enum<T, U> {} |
| 100 | impl<T, U> ::pin_project::__private::PinnedDrop for Enum<T, U> { |
| 101 | unsafe fn drop(self: ::pin_project::__reexport::pin::Pin<&mut Self>) {} |
| 102 | } |
| 103 | |
| 104 | // We don't need to check for `#[repr(packed)]`, |
| 105 | // since it does not apply to enums. |
| 106 | }; |
| 107 | |
| 108 | fn main() {} |