From 3f2e471b493f37be732bf68ca780a2d502efb9fc Mon Sep 17 00:00:00 2001 From: Mitchell Kember Date: Fri, 30 Jun 2023 20:45:11 +0000 Subject: [PATCH] [net-types] Change IP Display to match rust #112606 This CL changes the Display impl for net_types::ip::Ipv6Addr to match std::net::Ipv6Addr and re-enables the `test_ipv6_display` test which was disabled in Ie459a53094b958b752e75e5cf86baa6f55bdade6. The change follows https://github.com/rust-lang/rust/pull/112606, which stops formatting IPv4-compatible addresses as "::a.b.c.d". IPv4-mapped addresses continue to be treated specially ("::ffff:a.b.c.d"). Test: fx test net_types_lib_test -- ip::tests::test_ipv6_display Bug: 126927 Change-Id: I854f2bf8ba42b3e1eedceb2a5a70e8ca1da17a4b Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/873716 Reviewed-by: Joshua Liebow-Feeser Commit-Queue: Mitchell Kember --- src/connectivity/lib/net-types/src/ip.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/connectivity/lib/net-types/src/ip.rs b/src/connectivity/lib/net-types/src/ip.rs index 7c3035e95e2..e558f56665f 100644 --- a/src/connectivity/lib/net-types/src/ip.rs +++ b/src/connectivity/lib/net-types/src/ip.rs @@ -1933,16 +1933,13 @@ impl Display for Ipv6Addr { // by creating a scratch buffer, calling `fmt_inner` on that scratch // buffer, and then satisfying those requirements. fn fmt_inner(addr: &Ipv6Addr, w: &mut W) -> Result<(), fmt::Error> { - // We special-case the unspecified and localhost addresses because - // both addresses are valid IPv4-compatible addresses, and so if we - // don't special case them, they'll get printed as IPv4-compatible - // addresses ("::0.0.0.0" and "::0.0.0.1") respectively. + // We special-case the unspecified address, localhost address, and + // IPv4-mapped addresses, but not IPv4-compatible addresses. We + // follow Rust's behavior here: https://github.com/rust-lang/rust/pull/112606 if !addr.is_specified() { write!(w, "::") } else if addr.is_loopback() { write!(w, "::1") - } else if let Some(v4) = addr.to_ipv4_compatible() { - write!(w, "::{}", v4) } else if let Some(v4) = addr.to_ipv4_mapped() { write!(w, "::ffff:{}", v4) } else { @@ -3658,9 +3655,6 @@ mod tests { } #[test] - // TODO(fxbug.dev/129316): Temporarily disabled for toolchain roll. - // Change to match https://github.com/rust-lang/rust/pull/112606 and re-enable. - #[ignore] fn test_ipv6_display() { // Test that `addr` is formatted the same by our `Display` impl as by // the standard library's `Display` impl. Optionally test that it