Skip to content

Commit

Permalink
Rollup merge of rust-lang#73389 - lzutao:from, r=kennytm
Browse files Browse the repository at this point in the history
Use `Ipv4Addr::from<[u8; 4]>` when possible

Resolve this comment: rust-lang#73331 (comment)
  • Loading branch information
Dylan-DPC authored Jun 16, 2020
2 parents 2199aa0 + 0e6c333 commit 176d7eb
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/libstd/sys/hermit/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ impl TcpStream {
.map_err(|_| io::Error::new(ErrorKind::Other, "peer_addr failed"))?;

let saddr = match ipaddr {
Ipv4(ref addr) => SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
port,
),
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
_ => {
return Err(io::Error::new(ErrorKind::Other, "peer_addr failed"));
Expand Down Expand Up @@ -227,10 +224,7 @@ impl TcpListener {
let (handle, ipaddr, port) = abi::tcplistener::accept(self.0.port())
.map_err(|_| io::Error::new(ErrorKind::Other, "accept failed"))?;
let saddr = match ipaddr {
Ipv4(ref addr) => SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
port,
),
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
_ => {
return Err(io::Error::new(ErrorKind::Other, "accept failed"));
Expand Down

0 comments on commit 176d7eb

Please sign in to comment.