diff options
| author | Thalia Archibald <thalia@archibald.dev> | 2025-02-27 19:06:06 -0800 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2025-02-27 19:06:06 -0800 |
| commit | b2bb7cc8ae45e8852e4b76fa10408a1eed626412 (patch) | |
| tree | c90365080342c62146296a76399792a2d416d166 | |
| parent | f45d4acf1bb635aa010f19f8a749eed8293203b3 (diff) | |
| download | rust-b2bb7cc8ae45e8852e4b76fa10408a1eed626412.tar.gz rust-b2bb7cc8ae45e8852e4b76fa10408a1eed626412.zip | |
Fix char count in Display for ByteStr
| -rw-r--r-- | library/core/src/bstr.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/bstr.rs b/library/core/src/bstr.rs index 74e07f3d242..ae84fd8adb6 100644 --- a/library/core/src/bstr.rs +++ b/library/core/src/bstr.rs @@ -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(); |
