Re: [PATCH] rust: alloc: allow different error types in `KBox::pin_slice`
From: Andreas Hindborg
Date: Sat Feb 14 2026 - 08:37:32 EST
Andreas Hindborg <a.hindborg@xxxxxxxxxx> writes:
> Previously, `KBox::pin_slice` required the initializer error type to match
> the return error type via `E: From<AllocError>`. This prevented using
> infallible initializers like `new_mutex!` inside `pin_slice`, because
> `Infallible` does not implement `From<AllocError>`.
>
> Introduce a separate type parameter `E2` for the initializer error type and
> require `AllocError: Into<E>` and `E2: Into<E>` instead. This allows the
> initializer to return a different error type that can be converted into the
> final error type, enabling use of infallible pin initializers in fallible
> allocation contexts.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> ---
> @Benno, I would like to add your SoB and CDB tags.
It just occured to me that we should probably add a zulip Link as well:
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/.E2.9C.94.20Constructing.20Mutex.20from.20PinInit.3CT.2C.20Error.3E/with/567385936
Best regards,
Andreas Hindborg