Skip to content

Commit

Permalink
Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett
Browse files Browse the repository at this point in the history
Fix char count in `Display` for `ByteStr`

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

r? ```````````@joshtriplett```````````
  • Loading branch information
compiler-errors authored Mar 6, 2025
2 parents 0013214 + b2bb7cc commit fe92638
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/core/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fe92638

Please sign in to comment.