]> git.lizzy.rs Git - rust.git/commitdiff
Remove intermediate `collect`
authorRoc Yu <rocyu@protonmail.com>
Wed, 12 Jan 2022 20:57:46 +0000 (15:57 -0500)
committerRoc Yu <rocyu@protonmail.com>
Wed, 12 Jan 2022 20:58:49 +0000 (15:58 -0500)
src/librustdoc/doctest.rs

index ac24543929b663df349edbbb7c9e59bbb8f982dc..67d43fbf0bbb07edcd2de456ed4fe21b6ca1ef15 100644 (file)
@@ -395,7 +395,7 @@ fn drop(&mut self) {
             eprint!("{}", self.0);
         }
     }
-    let mut out_lines = str::from_utf8(&output.stderr)
+    let mut out = str::from_utf8(&output.stderr)
         .unwrap()
         .lines()
         .filter(|l| {
@@ -406,15 +406,15 @@ fn drop(&mut self) {
                 true
             }
         })
-        .collect::<Vec<_>>();
+        .intersperse_with(|| "\n")
+        .collect::<String>();
 
     // Add a \n to the end to properly terminate the last line,
     // but only if there was output to be printed
-    if !out_lines.is_empty() {
-        out_lines.push("");
+    if !out.is_empty() {
+        out.push('\n');
     }
 
-    let out = out_lines.join("\n");
     let _bomb = Bomb(&out);
     match (output.status.success(), lang_string.compile_fail) {
         (true, true) => {