diff options
| author | AnthonyMikh <anthony.mikh@yandex.ru> | 2019-09-25 23:23:19 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-25 23:23:19 +0300 |
| commit | d6327e8f12cc51254d62e6755f67ea580fc4dd21 (patch) | |
| tree | b5b4a271c050f534440735ffec4319e8008a967d | |
| parent | 4fc5650d17794c00fbf03597b35979de7094d386 (diff) | |
| download | rust-d6327e8f12cc51254d62e6755f67ea580fc4dd21.tar.gz rust-d6327e8f12cc51254d62e6755f67ea580fc4dd21.zip | |
Use map + sum instead of fold for computing Unicode width
| -rw-r--r-- | src/librustc_errors/emitter.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 151c06ddbbd..17a5fac6da7 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -594,9 +594,9 @@ impl EmitterWriter { let left = margin.left(source_string.len()); // Left trim // Account for unicode characters of width !=0 that were removed. - let left = source_string.chars().take(left).fold(0, |acc, ch| { - acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1) - }); + let left = source_string.chars().take(left) + .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .sum(); self.draw_line( buffer, @@ -1512,9 +1512,9 @@ impl EmitterWriter { .saturating_sub(part.snippet.trim_start().len()); // ...or trailing spaces. Account for substitutions containing unicode // characters. - let sub_len = part.snippet.trim().chars().fold(0, |acc, ch| { - acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1) - }); + let sub_len = part.snippet.trim().chars() + .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .sum(); let underline_start = (span_start_pos + start) as isize + offset; let underline_end = (span_start_pos + start + sub_len) as isize + offset; @@ -1535,9 +1535,9 @@ impl EmitterWriter { } // length of the code after substitution - let full_sub_len = part.snippet.chars().fold(0, |acc, ch| { - acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1) as isize - }); + let full_sub_len = part.snippet.chars() + .map(|ch| acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .sum() as isize; // length of the code to be substituted let snippet_len = span_end_pos as isize - span_start_pos as isize; |
