Skip to content

Commit 950ed27

Browse files
authored
Rollup merge of #81202 - lzutao:dbg_ipv6, r=Amanieu
Don't prefix 0x for each segments in `dbg!(Ipv6)` Fixes #81182
2 parents b59f6e0 + 116b66a commit 950ed27

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

library/std/src/net/ip.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1610,11 +1610,11 @@ impl fmt::Display for Ipv6Addr {
16101610
/// Write a colon-separated part of the address
16111611
#[inline]
16121612
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
1613-
if let Some(first) = chunk.first() {
1614-
fmt::LowerHex::fmt(first, f)?;
1615-
for segment in &chunk[1..] {
1613+
if let Some((first, tail)) = chunk.split_first() {
1614+
write!(f, "{:x}", first)?;
1615+
for segment in tail {
16161616
f.write_char(':')?;
1617-
fmt::LowerHex::fmt(segment, f)?;
1617+
write!(f, "{:x}", segment)?;
16181618
}
16191619
}
16201620
Ok(())

library/std/src/net/ip/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ fn ipv6_addr_to_string() {
166166

167167
// two runs of zeros, equal length
168168
assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string());
169+
170+
// don't prefix `0x` to each segment in `dbg!`.
171+
assert_eq!("1::4:5:0:0:8", &format!("{:#?}", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8)));
169172
}
170173

171174
#[test]

0 commit comments

Comments
 (0)