rust: alloc: fix assert in `Vec::reserve` doc test
Subsystems (2)
PATCH 1/1 rust: alloc: fix assert in `Vec::reserve` doc test
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.
--- rust/kernel/alloc/kvec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/alloc/kvec.rs +1 -1
@@ -611,7 +611,7 @@ pub fn clear(&mut self) {/// /// v.reserve(10, GFP_KERNEL)?; /// let cap = v.capacity(); -/// assert!(cap >= 10); +/// assert!(cap >= v.len() + 10); /// /// v.reserve(10, GFP_KERNEL)?; /// let new_cap = v.capacity();
---
base-commit: b4e07588e743c989499ca24d49e752c074924a9a
change-id: 20260427-doctest-kvec-reserve-6a84e832b05e
Best regards,
Signature · 1 line
Hsiu Che Yu <[email protected]>
Quoted 5 lines · Hsiu Che Yu
The assert in the doctest used
>= 10, which only checks that the capacity can holdadditionalelements, ignoring the existing length ofv. The correct check should ensure there is room foradditional*extra* elements on top of what is already in the vector.
Quoted 7 lines
Fix the assert to use
>= v.len() + 10so the example accurately reflects the actual semantics of the function.Reported-by Miguel Ojeda <[email protected]>Closes https://lore.kernel.org/rust-for-linux/CANiq72nkXWhjK9iFRrhGtkMZGsvNE_zVsu4JnxaFRfxWL7RRdg@mail.gmail.com/ open hereFixes 2aac4cd7dae3d ("rust: alloc: implement kernel `Vec` type")Signed-off-by Hsiu Che Yu <[email protected]>
Quoted 5 lines · Hsiu Che Yu
The assert in the doctest used
>= 10, which only checks that the capacity can holdadditionalelements, ignoring the existing length ofv. The correct check should ensure there is room foradditional*extra* elements on top of what is already in the vector.
Quoted 7 lines
Fix the assert to use
>= v.len() + 10so the example accurately reflects the actual semantics of the function.Reported-by Miguel Ojeda <[email protected]>Closes https://lore.kernel.org/rust-for-linux/CANiq72nkXWhjK9iFRrhGtkMZGsvNE_zVsu4JnxaFRfxWL7RRdg@mail.gmail.com/ open hereFixes 2aac4cd7dae3d ("rust: alloc: implement kernel `Vec` type")Signed-off-by Hsiu Che Yu <[email protected]>
Quoted 1 line · Hsiu Che Yu
[PATCH] rust: alloc: fix assert in
Vec::reservedoc test
Applied, thanks!
Branch: alloc-next
Tree: [email protected]:Rust-for-Linux/linux.git
[1/1] rust: alloc: fix assert in Vec::reserve doc test
commit: 75619f2df7a5
The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).
The patch is queued up for the upcoming merge window for the next major kernel release.