@@ -17,7 +17,7 @@ use io::{self, Initializer, BufReader, LineWriter};
1717use sync:: { Arc , Mutex , MutexGuard } ;
1818use sys:: stdio;
1919use sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
20- use thread:: { LocalKey , LocalKeyState } ;
20+ use thread:: LocalKey ;
2121
2222/// Stdout used by print! and println! macros
2323thread_local ! {
@@ -674,20 +674,14 @@ fn print_to<T>(args: fmt::Arguments,
674674 local_s : & ' static LocalKey < RefCell < Option < Box < Write +Send > > > > ,
675675 global_s : fn ( ) -> T ,
676676 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+ }
689682 }
690- } ;
683+ global_s ( ) . write_fmt ( args)
684+ } ) . unwrap_or_else ( |_| global_s ( ) . write_fmt ( args) ) ;
691685 if let Err ( e) = result {
692686 panic ! ( "failed printing to {}: {}" , label, e) ;
693687 }
0 commit comments