]> git.lizzy.rs Git - rust.git/commitdiff
Correctly estimate required space for string
authorAnthonyMikh <anthony.mikh@yandex.ru>
Sat, 5 Oct 2019 00:08:05 +0000 (03:08 +0300)
committerGitHub <noreply@github.com>
Sat, 5 Oct 2019 00:08:05 +0000 (03:08 +0300)
`.len()` returns length in bytes so it overestimates the required space

src/librustc_errors/styled_buffer.rs

index 6e03618d2b0b5f24b6d2296d5e9f60317284aaff..b12ab9e4576025c8efb7d17777df90fe7e94458b 100644 (file)
@@ -111,7 +111,7 @@ pub fn puts(&mut self, line: usize, col: usize, string: &str, style: Style) {
 
     pub fn prepend(&mut self, line: usize, string: &str, style: Style) {
         self.ensure_lines(line);
-        let string_len = string.len();
+        let string_len = string.chars().count();
 
         // Push the old content over to make room for new content
         for _ in 0..string_len {