Use `match` to avoid potential inlining issues of the `unwrap_or_else` function.
Suggested-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/rust-for-linux/[email protected]/ Signed-off-by: Gary Guo <[email protected]> --- 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
