aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
authorGary Guo <gary@garyguo.net>2026-06-02 15:17:53 +0100
committerMiguel Ojeda <ojeda@kernel.org>2026-06-05 10:11:23 +0200
commit4dda19120a93a559681205fe0476908d8356d52c (patch)
tree5c60e05d8fbbb2bb8e9c50ff1641bc214dd64834 /rust
parent735bc1c843101aa2383061acb73d3824c7a66e11 (diff)
downloadath-4dda19120a93a559681205fe0476908d8356d52c.tar.gz
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 <aliceryhl@google.com> Link: https://lore.kernel.org/rust-for-linux/aeCKlut-88SbNsyW@google.com/ Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260602-projection-syntax-rework-v2-2-6989470f5440@garyguo.net Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/ptr/projection.rs5
1 files changed, 4 insertions, 1 deletions
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<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!(),
+ }
}
}