From 7f9e653a299209c17d0093934973fc121e972d29 Mon Sep 17 00:00:00 2001 From: leavehouse Date: Thu, 28 Sep 2017 20:09:31 -0500 Subject: [PATCH 1/2] Fix TcpStream::local_addr example code The local address's port is not 8080 in this example, that's the remote peer address port. On my machine, the local address is different every time, so I've changed `assert_eq` to only test the IP address --- src/libstd/net/tcp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index aff9af66444c4..2497f38f38c9b 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -198,8 +198,8 @@ impl TcpStream { /// /// let stream = TcpStream::connect("127.0.0.1:8080") /// .expect("Couldn't connect to the server..."); - /// assert_eq!(stream.local_addr().unwrap(), - /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080))); + /// assert_eq!(stream.local_addr().unwrap().ip(), + /// IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn local_addr(&self) -> io::Result { From 6482ee7cde565a432980036abe521e86bff432bd Mon Sep 17 00:00:00 2001 From: leavehouse Date: Thu, 28 Sep 2017 21:49:00 -0500 Subject: [PATCH 2/2] Fix imports in TcpStream::local_addr docs example Add a missing import and remove unused imports --- src/libstd/net/tcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 2497f38f38c9b..cf3b354847c83 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -194,7 +194,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpStream}; + /// use std::net::{IpAddr, Ipv4Addr, TcpStream}; /// /// let stream = TcpStream::connect("127.0.0.1:8080") /// .expect("Couldn't connect to the server...");