Rollup merge of #62732 - nathanwhit:fix_mem_uninit, r=Amanieu

Remove last use of mem::uninitialized from std::io::util

Addresses #62397 for std::io::util
This commit is contained in:
Mark Rousskov 2019-07-18 11:29:45 -04:00 committed by GitHub
commit 5d4681f76a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,10 +44,15 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
where R: Read, W: Write
{
let mut buf = unsafe {
#[allow(deprecated)]
let mut buf: [u8; super::DEFAULT_BUF_SIZE] = mem::uninitialized();
reader.initializer().initialize(&mut buf);
buf
// This is still technically undefined behavior due to creating a reference
// to uninitialized data, but within libstd we can rely on more guarantees
// than if this code were in an external lib
// FIXME: This should probably be changed to an array of `MaybeUninit<u8>`
// once the `mem::MaybeUninit` slice APIs stabilize
let mut buf: mem::MaybeUninit<[u8; super::DEFAULT_BUF_SIZE]> = mem::MaybeUninit::uninit();
reader.initializer().initialize(&mut *buf.as_mut_ptr());
buf.assume_init()
};
let mut written = 0;