Skip to contentSkip to conversation

rust: alloc: fix assert in `Vec::reserve` doc test

PATCH Applied Hsiu Che Yu 4 participants 4 messages Apr 27 – May 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index ac8d6f763ae8..d05f3835cf53 100644
@@ -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]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Hsiu Che Yu

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.

Quoted 7 lines

Fix the assert to use >= v.len() + 10 so the example accurately reflects the actual semantics of the function.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Hsiu Che Yu
Quoted 5 lines · Hsiu Che Yu

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.

Quoted 7 lines

Fix the assert to use >= v.len() + 10 so the example accurately reflects the actual semantics of the function.

maintainer Applied
#3 lore raw
In reply to Hsiu Che Yu
Quoted 1 line · Hsiu Che Yu

[PATCH] rust: alloc: fix assert in Vec::reserve doc 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.