Skip to content

Commit a539574

Browse files
authored
Rollup merge of rust-lang#73304 - dtolnay:socketeq, r=Mark-Simulacrum
Revert heterogeneous SocketAddr PartialEq impls Originally added in rust-lang#72239. These lead to inference regressions (mostly in tests) in code that looks like: ```rust let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); ``` That compiles as of stable 1.44.0 but fails in beta with: ```console error[E0284]: type annotations needed --> src/main.rs:3:41 | 3 | assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); | ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse` | = note: cannot satisfy `<_ as std::str::FromStr>::Err == _` help: consider specifying the type argument in the method call | 3 | assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap()); | ``` Closes rust-lang#73242.
2 parents e4d096b + 204c236 commit a539574

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

src/libstd/net/addr.rs

+5-40
Original file line numberDiff line numberDiff line change
@@ -694,42 +694,6 @@ impl PartialEq for SocketAddrV6 {
694694
&& self.inner.sin6_scope_id == other.inner.sin6_scope_id
695695
}
696696
}
697-
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
698-
impl PartialEq<SocketAddrV4> for SocketAddr {
699-
fn eq(&self, other: &SocketAddrV4) -> bool {
700-
match self {
701-
SocketAddr::V4(v4) => v4 == other,
702-
SocketAddr::V6(_) => false,
703-
}
704-
}
705-
}
706-
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
707-
impl PartialEq<SocketAddrV6> for SocketAddr {
708-
fn eq(&self, other: &SocketAddrV6) -> bool {
709-
match self {
710-
SocketAddr::V4(_) => false,
711-
SocketAddr::V6(v6) => v6 == other,
712-
}
713-
}
714-
}
715-
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
716-
impl PartialEq<SocketAddr> for SocketAddrV4 {
717-
fn eq(&self, other: &SocketAddr) -> bool {
718-
match other {
719-
SocketAddr::V4(v4) => self == v4,
720-
SocketAddr::V6(_) => false,
721-
}
722-
}
723-
}
724-
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
725-
impl PartialEq<SocketAddr> for SocketAddrV6 {
726-
fn eq(&self, other: &SocketAddr) -> bool {
727-
match other {
728-
SocketAddr::V4(_) => false,
729-
SocketAddr::V6(v6) => self == v6,
730-
}
731-
}
732-
}
733697
#[stable(feature = "rust1", since = "1.0.0")]
734698
impl Eq for SocketAddrV4 {}
735699
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1242,12 +1206,8 @@ mod tests {
12421206
// equality
12431207
assert_eq!(v4_1, v4_1);
12441208
assert_eq!(v6_1, v6_1);
1245-
assert_eq!(v4_1, SocketAddr::V4(v4_1));
1246-
assert_eq!(v6_1, SocketAddr::V6(v6_1));
12471209
assert_eq!(SocketAddr::V4(v4_1), SocketAddr::V4(v4_1));
12481210
assert_eq!(SocketAddr::V6(v6_1), SocketAddr::V6(v6_1));
1249-
assert!(v4_1 != SocketAddr::V6(v6_1));
1250-
assert!(v6_1 != SocketAddr::V4(v4_1));
12511211
assert!(v4_1 != v4_2);
12521212
assert!(v6_1 != v6_2);
12531213

@@ -1268,5 +1228,10 @@ mod tests {
12681228
assert!(v6_1 < v6_3);
12691229
assert!(v4_3 > v4_1);
12701230
assert!(v6_3 > v6_1);
1231+
1232+
// compare with an inferred right-hand side
1233+
assert_eq!(v4_1, "224.120.45.1:23456".parse().unwrap());
1234+
assert_eq!(v6_1, "[2001:db8:f00::1002]:23456".parse().unwrap());
1235+
assert_eq!(SocketAddr::V4(v4_1), "224.120.45.1:23456".parse().unwrap());
12711236
}
12721237
}

0 commit comments

Comments
 (0)