@@ -28,11 +28,7 @@ use intrinsics;
2828use mem;
2929use raw;
3030use sys_common:: rwlock:: RWLock ;
31- #[ cfg( feature = "backtrace" ) ]
32- use sync:: atomic:: { AtomicBool , Ordering } ;
3331use sys:: stdio:: Stderr ;
34- #[ cfg( feature = "backtrace" ) ]
35- use sys_common:: backtrace;
3632use sys_common:: thread_info;
3733use sys_common:: util;
3834use thread;
@@ -73,8 +69,6 @@ enum Hook {
7369
7470static HOOK_LOCK : RWLock = RWLock :: new ( ) ;
7571static 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
188182fn 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 ) {
0 commit comments