Skip to content

Commit ab0b57c

Browse files
authored
Rollup merge of rust-lang#120528 - GnomedDev:atomicu8-backtrace-style, r=cuviper
Store SHOULD_CAPTURE as AtomicU8 `BacktraceStyle` easily fits into a u8, so `SHOULD_CAPTURE`, which is just `Atomic<Option<BacktraceStyle>>`, should be stored as `AtomicU8`
2 parents 08c7f26 + 7ea4dbb commit ab0b57c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/std/src/panic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::any::Any;
66
use crate::collections;
77
use crate::panicking;
8-
use crate::sync::atomic::{AtomicUsize, Ordering};
8+
use crate::sync::atomic::{AtomicU8, Ordering};
99
use crate::sync::{Mutex, RwLock};
1010
use crate::thread::Result;
1111

@@ -228,15 +228,15 @@ impl BacktraceStyle {
228228
if cfg!(feature = "backtrace") { Some(BacktraceStyle::Full) } else { None }
229229
}
230230

231-
fn as_usize(self) -> usize {
231+
fn as_u8(self) -> u8 {
232232
match self {
233233
BacktraceStyle::Short => 1,
234234
BacktraceStyle::Full => 2,
235235
BacktraceStyle::Off => 3,
236236
}
237237
}
238238

239-
fn from_usize(s: usize) -> Option<Self> {
239+
fn from_u8(s: u8) -> Option<Self> {
240240
Some(match s {
241241
0 => return None,
242242
1 => BacktraceStyle::Short,
@@ -251,7 +251,7 @@ impl BacktraceStyle {
251251
// that backtrace.
252252
//
253253
// Internally stores equivalent of an Option<BacktraceStyle>.
254-
static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0);
254+
static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0);
255255

256256
/// Configure whether the default panic hook will capture and display a
257257
/// backtrace.
@@ -264,7 +264,7 @@ pub fn set_backtrace_style(style: BacktraceStyle) {
264264
// If the `backtrace` feature of this crate isn't enabled, skip setting.
265265
return;
266266
}
267-
SHOULD_CAPTURE.store(style.as_usize(), Ordering::Release);
267+
SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release);
268268
}
269269

270270
/// Checks whether the standard library's panic hook will capture and print a
@@ -296,7 +296,7 @@ pub fn get_backtrace_style() -> Option<BacktraceStyle> {
296296
// to optimize away callers.
297297
return None;
298298
}
299-
if let Some(style) = BacktraceStyle::from_usize(SHOULD_CAPTURE.load(Ordering::Acquire)) {
299+
if let Some(style) = BacktraceStyle::from_u8(SHOULD_CAPTURE.load(Ordering::Acquire)) {
300300
return Some(style);
301301
}
302302

0 commit comments

Comments
 (0)