1+ #![ cfg_attr( test, allow( unused) ) ]
2+
13use crate :: io:: prelude:: * ;
24
35use crate :: cell:: RefCell ;
@@ -16,6 +18,13 @@ thread_local! {
1618 }
1719}
1820
21+ /// Stderr used by eprint! and eprintln! macros, and panics
22+ thread_local ! {
23+ static LOCAL_STDERR : RefCell <Option <Box <dyn Write + Send >>> = {
24+ RefCell :: new( None )
25+ }
26+ }
27+
1928/// A handle to a raw instance of the standard input stream of this process.
2029///
2130/// This handle is not synchronized or buffered in any fashion. Constructed via
@@ -668,7 +677,6 @@ impl fmt::Debug for StderrLock<'_> {
668677 issue = "0" ) ]
669678#[ doc( hidden) ]
670679pub fn set_panic ( sink : Option < Box < dyn Write + Send > > ) -> Option < Box < dyn Write + Send > > {
671- use crate :: panicking:: LOCAL_STDERR ;
672680 use crate :: mem;
673681 LOCAL_STDERR . with ( move |slot| {
674682 mem:: replace ( & mut * slot. borrow_mut ( ) , sink)
@@ -740,6 +748,7 @@ where
740748 reason = "implementation detail which may disappear or be replaced at any time" ,
741749 issue = "0" ) ]
742750#[ doc( hidden) ]
751+ #[ cfg( not( test) ) ]
743752pub fn _print ( args : fmt:: Arguments ) {
744753 print_to ( args, & LOCAL_STDOUT , stdout, "stdout" ) ;
745754}
@@ -748,11 +757,14 @@ pub fn _print(args: fmt::Arguments) {
748757 reason = "implementation detail which may disappear or be replaced at any time" ,
749758 issue = "0" ) ]
750759#[ doc( hidden) ]
760+ #[ cfg( not( test) ) ]
751761pub fn _eprint ( args : fmt:: Arguments ) {
752- use crate :: panicking:: LOCAL_STDERR ;
753762 print_to ( args, & LOCAL_STDERR , stderr, "stderr" ) ;
754763}
755764
765+ #[ cfg( test) ]
766+ pub use realstd:: io:: { _eprint, _print} ;
767+
756768#[ cfg( test) ]
757769mod tests {
758770 use crate :: panic:: { UnwindSafe , RefUnwindSafe } ;
0 commit comments