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