diff options
| author | bors <bors@rust-lang.org> | 2024-08-03 21:19:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-03 21:19:42 +0000 |
| commit | 64ebd39da5ec28caa3bd7cbb3f22f5949432fe2b (patch) | |
| tree | 3c2c7dfa5c39be2dbd6aff2d26e3bfb0f3ef135d /library/std/src/panic.rs | |
| parent | bbf60c897e18a72923129c63ff33ce2de2968815 (diff) | |
| parent | 0655ed234f942959c70560ec907ae442fb51f146 (diff) | |
| download | rust-64ebd39da5ec28caa3bd7cbb3f22f5949432fe2b.tar.gz rust-64ebd39da5ec28caa3bd7cbb3f22f5949432fe2b.zip | |
Auto merge of #128614 - matthiaskrgr:rollup-d2fextz, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #127921 (Stabilize unsafe extern blocks (RFC 3484)) - #128283 (bootstrap: fix bug preventing the use of custom targets) - #128530 (Implement `UncheckedIterator` directly for `RepeatN`) - #128551 (chore: refactor backtrace style in panic) - #128573 (Simplify `body` usage in rustdoc) - #128581 (Assert that all attributes are actually checked via `CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes) - #128603 (Update run-make/used to use `any_symbol_contains`) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/panic.rs')
| -rw-r--r-- | library/std/src/panic.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 2ca9256715c..4c496ade81c 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -463,11 +463,10 @@ static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0); /// environment variable; see the details in [`get_backtrace_style`]. #[unstable(feature = "panic_backtrace_config", issue = "93346")] pub fn set_backtrace_style(style: BacktraceStyle) { - if !cfg!(feature = "backtrace") { - // If the `backtrace` feature of this crate isn't enabled, skip setting. - return; + if cfg!(feature = "backtrace") { + // If the `backtrace` feature of this crate is enabled, set the backtrace style. + SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release); } - SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release); } /// Checks whether the standard library's panic hook will capture and print a @@ -503,21 +502,13 @@ pub fn get_backtrace_style() -> Option<BacktraceStyle> { return Some(style); } - let format = crate::env::var_os("RUST_BACKTRACE") - .map(|x| { - if &x == "0" { - BacktraceStyle::Off - } else if &x == "full" { - BacktraceStyle::Full - } else { - BacktraceStyle::Short - } - }) - .unwrap_or(if crate::sys::FULL_BACKTRACE_DEFAULT { - BacktraceStyle::Full - } else { - BacktraceStyle::Off - }); + let format = match crate::env::var_os("RUST_BACKTRACE") { + Some(x) if &x == "0" => BacktraceStyle::Off, + Some(x) if &x == "full" => BacktraceStyle::Full, + Some(_) => BacktraceStyle::Short, + None if crate::sys::FULL_BACKTRACE_DEFAULT => BacktraceStyle::Full, + None => BacktraceStyle::Off, + }; set_backtrace_style(format); Some(format) } |
