about summary refs log tree commit diff
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-07-29 18:35:11 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-07-29 19:03:25 +0000
commit3945480ce7b93eefc2fec90bb87bc53a19e30f96 (patch)
treecb1c10ec28134b457e2420891d5031efdcae750a /compiler/rustc_errors
parent6d9ee6ee26c296d9361d5f0fb479b2462687fe4e (diff)
downloadrust-3945480ce7b93eefc2fec90bb87bc53a19e30f96.tar.gz
rust-3945480ce7b93eefc2fec90bb87bc53a19e30f96.zip
Use `fold` instead of `flat_map`
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/Cargo.toml1
-rw-r--r--compiler/rustc_errors/src/emitter.rs16
2 files changed, 8 insertions, 9 deletions
diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml
index ddf72a2d5fd..2fff9f2de50 100644
--- a/compiler/rustc_errors/Cargo.toml
+++ b/compiler/rustc_errors/Cargo.toml
@@ -7,7 +7,6 @@ edition = "2021"
 # tidy-alphabetical-start
 annotate-snippets = "0.10"
 derive_setters = "0.1.6"
-either = "1.5.0"
 rustc_ast = { path = "../rustc_ast" }
 rustc_ast_pretty = { path = "../rustc_ast_pretty" }
 rustc_data_structures = { path = "../rustc_data_structures" }
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index d186996040b..18e077ed8a2 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -16,7 +16,6 @@ use std::iter;
 use std::path::Path;
 
 use derive_setters::Setters;
-use either::Either;
 use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
 use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
 use rustc_error_messages::{FluentArgs, SpanLabel};
@@ -2609,16 +2608,17 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
     ('\u{2069}', "�"),
 ];
 
-fn normalize_whitespace(str: &str) -> String {
+fn normalize_whitespace(s: &str) -> String {
     // Scan the input string for a character in the ordered table above. If it's present, replace
     // it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
     // char. At the end, allocate all chars into a string in one operation.
-    str.chars()
-        .flat_map(|c| match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) {
-            Ok(i) => Either::Left(OUTPUT_REPLACEMENTS[i].1.chars()),
-            _ => Either::Right([c].into_iter()),
-        })
-        .collect()
+    s.chars().fold(String::with_capacity(s.len()), |mut s, c| {
+        match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) {
+            Ok(i) => s.push_str(OUTPUT_REPLACEMENTS[i].1),
+            _ => s.push(c),
+        }
+        s
+    })
 }
 
 fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {