Skip to content

Commit 4dda191

Browse files
nbdd0121ojeda
authored andcommitted
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>
1 parent 735bc1c commit 4dda191

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

rust/kernel/ptr/projection.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub unsafe trait ProjectIndex<T: ?Sized>: Sized {
4545
/// Returns an index-projected pointer; fail the build if it cannot be proved to be in bounds.
4646
#[inline(always)]
4747
fn build_index(self, slice: *mut T) -> *mut Self::Output {
48-
Self::get(self, slice).unwrap_or_else(|| build_error!())
48+
match Self::get(self, slice) {
49+
Some(v) => v,
50+
None => build_error!(),
51+
}
4952
}
5053
}
5154

0 commit comments

Comments
 (0)