Skip to contentSkip to conversation

rust: xarray: capture the iterator lifetime explicitly

PATCH In review Peder Bergan 2 participants 2 messages Nov 18

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

PATCH 1/1 rust: xarray: capture the iterator lifetime explicitly

XArray::iter uses an outlives bound to capture the lifetime of the borrow of self in the returned iterator. Its caller consumes the iterator during pinned drop and does not need an outlives guarantee.

Use a precise capturing bound to name the borrowed lifetime. Also include T, since the bound must list all in-scope type parameters.

---
The XArray KUnit doctest passed on x86-64 QEMU. The Rust kernel crate built with CLIPPY=1.

OpenAI Codex assisted with the signature changes, testing and drafting this commit message.

---
 rust/kernel/xarray.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/xarray.rs +1 -1
index 987c9c0c2198..4a67e7f24335 100644
@@ -108,7 +108,7 @@ pub fn new(kind: AllocKind) -> impl PinInit<Self> {
         })
     }
 
-    fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + '_ {
+    fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + use<'_, T> {
         let mut index = 0;
 
         // SAFETY: `self.xa` is always valid by the type invariant.

---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261118-cleanup-xarray-precise-capture-1bf06165c6cf

Best regards,

Signature · 1 line
Peder Bergan <[email protected]>
reviewer
#1 lore raw
Quoted 12 lines · On Wed Nov 18, 2026 at 10:39 AM GMT, Peder Bergan via B4 Relay wrote:

From: Peder Bergan <[email protected]>

XArray::iter uses an outlives bound to capture the lifetime of the borrow of self in the returned iterator. Its caller consumes the iterator during pinned drop and does not need an outlives guarantee.

Use a precise capturing bound to name the borrowed lifetime. Also include T, since the bound must list all in-scope type parameters.

Quoted 6 lines

---
The XArray KUnit doctest passed on x86-64 QEMU. The Rust kernel crate built with CLIPPY=1.

OpenAI Codex assisted with the signature changes, testing and drafting this commit message.

None of this is relevant when we upgrade to Rust 2024, I'd avoid the additional churn and only do this where needed.

Best,
Gary

Quoted 25 lines
---
 rust/kernel/xarray.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/xarray.rs +1 -2
index 987c9c0c2198..4a67e7f24335 100644
@@ -108,7 +108,7 @@ pub fn new(kind: AllocKind) -> impl PinInit<Self> {
         })
     }
 
-    fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + '_ {
+    fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + use<'_, T> {
         let mut index = 0;
 
         // SAFETY: `self.xa` is always valid by the type invariant.
 
---

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261118-cleanup-xarray-precise-capture-1bf06165c6cf

Best regards,

Signature · 1 line
Peder Bergan <[email protected]>