diff options
| author | bors <bors@rust-lang.org> | 2016-01-26 16:50:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-01-26 16:50:27 +0000 |
| commit | 13b5edab6323b676cae21df54bb58a5dc1339f38 (patch) | |
| tree | 21feace99352fdb27f936bd8f9cfa94dce4406b8 /src/libstd | |
| parent | 5d6e8fcedac1184a28031ee0cf63e2d862e4536f (diff) | |
| parent | c07413c204d055de881f304b8fccaa50ecd60956 (diff) | |
| download | rust-13b5edab6323b676cae21df54bb58a5dc1339f38.tar.gz rust-13b5edab6323b676cae21df54bb58a5dc1339f38.zip | |
Auto merge of #30402 - jooert:prettypanic, r=alexcrichton
This splits the output of panics into two lines as proposed in #15239 and adds a note about how to get a backtrace. Because the default panic message consists of multiple lines now, this changes the test runner's failure output to not indent the first line anymore. Fixes #15239 and fixes #11704.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/panicking.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 8561ecd9c4c..490c5f4b352 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -16,6 +16,7 @@ use cell::Cell; use cell::RefCell; use intrinsics; use sync::StaticRwLock; +use sync::atomic::{AtomicBool, Ordering}; use sys::stdio::Stderr; use sys_common::backtrace; use sys_common::thread_info; @@ -38,6 +39,7 @@ enum Handler { static HANDLER_LOCK: StaticRwLock = StaticRwLock::new(); static mut HANDLER: Handler = Handler::Default; +static FIRST_PANIC: AtomicBool = AtomicBool::new(true); /// Registers a custom panic handler, replacing any that was previously /// registered. @@ -173,8 +175,11 @@ fn default_handler(info: &PanicInfo) { let write = |err: &mut ::io::Write| { let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}", name, msg, file, line); + if log_backtrace { let _ = backtrace::write(err); + } else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) { + let _ = writeln!(err, "note: Run with `RUST_BACKTRACE=1` for a backtrace."); } }; |
