[PATCH v2 2/6] rust: ptr: use `match` instead of `unwrap_or_else` for `build_index`
From: Gary Guo
Date: Tue Jun 02 2026 - 10:33:01 EST
Use `match` to avoid potential inlining issues of the `unwrap_or_else`
function.
Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Link: https://lore.kernel.org/rust-for-linux/aeCKlut-88SbNsyW@xxxxxxxxxx/
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
rust/kernel/ptr/projection.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/ptr/projection.rs b/rust/kernel/ptr/projection.rs
index fbe172e493c2..1b54616c6cbb 100644
--- a/rust/kernel/ptr/projection.rs
+++ b/rust/kernel/ptr/projection.rs
@@ -45,7 +45,10 @@ pub unsafe trait ProjectIndex<T: ?Sized>: Sized {
/// Returns an index-projected pointer; fail the build if it cannot be proved to be in bounds.
#[inline(always)]
fn build_index(self, slice: *mut T) -> *mut Self::Output {
- Self::get(self, slice).unwrap_or_else(|| build_error!())
+ match Self::get(self, slice) {
+ Some(v) => v,
+ None => build_error!(),
+ }
}
}
--
2.54.0