@@ -463,11 +463,10 @@ static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0);
463463/// environment variable; see the details in [`get_backtrace_style`].
464464#[ unstable( feature = "panic_backtrace_config" , issue = "93346" ) ]
465465pub fn set_backtrace_style ( style : BacktraceStyle ) {
466- if ! cfg ! ( feature = "backtrace" ) {
467- // If the `backtrace` feature of this crate isn't enabled, skip setting .
468- return ;
466+ if cfg ! ( feature = "backtrace" ) {
467+ // If the `backtrace` feature of this crate is enabled, set the backtrace style .
468+ SHOULD_CAPTURE . store ( style . as_u8 ( ) , Ordering :: Release ) ;
469469 }
470- SHOULD_CAPTURE . store ( style. as_u8 ( ) , Ordering :: Release ) ;
471470}
472471
473472/// Checks whether the standard library's panic hook will capture and print a
@@ -503,21 +502,13 @@ pub fn get_backtrace_style() -> Option<BacktraceStyle> {
503502 return Some ( style) ;
504503 }
505504
506- let format = crate :: env:: var_os ( "RUST_BACKTRACE" )
507- . map ( |x| {
508- if & x == "0" {
509- BacktraceStyle :: Off
510- } else if & x == "full" {
511- BacktraceStyle :: Full
512- } else {
513- BacktraceStyle :: Short
514- }
515- } )
516- . unwrap_or ( if crate :: sys:: FULL_BACKTRACE_DEFAULT {
517- BacktraceStyle :: Full
518- } else {
519- BacktraceStyle :: Off
520- } ) ;
505+ let format = match crate :: env:: var_os ( "RUST_BACKTRACE" ) {
506+ Some ( x) if & x == "0" => BacktraceStyle :: Off ,
507+ Some ( x) if & x == "full" => BacktraceStyle :: Full ,
508+ Some ( _) => BacktraceStyle :: Short ,
509+ None if crate :: sys:: FULL_BACKTRACE_DEFAULT => BacktraceStyle :: Full ,
510+ None => BacktraceStyle :: Off ,
511+ } ;
521512 set_backtrace_style ( format) ;
522513 Some ( format)
523514}
0 commit comments