Rollup merge of #128632 - joboet:dont_overwrite_style, r=Amanieu · patricklam/verify-rust-std@ceceae3 (original) (raw)
`@@ -440,13 +440,12 @@ impl BacktraceStyle {
`
440
440
`}
`
441
441
``
442
442
`fn from_u8(s: u8) -> Option {
`
443
``
`-
Some(match s {
`
444
``
`-
0 => return None,
`
445
``
`-
1 => BacktraceStyle::Short,
`
446
``
`-
2 => BacktraceStyle::Full,
`
447
``
`-
3 => BacktraceStyle::Off,
`
448
``
`-
_ => unreachable!(),
`
449
``
`-
})
`
``
443
`+
match s {
`
``
444
`+
1 => Some(BacktraceStyle::Short),
`
``
445
`+
2 => Some(BacktraceStyle::Full),
`
``
446
`+
3 => Some(BacktraceStyle::Off),
`
``
447
`+
_ => None,
`
``
448
`+
}
`
450
449
`}
`
451
450
`}
`
452
451
``
`@@ -465,7 +464,7 @@ static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0);
`
465
464
`pub fn set_backtrace_style(style: BacktraceStyle) {
`
466
465
`if cfg!(feature = "backtrace") {
`
467
466
`` // If the backtrace
feature of this crate is enabled, set the backtrace style.
``
468
``
`-
SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release);
`
``
467
`+
SHOULD_CAPTURE.store(style.as_u8(), Ordering::Relaxed);
`
469
468
`}
`
470
469
`}
`
471
470
``
`@@ -498,7 +497,9 @@ pub fn get_backtrace_style() -> Option {
`
498
497
`// to optimize away callers.
`
499
498
`return None;
`
500
499
`}
`
501
``
`-
if let Some(style) = BacktraceStyle::from_u8(SHOULD_CAPTURE.load(Ordering::Acquire)) {
`
``
500
+
``
501
`+
let current = SHOULD_CAPTURE.load(Ordering::Relaxed);
`
``
502
`+
if let Some(style) = BacktraceStyle::from_u8(current) {
`
502
503
`return Some(style);
`
503
504
`}
`
504
505
``
`@@ -509,8 +510,11 @@ pub fn get_backtrace_style() -> Option {
`
509
510
`None if crate::sys::FULL_BACKTRACE_DEFAULT => BacktraceStyle::Full,
`
510
511
`None => BacktraceStyle::Off,
`
511
512
`};
`
512
``
`-
set_backtrace_style(format);
`
513
``
`-
Some(format)
`
``
513
+
``
514
`+
match SHOULD_CAPTURE.compare_exchange(0, format.as_u8(), Ordering::Relaxed, Ordering::Relaxed) {
`
``
515
`+
Ok(_) => Some(format),
`
``
516
`+
Err(new) => BacktraceStyle::from_u8(new),
`
``
517
`+
}
`
514
518
`}
`
515
519
``
516
520
`#[cfg(test)]
`