Skip to content

Commit 39dcf36

Browse files
committed
fix: .unwrap() requires Err(E: Debug), a luxuary we cannot afford
1 parent e57fa6e commit 39dcf36

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

library/alloc/src/vec/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,16 @@ impl<T, A: Allocator> Vec<T, A> {
17611761
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
17621762
#[must_use]
17631763
pub fn into_array<const N: usize>(self) -> Result<Box<[T; N], A>, Self> {
1764-
if self.len() == N { Ok(self.into_boxed_slice().into_array().unwrap()) } else { Err(self) }
1764+
if self.len() == N {
1765+
unsafe {
1766+
let me = ManuallyDrop::new(self);
1767+
let buf = me.buf.ptr() as *mut [T; N];
1768+
let alloc = ptr::read(me.allocator());
1769+
Ok(Box::from_raw_in(buf, alloc))
1770+
}
1771+
} else {
1772+
Err(self)
1773+
}
17651774
}
17661775

17671776
/// Shortens the vector, keeping the first `len` elements and dropping

0 commit comments

Comments
 (0)