diff options
| author | Kornel <kornel@geekhood.net> | 2022-01-17 02:17:25 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2022-01-17 02:21:24 +0000 |
| commit | c2807525a5d7adff0e340007f73b9558f45e38b5 (patch) | |
| tree | a7d128674055cf904bb2792075df02f6ae3b7243 /library/std/src/sys_common/backtrace.rs | |
| parent | bd3cb52565faab2755ff1bdb54d88bc91f47b4b9 (diff) | |
| download | rust-c2807525a5d7adff0e340007f73b9558f45e38b5.tar.gz rust-c2807525a5d7adff0e340007f73b9558f45e38b5.zip | |
Help optimize out backtraces when disabled
Diffstat (limited to 'library/std/src/sys_common/backtrace.rs')
| -rw-r--r-- | library/std/src/sys_common/backtrace.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index d5e8f12414f..dc581a0675b 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -150,16 +150,18 @@ pub enum RustBacktrace { RuntimeDisabled, } +// If the `backtrace` feature of this crate isn't enabled quickly return +// `Disabled` so this can be constant propagated all over the place to +// optimize away callers. +#[cfg(not(feature = "backtrace"))] +pub fn rust_backtrace_env() -> RustBacktrace { + RustBacktrace::Disabled +} + // For now logging is turned off by default, and this function checks to see // whether the magical environment variable is present to see if it's turned on. +#[cfg(feature = "backtrace")] pub fn rust_backtrace_env() -> RustBacktrace { - // If the `backtrace` feature of this crate isn't enabled quickly return - // `None` so this can be constant propagated all over the place to turn - // optimize away callers. - if !cfg!(feature = "backtrace") { - return RustBacktrace::Disabled; - } - // Setting environment variables for Fuchsia components isn't a standard // or easily supported workflow. For now, always display backtraces. if cfg!(target_os = "fuchsia") { @@ -189,6 +191,15 @@ pub fn rust_backtrace_env() -> RustBacktrace { format } +/// Setting for printing the full backtrace, unless backtraces are completely disabled +pub(crate) fn rust_backtrace_print_full() -> RustBacktrace { + if cfg!(feature = "backtrace") { + RustBacktrace::Print(PrintFmt::Full) + } else { + RustBacktrace::Disabled + } +} + /// Prints the filename of the backtrace frame. /// /// See also `output`. |
