Skip to content

Commit

Permalink
Remove an unnecessary use of unwrap_unchecked
Browse files Browse the repository at this point in the history
also add a new SAFETY comment and simplify/remove a closure
  • Loading branch information
steffahn authored and c410-f3r committed Sep 30, 2021
1 parent 13bfcb7 commit 355c7e9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,14 @@ unsafe fn collect_into_array_unchecked<I, const N: usize>(iter: &mut I) -> [I::I
where
I: Iterator + TrustedLen,
{
let mut map = iter.map(|el| Ok::<_, Infallible>(el));
let mut map = iter.map(Ok::<_, Infallible>);

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

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

0 comments on commit 355c7e9

Please sign in to comment.