Skip to content

Commit

Permalink
Update Other errors to HostUnreachable
Browse files Browse the repository at this point in the history
Rust 1.83 has dropped and with it comes new error kinds!
  • Loading branch information
brandonpike committed Nov 30, 2024
1 parent 49a7038 commit a46830f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ categories = ["asynchronous", "network-programming", "simulation"]
[workspace]
members = ["examples/*"]

[workspace.package]
rust-version = "1.83"

[dependencies]
bytes = "1.4"
futures = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl ToIpAddr for String {
}
}

impl<'a> ToIpAddr for &'a str {
impl ToIpAddr for &'_ str {
fn to_ip_addr(&self, dns: &mut Dns) -> IpAddr {
if let Ok(ipaddr) = self.parse() {
return ipaddr;
Expand Down Expand Up @@ -121,7 +121,7 @@ impl ToSocketAddrs for (String, u16) {
}
}

impl<'a> ToSocketAddrs for (&'a str, u16) {
impl ToSocketAddrs for (&'_ str, u16) {
fn to_socket_addr(&self, dns: &Dns) -> SocketAddr {
// When IP address is passed directly as a str.
if let Ok(ip) = self.0.parse::<IpAddr>() {
Expand Down
2 changes: 1 addition & 1 deletion src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ mod test {
sim.client("client", async move {
// Peers are partitioned. TCP setup should fail.
let err = TcpStream::connect("server:1234").await.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::Other);
assert_eq!(err.kind(), io::ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down
10 changes: 3 additions & 7 deletions src/top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct LinkIter<'a> {
iter: std::collections::vec_deque::IterMut<'a, Sent>,
}

impl<'a> LinkIter<'a> {
impl LinkIter<'_> {
/// The [`IpAddr`] pair for the link. Always ordered to uniquely identify
/// the link.
pub fn pair(&self) -> (IpAddr, IpAddr) {
Expand All @@ -84,7 +84,7 @@ pub struct SentRef<'a> {
sent: &'a mut Sent,
}

impl<'a> SentRef<'a> {
impl SentRef<'_> {
/// The (src, dst) [`SocketAddr`] pair for the message.
pub fn pair(&self) -> (SocketAddr, SocketAddr) {
(self.src, self.dst)
Expand Down Expand Up @@ -243,11 +243,7 @@ impl Topology {
link.enqueue_message(&self.config, rand, src, dst, message);
Ok(())
} else {
// TODO: `ErrorKind::Other` is incorrect here, but
// `ErrorKind::HostUnreachable` has not been stabilized.
//
// See: https://github.com/rust-lang/rust/issues/86442
Err(Error::new(ErrorKind::Other, "host unreachable"))
Err(Error::new(ErrorKind::HostUnreachable, "host unreachable"))
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn network_partitions_during_connect() -> Result {
turmoil::partition("client", "server");

let err = TcpStream::connect(("server", PORT)).await.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::Other);
assert_eq!(err.kind(), io::ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

turmoil::repair("client", "server");
Expand Down Expand Up @@ -220,7 +220,7 @@ fn network_partition_once_connected() -> Result {
assert!(timeout(Duration::from_secs(1), s.read_u8()).await.is_err());

let err = s.write_u8(1).await.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::Other);
assert_eq!(err.kind(), io::ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand All @@ -232,7 +232,7 @@ fn network_partition_once_connected() -> Result {
turmoil::partition("server", "client");

let err = s.write_u8(1).await.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::Other);
assert_eq!(err.kind(), io::ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down Expand Up @@ -1129,7 +1129,7 @@ fn socket_to_nonexistent_node() -> Result {
);

let err = sock.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::Other);
assert_eq!(err.kind(), io::ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions tests/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn network_partition() -> Result {

let sock = bind().await?;
let err = send_ping(&sock).await.unwrap_err();
assert_eq!(err.kind(), ErrorKind::Other);
assert_eq!(err.kind(), ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down Expand Up @@ -562,7 +562,7 @@ fn loopback_localhost_public_v4() -> Result {
let bind_addr = SocketAddr::new(bind_addr.ip(), 0);
let socket = UdpSocket::bind(bind_addr).await?;
let err = socket.send_to(&expected, connect_addr).await.unwrap_err();
assert_eq!(err.kind(), ErrorKind::Other);
assert_eq!(err.kind(), ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down Expand Up @@ -614,7 +614,7 @@ fn loopback_localhost_public_v6() -> Result {
let bind_addr = SocketAddr::new(bind_addr.ip(), 0);
let socket = UdpSocket::bind(bind_addr).await?;
let err = socket.send_to(&expected, connect_addr).await.unwrap_err();
assert_eq!(err.kind(), ErrorKind::Other);
assert_eq!(err.kind(), ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down Expand Up @@ -723,7 +723,7 @@ fn socket_to_nonexistent_node() -> Result {
);

let err = send.unwrap_err();
assert_eq!(err.kind(), ErrorKind::Other);
assert_eq!(err.kind(), ErrorKind::HostUnreachable);
assert_eq!(err.to_string(), "host unreachable");

Ok(())
Expand Down

0 comments on commit a46830f

Please sign in to comment.