From: Gary Guo Date: Tue, 2 Jun 2026 14:17:53 +0000 (+0100) Subject: rust: ptr: use `match` instead of `unwrap_or_else` for `build_index` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dda19120a93a559681205fe0476908d8356d52c;p=thirdparty%2Flinux.git 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 --- diff --git a/rust/kernel/ptr/projection.rs b/rust/kernel/ptr/projection.rs index 441bc1b83c3f7..575e936f6d291 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!(), + } } }