Skip to content

Commit 7eeb0e7

Browse files
wutchzoneojeda
authored andcommitted
rust: init: replace unwraps with question mark operators
Use `?` operator in the doctests. Since it is in the examples, using unwraps can convey a wrong impression that unwrapping is fine in general, thus this patch removes this unwrapping. Suggested-by: Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/rust-for-linux/CANiq72nsK1D4NuQ1U7NqMWoYjXkqQSj4QuUEL98OmFbq022Z9A@mail.gmail.com/ Signed-off-by: Daniel Sedlak <daniel@sedlak.dev> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241123095033.41240-2-daniel@sedlak.dev [ Reworded commit slightly. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 0730422 commit 7eeb0e7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rust/kernel/init.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,9 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
10761076
/// ```rust
10771077
/// use kernel::{alloc::KBox, error::Error, init::init_array_from_fn};
10781078
/// let array: KBox<[usize; 1_000]> =
1079-
/// KBox::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
1079+
/// KBox::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL)?;
10801080
/// assert_eq!(array.len(), 1_000);
1081+
/// # Ok::<(), Error>(())
10811082
/// ```
10821083
pub fn init_array_from_fn<I, const N: usize, T, E>(
10831084
mut make_init: impl FnMut(usize) -> I,
@@ -1120,8 +1121,9 @@ where
11201121
/// ```rust
11211122
/// use kernel::{sync::{Arc, Mutex}, init::pin_init_array_from_fn, new_mutex};
11221123
/// let array: Arc<[Mutex<usize>; 1_000]> =
1123-
/// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i)), GFP_KERNEL).unwrap();
1124+
/// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i)), GFP_KERNEL)?;
11241125
/// assert_eq!(array.len(), 1_000);
1126+
/// # Ok::<(), Error>(())
11251127
/// ```
11261128
pub fn pin_init_array_from_fn<I, const N: usize, T, E>(
11271129
mut make_init: impl FnMut(usize) -> I,

0 commit comments

Comments
 (0)