Re: [PATCH] rust: alloc: fix assert in `Vec::reserve` doc test
From: Alexandre Courbot
Date: Tue Apr 28 2026 - 10:11:06 EST
On Mon Apr 27, 2026 at 11:15 PM JST, Hsiu Che Yu wrote:
> The assert in the doctest used `>= 10`, which only checks that the
> capacity can hold `additional` elements, ignoring the existing length
> of `v`. The correct check should ensure there is room for `additional`
> *extra* elements on top of what is already in the vector.
>
> Fix the assert to use `>= v.len() + 10` so the example accurately
> reflects the actual semantics of the function.
>
> Reported-by: Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx>
> Closes: https://lore.kernel.org/rust-for-linux/CANiq72nkXWhjK9iFRrhGtkMZGsvNE_zVsu4JnxaFRfxWL7RRdg@xxxxxxxxxxxxxx/
> Fixes: 2aac4cd7dae3d ("rust: alloc: implement kernel `Vec` type")
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@xxxxxxxxx>
Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>