about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-08-31 09:38:36 -0700
committerGitHub <noreply@github.com>2016-08-31 09:38:36 -0700
commit7a187c39c79e21cd61d1688d449bdd52d7510281 (patch)
treeaedca39b638efcfef2c175d3d0e86234a9d9d61c /src/libstd
parent824000aee3b9fd594a3da3eb38462fa341f0fa81 (diff)
parent0cb507394e15e131b681ab975eda51a69501982c (diff)
downloadrust-7a187c39c79e21cd61d1688d449bdd52d7510281.tar.gz
rust-7a187c39c79e21cd61d1688d449bdd52d7510281.zip
Auto merge of #36166 - jonathandturner:rollup, r=jonathandturner
Rollup of 16 pull requests

- Successful merges: #35758, #35926, #36050, #36079, #36085, #36089, #36101, #36130, #36134, #36135, #36136, #36140, #36141, #36147, #36148, #36165
- Failed merges:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/net/tcp.rs9
-rw-r--r--src/libstd/path.rs81
2 files changed, 82 insertions, 8 deletions
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs
index dcd3652af87..3c5f07c3e33 100644
--- a/src/libstd/net/tcp.rs
+++ b/src/libstd/net/tcp.rs
@@ -45,7 +45,6 @@ pub struct TcpStream(net_imp::TcpStream);
 ///
 /// ```no_run
 /// use std::net::{TcpListener, TcpStream};
-/// use std::thread;
 ///
 /// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
 ///
@@ -57,17 +56,11 @@ pub struct TcpStream(net_imp::TcpStream);
 /// for stream in listener.incoming() {
 ///     match stream {
 ///         Ok(stream) => {
-///             thread::spawn(move|| {
-///                 // connection succeeded
-///                 handle_client(stream)
-///             });
+///             handle_client(stream);
 ///         }
 ///         Err(e) => { /* connection failed */ }
 ///     }
 /// }
-///
-/// // close the socket server
-/// drop(listener);
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct TcpListener(net_imp::TcpListener);
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 67219b6fd1b..dbf17b3c813 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -639,6 +639,25 @@ pub struct Iter<'a> {
     inner: Components<'a>,
 }
 
+#[stable(feature = "path_components_debug", since = "1.13.0")]
+impl<'a> fmt::Debug for Components<'a> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        struct DebugHelper<'a>(&'a Path);
+
+        impl<'a> fmt::Debug for DebugHelper<'a> {
+            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+                f.debug_list()
+                    .entries(self.0.components())
+                    .finish()
+            }
+        }
+
+        f.debug_tuple("Components")
+            .field(&DebugHelper(self.as_path()))
+            .finish()
+    }
+}
+
 impl<'a> Components<'a> {
     // how long is the prefix, if any?
     #[inline]
@@ -818,6 +837,25 @@ impl<'a> AsRef<OsStr> for Components<'a> {
     }
 }
 
+#[stable(feature = "path_iter_debug", since = "1.13.0")]
+impl<'a> fmt::Debug for Iter<'a> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        struct DebugHelper<'a>(&'a Path);
+
+        impl<'a> fmt::Debug for DebugHelper<'a> {
+            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+                f.debug_list()
+                    .entries(self.0.iter())
+                    .finish()
+            }
+        }
+
+        f.debug_tuple("Iter")
+            .field(&DebugHelper(self.as_path()))
+            .finish()
+    }
+}
+
 impl<'a> Iter<'a> {
     /// Extracts a slice corresponding to the portion of the path remaining for iteration.
     #[stable(feature = "rust1", since = "1.0.0")]
@@ -3483,4 +3521,47 @@ mod tests {
                 );
         }
     }
+
+    #[test]
+    fn test_components_debug() {
+        let path = Path::new("/tmp");
+
+        let mut components = path.components();
+
+        let expected = "Components([RootDir, Normal(\"tmp\")])";
+        let actual = format!("{:?}", components);
+        assert_eq!(expected, actual);
+
+        let _ = components.next().unwrap();
+        let expected = "Components([Normal(\"tmp\")])";
+        let actual = format!("{:?}", components);
+        assert_eq!(expected, actual);
+
+        let _ = components.next().unwrap();
+        let expected = "Components([])";
+        let actual = format!("{:?}", components);
+        assert_eq!(expected, actual);
+    }
+
+    #[cfg(unix)]
+    #[test]
+    fn test_iter_debug() {
+        let path = Path::new("/tmp");
+
+        let mut iter = path.iter();
+
+        let expected = "Iter([\"/\", \"tmp\"])";
+        let actual = format!("{:?}", iter);
+        assert_eq!(expected, actual);
+
+        let _ = iter.next().unwrap();
+        let expected = "Iter([\"tmp\"])";
+        let actual = format!("{:?}", iter);
+        assert_eq!(expected, actual);
+
+        let _ = iter.next().unwrap();
+        let expected = "Iter([])";
+        let actual = format!("{:?}", iter);
+        assert_eq!(expected, actual);
+    }
 }