Skip to content
Myr

Remove extra trailing newline from debug representation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The termination impl for Result inserts a trailing newline automatically: https://github.com/rust-lang/rust/blob/1.39.0/src/libstd/process.rs#L1640 So if we print one too, there ends up being a needless blank line in the output.

authored by David Tolnay · committed by David Tolnay · parent 9a06ac1 · Browse files · 2 files+9 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−10 removed

  • tests:+3 added−5 removed
  • other:+6 added−5 removed

2 files+9 added−10 removed

modified:src/fmt.rs+6 added-5 removed
20 unmodified lines
21 if f.alternate() {22 return Debug::fmt(error, f);23 }2425 writeln!(f, "{}", error)?;25 write!(f, "{}", error)?;2627 if let Some(cause) = error.source() {28 write!(f, "\nCaused by:\n")?;28 write!(f, "\n\nCaused by:")?;29 let multiple = cause.source().is_some();30 for (n, error) in Chain::new(cause).enumerate() {31 write!(f, " ")?;31 write!(f, "\n ")?;32 if multiple {33 write!(f, "{}: ", n)?;34 }35 writeln!(f, "{}", error)?;35 write!(f, "{}", error)?;36 }37 }3839 #[cfg(backtrace)]
6 unmodified lines
46 if backtrace.starts_with("stack backtrace:") {47 // Capitalize to match "Caused by:"48 backtrace.replace_range(0..1, "S");49 }50 backtrace.truncate(backtrace.trim_end().len());50 write!(f, "\n{}", backtrace)?;51 write!(f, "\n\n{}", backtrace)?;52 }53 }5455 Ok(())
2 unmodified lines
modified:tests/test_fmt.rs+3 added-5 removed
17 unmodified lines
18const EXPECTED_ALTDISPLAY_G: &str = "f failed: oh no!";1920const EXPECTED_ALTDISPLAY_H: &str = "g failed: f failed: oh no!";2122const EXPECTED_DEBUG_F: &str = "\23oh no!24";22const EXPECTED_DEBUG_F: &str = "oh no!";2324const EXPECTED_DEBUG_G: &str = "\25f failed2627Caused by:30 oh no!28 oh no!\29";3031const EXPECTED_DEBUG_H: &str = "\32g failed3334Caused by:35 0: f failed38 1: oh no!36 1: oh no!\37";3839const EXPECTED_ALTDEBUG_F: &str = "\40Custom {
54 unmodified lines