Re: [PATCH] rust: alloc: allow different error types in `KBox::pin_slice`

From: Danilo Krummrich

Date: Mon Feb 16 2026 - 04:37:24 EST


On Mon Feb 16, 2026 at 9:48 AM CET, Alice Ryhl wrote:
> On Sat, Feb 14, 2026 at 03:56:43PM +0100, Danilo Krummrich wrote:
>> Yeah, but isn't this only because of [1], which does not apply to the kernel
>> because our minimum compiler version is 1.78 anyways?
>>
>> I.e. are there any cases where we can't implement From in the kernel and have to
>> fall back to Into?
>
> Probably not, but it's still best practice to use Into over From when
> specifying trait bounds.

I'm aware; my point is that I'm questioning this best practice in the context of
a modern and self-contained project like Rust in the kernel.

This patch is a very good example, as there seem to be zero downsides to a >From
trait bound, while using the From trait bound allows for cleaner code.

(I.e. we get rid of the matches and can use the '?' operator instead. To be
fair, this could also be written as `.map_err(Into::into)?`, but still.)

I'd even argue that using a From trait bound here is a feature and not a
limitation. I.e. if someone would pass something that implements Into (but not
From) we'd catch it and can tell the caller to implement From instead of Into,
which is preferred and should always be possible in the kernel.