diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 8db5f8b0cff..41efda980a2 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -399,7 +399,7 @@ fn run_test( eprint!("{}", self.0); } } - let mut out_lines = str::from_utf8(&output.stderr) + let mut out = str::from_utf8(&output.stderr) .unwrap() .lines() .filter(|l| { @@ -410,15 +410,15 @@ fn run_test( true } }) - .collect::>(); + .intersperse_with(|| "\n") + .collect::(); // 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) => {