|
| 1 | +use core::{marker::PhantomPinned, pin::Pin}; |
| 2 | +use pinned_init::*; |
| 3 | +trait Bar<'a, const ID: usize = 0> { |
| 4 | + fn bar(&mut self); |
| 5 | +} |
| 6 | +struct Foo<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0> |
| 7 | +where |
| 8 | + T: Bar<'a, 1>, |
| 9 | +{ |
| 10 | + array: [u8; 1024 * 1024], |
| 11 | + r: &'b mut [&'a mut T; SIZE], |
| 12 | + _pin: PhantomPinned, |
| 13 | +} |
| 14 | +const _: () = { |
| 15 | + struct __ThePinData<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> |
| 16 | + where |
| 17 | + T: Bar<'a, 1>, |
| 18 | + { |
| 19 | + __phantom: ::core::marker::PhantomData< |
| 20 | + fn(Foo<'a, 'b, T, SIZE>) -> Foo<'a, 'b, T, SIZE>, |
| 21 | + >, |
| 22 | + } |
| 23 | + impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::clone::Clone |
| 24 | + for __ThePinData<'a, 'b, T, SIZE> |
| 25 | + where |
| 26 | + T: Bar<'a, 1>, |
| 27 | + { |
| 28 | + fn clone(&self) -> Self { |
| 29 | + *self |
| 30 | + } |
| 31 | + } |
| 32 | + impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::marker::Copy |
| 33 | + for __ThePinData<'a, 'b, T, SIZE> |
| 34 | + where |
| 35 | + T: Bar<'a, 1>, |
| 36 | + {} |
| 37 | + #[allow(dead_code)] |
| 38 | + impl< |
| 39 | + 'a, |
| 40 | + 'b: 'a, |
| 41 | + T: Bar<'b> + ?Sized + 'a, |
| 42 | + const SIZE: usize, |
| 43 | + > __ThePinData<'a, 'b, T, SIZE> |
| 44 | + where |
| 45 | + T: Bar<'a, 1>, |
| 46 | + { |
| 47 | + unsafe fn _pin<E>( |
| 48 | + self, |
| 49 | + slot: *mut PhantomPinned, |
| 50 | + init: impl ::pinned_init::PinInit<PhantomPinned, E>, |
| 51 | + ) -> ::core::result::Result<(), E> { |
| 52 | + unsafe { ::pinned_init::PinInit::__pinned_init(init, slot) } |
| 53 | + } |
| 54 | + unsafe fn array<E>( |
| 55 | + self, |
| 56 | + slot: *mut [u8; 1024 * 1024], |
| 57 | + init: impl ::pinned_init::Init<[u8; 1024 * 1024], E>, |
| 58 | + ) -> ::core::result::Result<(), E> { |
| 59 | + unsafe { ::pinned_init::Init::__init(init, slot) } |
| 60 | + } |
| 61 | + unsafe fn r<E>( |
| 62 | + self, |
| 63 | + slot: *mut &'b mut [&'a mut T; SIZE], |
| 64 | + init: impl ::pinned_init::Init<&'b mut [&'a mut T; SIZE], E>, |
| 65 | + ) -> ::core::result::Result<(), E> { |
| 66 | + unsafe { ::pinned_init::Init::__init(init, slot) } |
| 67 | + } |
| 68 | + } |
| 69 | + unsafe impl< |
| 70 | + 'a, |
| 71 | + 'b: 'a, |
| 72 | + T: Bar<'b> + ?Sized + 'a, |
| 73 | + const SIZE: usize, |
| 74 | + > ::pinned_init::__internal::HasPinData for Foo<'a, 'b, T, SIZE> |
| 75 | + where |
| 76 | + T: Bar<'a, 1>, |
| 77 | + { |
| 78 | + type PinData = __ThePinData<'a, 'b, T, SIZE>; |
| 79 | + unsafe fn __pin_data() -> Self::PinData { |
| 80 | + __ThePinData { |
| 81 | + __phantom: ::core::marker::PhantomData, |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + unsafe impl< |
| 86 | + 'a, |
| 87 | + 'b: 'a, |
| 88 | + T: Bar<'b> + ?Sized + 'a, |
| 89 | + const SIZE: usize, |
| 90 | + > ::pinned_init::__internal::PinData for __ThePinData<'a, 'b, T, SIZE> |
| 91 | + where |
| 92 | + T: Bar<'a, 1>, |
| 93 | + { |
| 94 | + type Datee = Foo<'a, 'b, T, SIZE>; |
| 95 | + } |
| 96 | + #[allow(dead_code)] |
| 97 | + struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> |
| 98 | + where |
| 99 | + T: Bar<'a, 1>, |
| 100 | + { |
| 101 | + __phantom_pin: ::core::marker::PhantomData<fn(&'__pin ()) -> &'__pin ()>, |
| 102 | + __phantom: ::core::marker::PhantomData< |
| 103 | + fn(Foo<'a, 'b, T, SIZE>) -> Foo<'a, 'b, T, SIZE>, |
| 104 | + >, |
| 105 | + _pin: PhantomPinned, |
| 106 | + } |
| 107 | + #[doc(hidden)] |
| 108 | + impl< |
| 109 | + '__pin, |
| 110 | + 'a, |
| 111 | + 'b: 'a, |
| 112 | + T: Bar<'b> + ?Sized + 'a, |
| 113 | + const SIZE: usize, |
| 114 | + > ::core::marker::Unpin for Foo<'a, 'b, T, SIZE> |
| 115 | + where |
| 116 | + __Unpin<'__pin, 'a, 'b, T, SIZE>: ::core::marker::Unpin, |
| 117 | + T: Bar<'a, 1>, |
| 118 | + {} |
| 119 | + impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::ops::Drop |
| 120 | + for Foo<'a, 'b, T, SIZE> |
| 121 | + where |
| 122 | + T: Bar<'a, 1>, |
| 123 | + { |
| 124 | + fn drop(&mut self) { |
| 125 | + let pinned = unsafe { ::core::pin::Pin::new_unchecked(self) }; |
| 126 | + let token = unsafe { ::pinned_init::__internal::OnlyCallFromDrop::new() }; |
| 127 | + ::pinned_init::PinnedDrop::drop(pinned, token); |
| 128 | + } |
| 129 | + } |
| 130 | +}; |
| 131 | +unsafe impl< |
| 132 | + 'a, |
| 133 | + 'b: 'a, |
| 134 | + T: Bar<'b> + ?Sized + 'a, |
| 135 | + const SIZE: usize, |
| 136 | +> ::pinned_init::PinnedDrop for Foo<'a, 'b, T, SIZE> |
| 137 | +where |
| 138 | + T: Bar<'b, 1>, |
| 139 | +{ |
| 140 | + fn drop(self: Pin<&mut Self>, _: ::pinned_init::__internal::OnlyCallFromDrop) { |
| 141 | + let me = unsafe { Pin::get_unchecked_mut(self) }; |
| 142 | + for t in &mut *me.r { |
| 143 | + Bar::<'a, 1>::bar(*t); |
| 144 | + } |
| 145 | + } |
| 146 | +} |
| 147 | +fn main() {} |
0 commit comments