diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-01-22 14:30:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-22 14:30:12 +0000 |
| commit | 950ed27e8bb8952fce24afbaf19dd1afa5368f83 (patch) | |
| tree | 82bb1b285bf4f74eae3237c4f73567bb87e7762c | |
| parent | b59f6e05eff31a8c0445ab3c955ed163dc37ce56 (diff) | |
| parent | 116b66ad491b3f0a5a809e49a6377d2697d0ed1b (diff) | |
| download | rust-950ed27e8bb8952fce24afbaf19dd1afa5368f83.tar.gz rust-950ed27e8bb8952fce24afbaf19dd1afa5368f83.zip | |
Rollup merge of #81202 - lzutao:dbg_ipv6, r=Amanieu
Don't prefix 0x for each segments in `dbg!(Ipv6)` Fixes #81182
| -rw-r--r-- | library/std/src/net/ip.rs | 8 | ||||
| -rw-r--r-- | library/std/src/net/ip/tests.rs | 3 |
2 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index d33b772633d..84449e48767 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1610,11 +1610,11 @@ impl fmt::Display for Ipv6Addr { /// Write a colon-separated part of the address #[inline] fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result { - if let Some(first) = chunk.first() { - fmt::LowerHex::fmt(first, f)?; - for segment in &chunk[1..] { + if let Some((first, tail)) = chunk.split_first() { + write!(f, "{:x}", first)?; + for segment in tail { f.write_char(':')?; - fmt::LowerHex::fmt(segment, f)?; + write!(f, "{:x}", segment)?; } } Ok(()) diff --git a/library/std/src/net/ip/tests.rs b/library/std/src/net/ip/tests.rs index 44fb3adf070..ef0d4edc434 100644 --- a/library/std/src/net/ip/tests.rs +++ b/library/std/src/net/ip/tests.rs @@ -166,6 +166,9 @@ fn ipv6_addr_to_string() { // two runs of zeros, equal length assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string()); + + // don't prefix `0x` to each segment in `dbg!`. + assert_eq!("1::4:5:0:0:8", &format!("{:#?}", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8))); } #[test] |
