Skip to content

Commit 355c7e9

Browse files
steffahnc410-f3r
authored andcommitted
Remove an unnecessary use of unwrap_unchecked
also add a new SAFETY comment and simplify/remove a closure
1 parent 13bfcb7 commit 355c7e9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/core/src/array/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,14 @@ unsafe fn collect_into_array_unchecked<I, const N: usize>(iter: &mut I) -> [I::I
533533
where
534534
I: Iterator + TrustedLen,
535535
{
536-
let mut map = iter.map(|el| Ok::<_, Infallible>(el));
536+
let mut map = iter.map(Ok::<_, Infallible>);
537537

538-
// SAFETY: Valid array elements are covered by the fact that all passed values
539-
// to `collect_into_array` are `Ok`.
540-
unsafe { collect_into_array_rslt_unchecked(&mut map).unwrap_unchecked() }
538+
// SAFETY: The same safety considerations w.r.t. the iterator length
539+
// apply for `collect_into_array_rslt_unchecked` as for
540+
// `collect_into_array_unchecked`
541+
match unsafe { collect_into_array_rslt_unchecked(&mut map) } {
542+
Ok(array) => array,
543+
}
541544
}
542545

543546
/// Pulls `N` items from `iter` and returns them as an array. If the iterator

0 commit comments

Comments
 (0)