diff options
| author | Gary Guo <gary@garyguo.net> | 2026-07-29 16:38:44 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2026-08-03 13:36:42 +0100 |
| commit | 91665820d9bf511e0c3fdf3edb464ba23130dafe (patch) | |
| tree | 3a97abbe1cd64a56b269235351130c71026a1d8d /rust/pin-init/src/alloc.rs | |
| parent | c998b661b7c024dfd6dd893927506e32ee8a42c5 (diff) | |
rust: pin-init: merge `__pinned_init` and `__init`
These functions have the same requirements and are also required to execute
the same code. Prevent duplication by merging them to the single function
and document the additional relaxation of `Init::__init` on both the merged
function and the safety requirement of `Init`.
The existing `__pinned_init` function is deprecated and kept for
compatibility for existing users. For `cfg(kernel)`, it is soft-deprecated
for now and will be removed when all users are migrated.
Link: https://patch.msgid.link/20260729-merge-init-v2-2-26adf47109e7@garyguo.net
Signed-off-by: Gary Guo <gary@garyguo.net>
Diffstat (limited to 'rust/pin-init/src/alloc.rs')
| -rw-r--r-- | rust/pin-init/src/alloc.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/rust/pin-init/src/alloc.rs b/rust/pin-init/src/alloc.rs index 5017f57442d8..641f4c7ce890 100644 --- a/rust/pin-init/src/alloc.rs +++ b/rust/pin-init/src/alloc.rs @@ -38,7 +38,7 @@ pub trait InPlaceInit<T>: Sized { fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { // SAFETY: We delegate to `init` and only change the error type. let init = unsafe { - pin_init_from_closure(|slot| match init.__pinned_init(slot) { + pin_init_from_closure(|slot| match init.__init(slot) { Ok(()) => Ok(()), Err(i) => match i {}, }) @@ -109,7 +109,7 @@ impl<T> InPlaceInit<T> for Arc<T> { let slot = slot.as_mut_ptr(); // SAFETY: When init errors/panics, slot will get deallocated but not dropped, // slot is valid and will not be moved, because we pin it later. - unsafe { init.__pinned_init(slot)? }; + unsafe { init.__init(slot)? }; // SAFETY: All fields have been initialized and this is the only `Arc` to that data. Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) } @@ -149,7 +149,7 @@ impl<T> InPlaceWrite<T> for Box<MaybeUninit<T>> { let slot = self.as_mut_ptr(); // SAFETY: When init errors/panics, slot will get deallocated but not dropped, // slot is valid and will not be moved, because we pin it later. - unsafe { init.__pinned_init(slot)? }; + unsafe { init.__init(slot)? }; // SAFETY: All fields have been initialized. Ok(unsafe { self.assume_init() }.into()) } |
