Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett

Fix char count in `Display` for `ByteStr`

`ByteStr as Display` performs a byte count when a char count is required.

r? ```````````@joshtriplett```````````
This commit is contained in:
Michael Goulet 2025-03-06 12:22:16 -05:00 committed by GitHub
commit fe926384c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,7 +151,9 @@ impl fmt::Display for ByteStr {
};
let nchars: usize = self
.utf8_chunks()
.map(|chunk| chunk.valid().len() + if chunk.invalid().is_empty() { 0 } else { 1 })
.map(|chunk| {
chunk.valid().chars().count() + if chunk.invalid().is_empty() { 0 } else { 1 }
})
.sum();
let padding = f.width().unwrap_or(0).saturating_sub(nchars);
let fill = f.fill();