Re: [PATCH 2/2] rust: uaccess: use NonEmpty in strcpy_into_buf()

From: Lorenzo Delgado

Date: Mon Oct 12 2026 - 14:25:54 EST


On Mon, Oct 12, 2026 at 2:22 PM Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> Hmm... I thought the idea was to request a `NonEmpty` in the signature.
>
> Is it not possible for some reason?

It's possible. I kept the signature as is to limit the change to the
inside of the function, but you're right: the point of the newtype is
to put the requirement in the signature. In v2 it will take
`&mut NonEmpty<[u8]>` and the `EINVAL` case goes away.

Since callers will usually pass a fixed-size array, v2 also adds a
constructor from `&mut [T; N]` that checks `N > 0` at compile time, so
they don't need a runtime check either.

Thanks,
Lorenzo