Skip to content

Commit 774fbdf

Browse files
author
Jorge Aparicio
committed
keep backtraces if using the old build system
1 parent d464422 commit 774fbdf

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/libstd/panicking.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ use intrinsics;
2828
use mem;
2929
use raw;
3030
use sys_common::rwlock::RWLock;
31-
#[cfg(feature = "backtrace")]
32-
use sync::atomic::{AtomicBool, Ordering};
3331
use sys::stdio::Stderr;
34-
#[cfg(feature = "backtrace")]
35-
use sys_common::backtrace;
3632
use sys_common::thread_info;
3733
use sys_common::util;
3834
use thread;
@@ -73,8 +69,6 @@ enum Hook {
7369

7470
static HOOK_LOCK: RWLock = RWLock::new();
7571
static mut HOOK: Hook = Hook::Default;
76-
#[cfg(feature = "backtrace")]
77-
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
7872

7973
/// Registers a custom panic hook, replacing any that was previously registered.
8074
///
@@ -186,13 +180,17 @@ impl<'a> Location<'a> {
186180
}
187181

188182
fn default_hook(info: &PanicInfo) {
189-
#[cfg(feature = "backtrace")]
190-
let panics = PANIC_COUNT.with(|c| c.get());
183+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
184+
use sys_common::backtrace;
191185

192186
// If this is a double panic, make sure that we print a backtrace
193187
// for this panic. Otherwise only print it if logging is enabled.
194-
#[cfg(feature = "backtrace")]
195-
let log_backtrace = panics >= 2 || backtrace::log_enabled();
188+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
189+
let log_backtrace = {
190+
let panics = PANIC_COUNT.with(|c| c.get());
191+
192+
panics >= 2 || backtrace::log_enabled()
193+
};
196194

197195
let file = info.location.file;
198196
let line = info.location.line;
@@ -212,8 +210,12 @@ fn default_hook(info: &PanicInfo) {
212210
let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}",
213211
name, msg, file, line);
214212

215-
#[cfg(feature = "backtrace")]
213+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
216214
{
215+
use sync::atomic::{AtomicBool, Ordering};
216+
217+
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
218+
217219
if log_backtrace {
218220
let _ = backtrace::write(err);
219221
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {

src/libstd/sys/common/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! rtassert {
2828

2929
pub mod args;
3030
pub mod at_exit_imp;
31-
#[cfg(feature = "backtrace")]
31+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
3232
pub mod backtrace;
3333
pub mod condvar;
3434
pub mod io;
@@ -43,7 +43,7 @@ pub mod thread_local;
4343
pub mod util;
4444
pub mod wtf8;
4545

46-
#[cfg(feature = "backtrace")]
46+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
4747
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
4848
all(windows, target_env = "gnu")))]
4949
pub mod gnu;

src/libstd/sys/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use libc;
3030
pub mod weak;
3131

3232
pub mod android;
33-
#[cfg(feature = "backtrace")]
33+
#[cfg(any(not(cargobuild), feature = "backtrace"))]
3434
pub mod backtrace;
3535
pub mod condvar;
3636
pub mod ext;

0 commit comments

Comments
 (0)