@@ -17,7 +17,7 @@ use io::{self, Initializer, BufReader, LineWriter};
17
17
use sync:: { Arc , Mutex , MutexGuard } ;
18
18
use sys:: stdio;
19
19
use sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
20
- use thread:: { LocalKey , LocalKeyState } ;
20
+ use thread:: LocalKey ;
21
21
22
22
/// Stdout used by print! and println! macros
23
23
thread_local ! {
@@ -674,20 +674,14 @@ fn print_to<T>(args: fmt::Arguments,
674
674
local_s : & ' static LocalKey < RefCell < Option < Box < Write +Send > > > > ,
675
675
global_s : fn ( ) -> T ,
676
676
label : & str ) where T : Write {
677
- let result = match local_s. state ( ) {
678
- LocalKeyState :: Uninitialized |
679
- LocalKeyState :: Destroyed => global_s ( ) . write_fmt ( args) ,
680
- LocalKeyState :: Valid => {
681
- local_s. with ( |s| {
682
- if let Ok ( mut borrowed) = s. try_borrow_mut ( ) {
683
- if let Some ( w) = borrowed. as_mut ( ) {
684
- return w. write_fmt ( args) ;
685
- }
686
- }
687
- global_s ( ) . write_fmt ( args)
688
- } )
677
+ let result = local_s. try_with ( |s| {
678
+ if let Ok ( mut borrowed) = s. try_borrow_mut ( ) {
679
+ if let Some ( w) = borrowed. as_mut ( ) {
680
+ return w. write_fmt ( args) ;
681
+ }
689
682
}
690
- } ;
683
+ global_s ( ) . write_fmt ( args)
684
+ } ) . unwrap_or_else ( |_| global_s ( ) . write_fmt ( args) ) ;
691
685
if let Err ( e) = result {
692
686
panic ! ( "failed printing to {}: {}" , label, e) ;
693
687
}
0 commit comments