@@ -28,11 +28,7 @@ use intrinsics;
28
28
use mem;
29
29
use raw;
30
30
use sys_common:: rwlock:: RWLock ;
31
- #[ cfg( feature = "backtrace" ) ]
32
- use sync:: atomic:: { AtomicBool , Ordering } ;
33
31
use sys:: stdio:: Stderr ;
34
- #[ cfg( feature = "backtrace" ) ]
35
- use sys_common:: backtrace;
36
32
use sys_common:: thread_info;
37
33
use sys_common:: util;
38
34
use thread;
@@ -73,8 +69,6 @@ enum Hook {
73
69
74
70
static HOOK_LOCK : RWLock = RWLock :: new ( ) ;
75
71
static mut HOOK : Hook = Hook :: Default ;
76
- #[ cfg( feature = "backtrace" ) ]
77
- static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
78
72
79
73
/// Registers a custom panic hook, replacing any that was previously registered.
80
74
///
@@ -186,13 +180,17 @@ impl<'a> Location<'a> {
186
180
}
187
181
188
182
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 ;
191
185
192
186
// If this is a double panic, make sure that we print a backtrace
193
187
// 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
+ } ;
196
194
197
195
let file = info. location . file ;
198
196
let line = info. location . line ;
@@ -212,8 +210,12 @@ fn default_hook(info: &PanicInfo) {
212
210
let _ = writeln ! ( err, "thread '{}' panicked at '{}', {}:{}" ,
213
211
name, msg, file, line) ;
214
212
215
- #[ cfg( feature = "backtrace" ) ]
213
+ #[ cfg( any ( not ( cargobuild ) , feature = "backtrace" ) ) ]
216
214
{
215
+ use sync:: atomic:: { AtomicBool , Ordering } ;
216
+
217
+ static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
218
+
217
219
if log_backtrace {
218
220
let _ = backtrace:: write ( err) ;
219
221
} else if FIRST_PANIC . compare_and_swap ( true , false , Ordering :: SeqCst ) {
0 commit comments