Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert heterogeneous SocketAddr PartialEq impls #73304

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 5 additions & 40 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,42 +694,6 @@ impl PartialEq for SocketAddrV6 {
&& self.inner.sin6_scope_id == other.inner.sin6_scope_id
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddrV4> for SocketAddr {
fn eq(&self, other: &SocketAddrV4) -> bool {
match self {
SocketAddr::V4(v4) => v4 == other,
SocketAddr::V6(_) => false,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddrV6> for SocketAddr {
fn eq(&self, other: &SocketAddrV6) -> bool {
match self {
SocketAddr::V4(_) => false,
SocketAddr::V6(v6) => v6 == other,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddr> for SocketAddrV4 {
fn eq(&self, other: &SocketAddr) -> bool {
match other {
SocketAddr::V4(v4) => self == v4,
SocketAddr::V6(_) => false,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddr> for SocketAddrV6 {
fn eq(&self, other: &SocketAddr) -> bool {
match other {
SocketAddr::V4(_) => false,
SocketAddr::V6(v6) => self == v6,
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for SocketAddrV4 {}
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1242,12 +1206,8 @@ mod tests {
// equality
assert_eq!(v4_1, v4_1);
assert_eq!(v6_1, v6_1);
assert_eq!(v4_1, SocketAddr::V4(v4_1));
assert_eq!(v6_1, SocketAddr::V6(v6_1));
assert_eq!(SocketAddr::V4(v4_1), SocketAddr::V4(v4_1));
assert_eq!(SocketAddr::V6(v6_1), SocketAddr::V6(v6_1));
assert!(v4_1 != SocketAddr::V6(v6_1));
assert!(v6_1 != SocketAddr::V4(v4_1));
assert!(v4_1 != v4_2);
assert!(v6_1 != v6_2);

Expand All @@ -1268,5 +1228,10 @@ mod tests {
assert!(v6_1 < v6_3);
assert!(v4_3 > v4_1);
assert!(v6_3 > v6_1);

// compare with an inferred right-hand side
assert_eq!(v4_1, "224.120.45.1:23456".parse().unwrap());
assert_eq!(v6_1, "[2001:db8:f00::1002]:23456".parse().unwrap());
assert_eq!(SocketAddr::V4(v4_1), "224.120.45.1:23456".parse().unwrap());
}
}