|
| 1 | +use pin_init::*; |
| 2 | +#[repr(C, packed)] |
| 3 | +struct Foo { |
| 4 | + a: i8, |
| 5 | + b: i32, |
| 6 | + c: i32, |
| 7 | +} |
| 8 | +fn main() { |
| 9 | + let _ = { |
| 10 | + struct __InitOk; |
| 11 | + let __data = unsafe { |
| 12 | + use ::pin_init::__internal::HasInitData; |
| 13 | + Foo::__init_data() |
| 14 | + }; |
| 15 | + let init = ::pin_init::__internal::InitData::make_closure::< |
| 16 | + _, |
| 17 | + __InitOk, |
| 18 | + ::core::convert::Infallible, |
| 19 | + >( |
| 20 | + __data, |
| 21 | + move |slot| { |
| 22 | + { |
| 23 | + struct __InitOk; |
| 24 | + { |
| 25 | + let c = -42; |
| 26 | + unsafe { ::core::ptr::write(&raw mut (*slot).c, c) }; |
| 27 | + } |
| 28 | + let __c_guard = unsafe { |
| 29 | + ::pin_init::__internal::DropGuard::new(&raw mut (*slot).c) |
| 30 | + }; |
| 31 | + { |
| 32 | + let b = *c; |
| 33 | + unsafe { ::core::ptr::write(&raw mut (*slot).b, b) }; |
| 34 | + } |
| 35 | + let __b_guard = unsafe { |
| 36 | + ::pin_init::__internal::DropGuard::new(&raw mut (*slot).b) |
| 37 | + }; |
| 38 | + { |
| 39 | + let a = 0; |
| 40 | + unsafe { ::core::ptr::write(&raw mut (*slot).a, a) }; |
| 41 | + } |
| 42 | + let __a_guard = unsafe { |
| 43 | + ::pin_init::__internal::DropGuard::new(&raw mut (*slot).a) |
| 44 | + }; |
| 45 | + ::core::mem::forget(__c_guard); |
| 46 | + ::core::mem::forget(__b_guard); |
| 47 | + ::core::mem::forget(__a_guard); |
| 48 | + #[allow(unreachable_code, clippy::diverging_sub_expression)] |
| 49 | + let _ = || unsafe { |
| 50 | + ::core::ptr::write( |
| 51 | + slot, |
| 52 | + Foo { |
| 53 | + c: ::core::panicking::panic("explicit panic"), |
| 54 | + b: ::core::panicking::panic("explicit panic"), |
| 55 | + a: ::core::panicking::panic("explicit panic"), |
| 56 | + }, |
| 57 | + ) |
| 58 | + }; |
| 59 | + } |
| 60 | + Ok(__InitOk) |
| 61 | + }, |
| 62 | + ); |
| 63 | + let init = move | |
| 64 | + slot, |
| 65 | + | -> ::core::result::Result<(), ::core::convert::Infallible> { |
| 66 | + init(slot).map(|__InitOk| ()) |
| 67 | + }; |
| 68 | + let init = unsafe { |
| 69 | + ::pin_init::init_from_closure::<_, ::core::convert::Infallible>(init) |
| 70 | + }; |
| 71 | + init |
| 72 | + }; |
| 73 | +} |
0 commit comments