diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 1e9a65e1d2fc4..7c19865b6d78b 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -173,15 +173,17 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String { .map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or("")) .collect::() .trim() - .replace('\n', " ") - .replace('/', "") - .replace('\t', " ") - .replace('{', "") - .replace('}', "") + .chars() + .filter_map(|c| match c { + '\n' | '\t' => Some(' '), + '/' | '{' | '}' => None, + c => Some(c), + }) + .collect::() .split(' ') .filter(|s| !s.is_empty()) - .collect::>() - .join(" "), + .intersperse(" ") + .collect::(), ) .unwrap_or_else(|_| String::new()) }