]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: ptr: use `match` instead of `unwrap_or_else` for `build_index`
authorGary Guo <gary@garyguo.net>
Tue, 2 Jun 2026 14:17:53 +0000 (15:17 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Fri, 5 Jun 2026 08:11:23 +0000 (10:11 +0200)
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>
rust/kernel/ptr/projection.rs

index 441bc1b83c3f7edc1f4bac4250255fd42dfce9b7..575e936f6d291f2361b6a5858bc3800fd7612e0d 100644 (file)
@@ -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!(),
+        }
     }
 }