about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-07-22 17:08:25 +0000
committerbors <bors@rust-lang.org>2019-07-22 17:08:25 +0000
commite649e903440bfd919bfc9db848c28df6d795a116 (patch)
treed182bd52c502a10edf0c1f8dfd172f1081685ac2 /src/libstd
parent4bc1ce7bdb7f5dc9ea07c0b630c087d8e11140e4 (diff)
parent376382aff3e8dad93b273ce7e9231ec7946edbe0 (diff)
downloadrust-e649e903440bfd919bfc9db848c28df6d795a116.tar.gz
rust-e649e903440bfd919bfc9db848c28df6d795a116.zip
Auto merge of #62873 - Centril:rollup-ncnuelj, r=Centril
Rollup of 14 pull requests

Successful merges:

 - #62709 (Test that maplike FromIter satisfies uniqueness)
 - #62713 (Stabilize <*mut _>::cast and <*const _>::cast)
 - #62746 ( do not use assume_init in std::io)
 - #62787 (Fix typo in src/libstd/net/udp.rs doc comment)
 - #62788 (normalize use of backticks in compiler messages for libcore/ptr)
 - #62799 (use const array repeat expressions for uninit_array)
 - #62810 (normalize use of backticks in compiler messages for librustc_lint)
 - #62812 (normalize use of backticks in compiler messages for librustc_metadata)
 - #62832 (normalize use of backticks in compiler messages for librustc_incremental)
 - #62845 (read: fix doc comment)
 - #62853 (normalize use of backticks in compiler messages for librustc/hir)
 - #62854 (Fix typo in Unicode character name)
 - #62858 (Change wrong variable name.)
 - #62870 (fix lexing of comments with many \r)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs4
-rw-r--r--src/libstd/collections/hash/set.rs4
-rw-r--r--src/libstd/io/mod.rs4
-rw-r--r--src/libstd/io/util.rs24
-rw-r--r--src/libstd/lib.rs3
-rw-r--r--src/libstd/net/udp.rs4
-rw-r--r--src/libstd/sync/mod.rs1
-rw-r--r--src/libstd/sys/cloudabi/mod.rs2
8 files changed, 24 insertions, 22 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 2925d8362c8..1e28ee8da26 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -3138,13 +3138,15 @@ mod test_map {
 
     #[test]
     fn test_from_iter() {
-        let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
+        let xs = [(1, 1), (2, 2), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
 
         let map: HashMap<_, _> = xs.iter().cloned().collect();
 
         for &(k, v) in &xs {
             assert_eq!(map.get(&k), Some(&v));
         }
+
+        assert_eq!(map.iter().len(), xs.len() - 1);
     }
 
     #[test]
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index 403914c0707..d243412405a 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -1782,13 +1782,15 @@ mod test_set {
 
     #[test]
     fn test_from_iter() {
-        let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9];
+        let xs = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9];
 
         let set: HashSet<_> = xs.iter().cloned().collect();
 
         for x in &xs {
             assert!(set.contains(x));
         }
+
+        assert_eq!(set.iter().len(), xs.len() - 1);
     }
 
     #[test]
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index a8d4d1181aa..e951b575773 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -511,8 +511,8 @@ pub trait Read {
     ///
     /// Correspondingly, however, *callers* of this method may not assume any guarantees
     /// about how the implementation uses `buf`. The trait is safe to implement,
-    //  so it is possible that the code that's supposed to write to the buffer might also read
-    //  from it. It is your responsibility to make sure that `buf` is initialized
+    /// so it is possible that the code that's supposed to write to the buffer might also read
+    /// from it. It is your responsibility to make sure that `buf` is initialized
     /// before calling `read`. Calling `read` with an uninitialized `buf` (of the kind one
     /// obtains via [`MaybeUninit<T>`]) is not safe, and can lead to undefined behavior.
     ///
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/net/udp.rs b/src/libstd/net/udp.rs
index 61d9149952e..c430e103951 100644
--- a/src/libstd/net/udp.rs
+++ b/src/libstd/net/udp.rs
@@ -422,7 +422,7 @@ impl UdpSocket {
     /// Sets the value of the `IP_MULTICAST_LOOP` option for this socket.
     ///
     /// If enabled, multicast packets will be looped back to the local socket.
-    /// Note that this may not have any affect on IPv6 sockets.
+    /// Note that this may not have any effect on IPv6 sockets.
     ///
     /// # Examples
     ///
@@ -464,7 +464,7 @@ impl UdpSocket {
     /// this socket. The default value is 1 which means that multicast packets
     /// don't leave the local network unless explicitly requested.
     ///
-    /// Note that this may not have any affect on IPv6 sockets.
+    /// Note that this may not have any effect on IPv6 sockets.
     ///
     /// # Examples
     ///
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;