From 4dda19120a93a559681205fe0476908d8356d52c Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Tue, 2 Jun 2026 15:17:53 +0100 Subject: [PATCH] rust: ptr: use `match` instead of `unwrap_or_else` for `build_index` Use `match` to avoid potential inlining issues of the `unwrap_or_else` function. Suggested-by: Alice Ryhl Link: https://lore.kernel.org/rust-for-linux/aeCKlut-88SbNsyW@google.com/ Signed-off-by: Gary Guo Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl Acked-by: Danilo Krummrich Link: https://patch.msgid.link/20260602-projection-syntax-rework-v2-2-6989470f5440@garyguo.net Signed-off-by: Miguel Ojeda --- 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 441bc1b83c3f..575e936f6d29 100644 --- a/rust/kernel/ptr/projection.rs +++ b/rust/kernel/ptr/projection.rs @@ -45,7 +45,10 @@ pub unsafe trait ProjectIndex: 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!(), + } } }