linux/rust/kernel/alloc
Andreas Hindborg d190aa2094 rust: alloc: allow different error types in KBox::pin_slice
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 `E: From<AllocError>` and `E: From<E2>` 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.

Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/.E2.9C.94.20Constructing.20Mutex.20from.20PinInit.3CT.2C.20Error.3E
Co-developed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://patch.msgid.link/20260605-pin-slice-init-v2-1-b197e84040ba@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2026-09-29 21:04:59 +02:00
..
allocator rust: alloc: cleanup imports and use "kernel vertical" style 2026-05-20 17:34:17 +02:00
kvec rust: alloc: cleanup imports and use "kernel vertical" style 2026-05-20 17:34:17 +02:00
allocator.rs rust: tests: add Kconfig for KUnit test 2026-06-08 02:30:33 +02:00
kbox.rs rust: alloc: allow different error types in KBox::pin_slice 2026-09-29 21:04:59 +02:00
kvec.rs rust: alloc: add Vec::zeroed method 2026-08-06 01:22:14 +02:00
layout.rs rust: alloc: cleanup doctest imports to "kernel vertical" style 2026-05-20 17:34:17 +02:00