diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b37f865020fd9..c3b86a635bd0f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1760,7 +1760,11 @@ impl Vec { #[must_use] pub fn into_array(self) -> Result, Self> { if self.len() == N { - Ok(self.into_boxed_slice().into_array().ok().unwrap()) + // SAFETY: `Box::into_array` is guaranteed to return `Ok` if the + // length of the slice is equal to `N`. + // `self.into_boxed_slice().len()` is equal to `self.len()`, + // which we just checked. + Ok(unsafe { self.into_boxed_slice().into_array().unwrap_unchecked() }) } else { Err(self) }