Skip to content

Commit 49854c4

Browse files
committed
avoid #[cfg] in favor of cfg!
1 parent dac0a15 commit 49854c4

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/libstd/panicking.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use crate::ptr;
1717
use crate::raw;
1818
use crate::sys::stdio::panic_output;
1919
use crate::sys_common::rwlock::RWLock;
20-
use crate::sys_common::thread_info;
21-
use crate::sys_common::util;
20+
use crate::sys_common::{thread_info, util, backtrace};
2221
use crate::thread;
2322

2423
#[cfg(not(test))]
@@ -157,20 +156,18 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
157156
}
158157

159158
fn default_hook(info: &PanicInfo<'_>) {
160-
#[cfg(feature = "backtrace")]
161-
use crate::sys_common::{backtrace as backtrace_mod};
162-
163159
// If this is a double panic, make sure that we print a backtrace
164160
// for this panic. Otherwise only print it if logging is enabled.
165-
#[cfg(feature = "backtrace")]
166-
let log_backtrace = {
161+
let log_backtrace = if cfg!(feature = "backtrace") {
167162
let panics = update_panic_count(0);
168163

169164
if panics >= 2 {
170165
Some(backtrace_rs::PrintFmt::Full)
171166
} else {
172-
backtrace_mod::log_enabled()
167+
backtrace::log_enabled()
173168
}
169+
} else {
170+
None
174171
};
175172

176173
// The current implementation always returns `Some`.
@@ -190,14 +187,13 @@ fn default_hook(info: &PanicInfo<'_>) {
190187
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
191188
name, msg, location);
192189

193-
#[cfg(feature = "backtrace")]
194-
{
190+
if cfg!(feature = "backtrace") {
195191
use crate::sync::atomic::{AtomicBool, Ordering};
196192

197193
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
198194

199195
if let Some(format) = log_backtrace {
200-
let _ = backtrace_mod::print(err, format);
196+
let _ = backtrace::print(err, format);
201197
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
202198
let _ = writeln!(err, "note: run with `RUST_BACKTRACE=1` \
203199
environment variable to display a backtrace.");

src/libstd/sys_common/backtrace.rs

-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub fn lock() -> impl Drop {
3333
}
3434

3535
/// Prints the current backtrace.
36-
#[cfg(feature = "backtrace")]
3736
pub fn print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
3837
// There are issues currently linking libbacktrace into tests, and in
3938
// general during libstd's own unit tests we're not testing this path. In
@@ -129,7 +128,6 @@ where
129128

130129
// For now logging is turned off by default, and this function checks to see
131130
// whether the magical environment variable is present to see if it's turned on.
132-
#[cfg(feature = "backtrace")]
133131
pub fn log_enabled() -> Option<PrintFmt> {
134132
use crate::sync::atomic::{self, Ordering};
135133

0 commit comments

Comments
 (0)