diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-22 15:32:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-22 15:32:12 +0200 |
| commit | 1d7faafe47a3d34ef854609e7b4a5e48cc66e7a9 (patch) | |
| tree | a3689c79a5f230b64cb6a34dd5b99e72122458b6 /src/libstd | |
| parent | 2567af67a6a0973937bc65f89f8b002829efad7a (diff) | |
| parent | 7c1e4054787f99dff36aa66318b7589f78dfc7d9 (diff) | |
| download | rust-1d7faafe47a3d34ef854609e7b4a5e48cc66e7a9.tar.gz rust-1d7faafe47a3d34ef854609e7b4a5e48cc66e7a9.zip | |
Rollup merge of #62746 - RalfJung:deprecated, r=KodrAus
do not use assume_init in std::io Cc https://github.com/rust-lang/rust/issues/62397
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/util.rs | 24 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sync/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/cloudabi/mod.rs | 2 |
4 files changed, 14 insertions, 16 deletions
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 1efccb53b75..33cc87eb795 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -2,7 +2,7 @@ use crate::fmt; use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoSlice, IoSliceMut}; -use crate::mem; +use crate::mem::MaybeUninit; /// Copies the entire contents of a reader into a writer. /// @@ -43,27 +43,23 @@ use crate::mem; pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64> where R: Read, W: Write { - let mut buf = unsafe { - // 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 buf = MaybeUninit::<[u8; super::DEFAULT_BUF_SIZE]>::uninit(); + // FIXME(#53491): This is calling `get_mut` and `get_ref` on an uninitialized + // `MaybeUninit`. Revisit this once we decided whether that is valid or not. + // 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. + unsafe { reader.initializer().initialize(buf.get_mut()); } let mut written = 0; loop { - let len = match reader.read(&mut buf) { + let len = match reader.read(unsafe { buf.get_mut() }) { Ok(0) => return Ok(written), Ok(len) => len, Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, Err(e) => return Err(e), }; - writer.write_all(&buf[..len])?; + writer.write_all(unsafe { &buf.get_ref()[..len] })?; written += len as u64; } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f394195d77a..49fb4be39b4 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -205,7 +205,7 @@ // Don't link to std. We are std. #![no_std] -//#![warn(deprecated_in_future)] // FIXME: std still has quite a few uses of `mem::uninitialized` +#![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings @@ -272,6 +272,7 @@ #![feature(libc)] #![feature(link_args)] #![feature(linkage)] +#![feature(maybe_uninit_ref)] #![feature(mem_take)] #![feature(needs_panic_runtime)] #![feature(never_type)] diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index fd6e46fd61d..e29faf18d83 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -163,6 +163,7 @@ pub use self::condvar::{Condvar, WaitTimeoutResult}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::mutex::{Mutex, MutexGuard}; #[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(bootstrap, allow(deprecated_in_future))] #[allow(deprecated)] pub use self::once::{Once, OnceState, ONCE_INIT}; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/cloudabi/mod.rs b/src/libstd/sys/cloudabi/mod.rs index 3fef7552259..77a52a8743d 100644 --- a/src/libstd/sys/cloudabi/mod.rs +++ b/src/libstd/sys/cloudabi/mod.rs @@ -1,4 +1,4 @@ -#![allow(deprecated)] // mem::uninitialized +#![allow(deprecated_in_future)] // mem::uninitialized; becomes `deprecated` when nightly is 1.39 use crate::io::ErrorKind; use crate::mem; |
