|
| 1 | +use pin_init::*; |
| 2 | +struct Foo([u8; 1024 * 1024], i32); |
| 3 | +/// Pin-projections of [`Foo`] |
| 4 | +#[allow(dead_code)] |
| 5 | +#[doc(hidden)] |
| 6 | +struct FooProjection<'__pin> { |
| 7 | + _0: &'__pin mut [u8; 1024 * 1024], |
| 8 | + _1: ::core::pin::Pin<&'__pin mut i32>, |
| 9 | + ___pin_phantom_data: ::core::marker::PhantomData<&'__pin mut ()>, |
| 10 | +} |
| 11 | +impl Foo { |
| 12 | + /// Pin-projects all fields of `Self`. |
| 13 | + /// |
| 14 | + /// These fields are structurally pinned: |
| 15 | + /// - index `1` |
| 16 | + /// |
| 17 | + /// These fields are **not** structurally pinned: |
| 18 | + /// - index `0` |
| 19 | + #[inline] |
| 20 | + fn project<'__pin>( |
| 21 | + self: ::core::pin::Pin<&'__pin mut Self>, |
| 22 | + ) -> FooProjection<'__pin> { |
| 23 | + let this = unsafe { ::core::pin::Pin::get_unchecked_mut(self) }; |
| 24 | + FooProjection { |
| 25 | + _0: &mut this.0, |
| 26 | + _1: unsafe { ::core::pin::Pin::new_unchecked(&mut this.1) }, |
| 27 | + ___pin_phantom_data: ::core::marker::PhantomData, |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | +const _: () = { |
| 32 | + #[doc(hidden)] |
| 33 | + struct __ThePinData { |
| 34 | + __phantom: ::core::marker::PhantomData<fn(Foo) -> Foo>, |
| 35 | + } |
| 36 | + impl ::core::clone::Clone for __ThePinData { |
| 37 | + fn clone(&self) -> Self { |
| 38 | + *self |
| 39 | + } |
| 40 | + } |
| 41 | + impl ::core::marker::Copy for __ThePinData {} |
| 42 | + #[allow(dead_code)] |
| 43 | + #[expect(clippy::missing_safety_doc)] |
| 44 | + impl __ThePinData { |
| 45 | + /// # Safety |
| 46 | + /// |
| 47 | + /// - `slot` is a valid pointer to uninitialized memory. |
| 48 | + /// - the caller does not touch `slot` when `Err` is returned, they are only permitted |
| 49 | + /// to deallocate. |
| 50 | + unsafe fn _0<E>( |
| 51 | + self, |
| 52 | + slot: *mut [u8; 1024 * 1024], |
| 53 | + init: impl ::pin_init::Init<[u8; 1024 * 1024], E>, |
| 54 | + ) -> ::core::result::Result<(), E> { |
| 55 | + unsafe { ::pin_init::Init::__init(init, slot) } |
| 56 | + } |
| 57 | + /// # Safety |
| 58 | + /// |
| 59 | + /// `slot` points at the field index `0` inside of `Foo`, which is pinned. |
| 60 | + unsafe fn __project_0<'__slot>( |
| 61 | + self, |
| 62 | + slot: &'__slot mut [u8; 1024 * 1024], |
| 63 | + ) -> &'__slot mut [u8; 1024 * 1024] { |
| 64 | + slot |
| 65 | + } |
| 66 | + /// # Safety |
| 67 | + /// |
| 68 | + /// - `slot` is a valid pointer to uninitialized memory. |
| 69 | + /// - the caller does not touch `slot` when `Err` is returned, they are only permitted |
| 70 | + /// to deallocate. |
| 71 | + /// - `slot` will not move until it is dropped, i.e. it will be pinned. |
| 72 | + unsafe fn _1<E>( |
| 73 | + self, |
| 74 | + slot: *mut i32, |
| 75 | + init: impl ::pin_init::PinInit<i32, E>, |
| 76 | + ) -> ::core::result::Result<(), E> { |
| 77 | + unsafe { ::pin_init::PinInit::__pinned_init(init, slot) } |
| 78 | + } |
| 79 | + /// # Safety |
| 80 | + /// |
| 81 | + /// `slot` points at the field index `1` inside of `Foo`, which is pinned. |
| 82 | + unsafe fn __project_1<'__slot>( |
| 83 | + self, |
| 84 | + slot: &'__slot mut i32, |
| 85 | + ) -> ::core::pin::Pin<&'__slot mut i32> { |
| 86 | + unsafe { ::core::pin::Pin::new_unchecked(slot) } |
| 87 | + } |
| 88 | + } |
| 89 | + unsafe impl ::pin_init::__internal::HasPinData for Foo { |
| 90 | + type PinData = __ThePinData; |
| 91 | + unsafe fn __pin_data() -> Self::PinData { |
| 92 | + __ThePinData { |
| 93 | + __phantom: ::core::marker::PhantomData, |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + unsafe impl ::pin_init::__internal::PinData for __ThePinData { |
| 98 | + type Datee = Foo; |
| 99 | + } |
| 100 | + #[allow(dead_code)] |
| 101 | + struct __Unpin<'__pin> { |
| 102 | + __phantom_pin: ::core::marker::PhantomData<fn(&'__pin ()) -> &'__pin ()>, |
| 103 | + __phantom: ::core::marker::PhantomData<fn(Foo) -> Foo>, |
| 104 | + _1: i32, |
| 105 | + } |
| 106 | + #[doc(hidden)] |
| 107 | + impl<'__pin> ::core::marker::Unpin for Foo |
| 108 | + where |
| 109 | + __Unpin<'__pin>: ::core::marker::Unpin, |
| 110 | + {} |
| 111 | + trait MustNotImplDrop {} |
| 112 | + #[expect(drop_bounds)] |
| 113 | + impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {} |
| 114 | + impl MustNotImplDrop for Foo {} |
| 115 | + #[expect(non_camel_case_types)] |
| 116 | + trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {} |
| 117 | + impl< |
| 118 | + T: ::pin_init::PinnedDrop + ?::core::marker::Sized, |
| 119 | + > UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {} |
| 120 | + impl UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for Foo {} |
| 121 | +}; |
0 commit comments