1
+ #![ cfg_attr( test, allow( unused) ) ]
2
+
1
3
use crate :: io:: prelude:: * ;
2
4
3
5
use crate :: cell:: RefCell ;
@@ -16,6 +18,13 @@ thread_local! {
16
18
}
17
19
}
18
20
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
+
19
28
/// A handle to a raw instance of the standard input stream of this process.
20
29
///
21
30
/// This handle is not synchronized or buffered in any fashion. Constructed via
@@ -668,7 +677,6 @@ impl fmt::Debug for StderrLock<'_> {
668
677
issue = "0" ) ]
669
678
#[ doc( hidden) ]
670
679
pub fn set_panic ( sink : Option < Box < dyn Write + Send > > ) -> Option < Box < dyn Write + Send > > {
671
- use crate :: panicking:: LOCAL_STDERR ;
672
680
use crate :: mem;
673
681
LOCAL_STDERR . with ( move |slot| {
674
682
mem:: replace ( & mut * slot. borrow_mut ( ) , sink)
@@ -740,6 +748,7 @@ where
740
748
reason = "implementation detail which may disappear or be replaced at any time" ,
741
749
issue = "0" ) ]
742
750
#[ doc( hidden) ]
751
+ #[ cfg( not( test) ) ]
743
752
pub fn _print ( args : fmt:: Arguments ) {
744
753
print_to ( args, & LOCAL_STDOUT , stdout, "stdout" ) ;
745
754
}
@@ -748,11 +757,14 @@ pub fn _print(args: fmt::Arguments) {
748
757
reason = "implementation detail which may disappear or be replaced at any time" ,
749
758
issue = "0" ) ]
750
759
#[ doc( hidden) ]
760
+ #[ cfg( not( test) ) ]
751
761
pub fn _eprint ( args : fmt:: Arguments ) {
752
- use crate :: panicking:: LOCAL_STDERR ;
753
762
print_to ( args, & LOCAL_STDERR , stderr, "stderr" ) ;
754
763
}
755
764
765
+ #[ cfg( test) ]
766
+ pub use realstd:: io:: { _eprint, _print} ;
767
+
756
768
#[ cfg( test) ]
757
769
mod tests {
758
770
use crate :: panic:: { UnwindSafe , RefUnwindSafe } ;
0 commit comments