@@ -6,9 +6,10 @@ use crate::cell::RefCell;
6
6
use crate :: fmt;
7
7
use crate :: io:: lazy:: Lazy ;
8
8
use crate :: io:: { self , Initializer , BufReader , LineWriter , IoVec , IoVecMut } ;
9
- use crate :: sync:: { Arc , Mutex , MutexGuard } ;
9
+ use crate :: sync:: Arc ;
10
10
use crate :: sys:: stdio;
11
- use crate :: sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
11
+ use crate :: panic:: { UnwindSafe , RefUnwindSafe } ;
12
+ use crate :: parking_lot:: { Mutex , MutexGuard , ReentrantMutex , ReentrantMutexGuard } ;
12
13
use crate :: thread:: LocalKey ;
13
14
14
15
thread_local ! {
@@ -242,9 +243,7 @@ pub struct StdinLock<'a> {
242
243
pub fn stdin ( ) -> Stdin {
243
244
static INSTANCE : Lazy < Mutex < BufReader < Maybe < StdinRaw > > > > = Lazy :: new ( ) ;
244
245
return Stdin {
245
- inner : unsafe {
246
- INSTANCE . get ( stdin_init) . expect ( "cannot access stdin during shutdown" )
247
- } ,
246
+ inner : INSTANCE . get ( stdin_init) . expect ( "cannot access stdin during shutdown" ) ,
248
247
} ;
249
248
250
249
fn stdin_init ( ) -> Arc < Mutex < BufReader < Maybe < StdinRaw > > > > {
@@ -285,7 +284,7 @@ impl Stdin {
285
284
/// ```
286
285
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
287
286
pub fn lock ( & self ) -> StdinLock < ' _ > {
288
- StdinLock { inner : self . inner . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) }
287
+ StdinLock { inner : self . inner . lock ( ) }
289
288
}
290
289
291
290
/// Locks this handle and reads a line of input into the specified buffer.
@@ -466,9 +465,7 @@ pub struct StdoutLock<'a> {
466
465
pub fn stdout ( ) -> Stdout {
467
466
static INSTANCE : Lazy < ReentrantMutex < RefCell < LineWriter < Maybe < StdoutRaw > > > > > = Lazy :: new ( ) ;
468
467
return Stdout {
469
- inner : unsafe {
470
- INSTANCE . get ( stdout_init) . expect ( "cannot access stdout during shutdown" )
471
- } ,
468
+ inner : INSTANCE . get ( stdout_init) . expect ( "cannot access stdout during shutdown" ) ,
472
469
} ;
473
470
474
471
fn stdout_init ( ) -> Arc < ReentrantMutex < RefCell < LineWriter < Maybe < StdoutRaw > > > > > {
@@ -504,7 +501,7 @@ impl Stdout {
504
501
/// ```
505
502
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
506
503
pub fn lock ( & self ) -> StdoutLock < ' _ > {
507
- StdoutLock { inner : self . inner . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) }
504
+ StdoutLock { inner : self . inner . lock ( ) }
508
505
}
509
506
}
510
507
@@ -533,6 +530,12 @@ impl Write for Stdout {
533
530
self . lock ( ) . write_fmt ( args)
534
531
}
535
532
}
533
+
534
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
535
+ impl UnwindSafe for Stdout { }
536
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
537
+ impl RefUnwindSafe for Stdout { }
538
+
536
539
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
537
540
impl Write for StdoutLock < ' _ > {
538
541
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -553,6 +556,11 @@ impl fmt::Debug for StdoutLock<'_> {
553
556
}
554
557
}
555
558
559
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
560
+ impl UnwindSafe for StdoutLock < ' _ > { }
561
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
562
+ impl RefUnwindSafe for StdoutLock < ' _ > { }
563
+
556
564
/// A handle to the standard error stream of a process.
557
565
///
558
566
/// For more information, see the [`io::stderr`] method.
@@ -625,9 +633,7 @@ pub struct StderrLock<'a> {
625
633
pub fn stderr ( ) -> Stderr {
626
634
static INSTANCE : Lazy < ReentrantMutex < RefCell < Maybe < StderrRaw > > > > = Lazy :: new ( ) ;
627
635
return Stderr {
628
- inner : unsafe {
629
- INSTANCE . get ( stderr_init) . expect ( "cannot access stderr during shutdown" )
630
- } ,
636
+ inner : INSTANCE . get ( stderr_init) . expect ( "cannot access stderr during shutdown" ) ,
631
637
} ;
632
638
633
639
fn stderr_init ( ) -> Arc < ReentrantMutex < RefCell < Maybe < StderrRaw > > > > {
@@ -663,7 +669,7 @@ impl Stderr {
663
669
/// ```
664
670
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
665
671
pub fn lock ( & self ) -> StderrLock < ' _ > {
666
- StderrLock { inner : self . inner . lock ( ) . unwrap_or_else ( |e| e . into_inner ( ) ) }
672
+ StderrLock { inner : self . inner . lock ( ) }
667
673
}
668
674
}
669
675
@@ -692,6 +698,12 @@ impl Write for Stderr {
692
698
self . lock ( ) . write_fmt ( args)
693
699
}
694
700
}
701
+
702
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
703
+ impl UnwindSafe for Stderr { }
704
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
705
+ impl RefUnwindSafe for Stderr { }
706
+
695
707
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
696
708
impl Write for StderrLock < ' _ > {
697
709
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -712,6 +724,11 @@ impl fmt::Debug for StderrLock<'_> {
712
724
}
713
725
}
714
726
727
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
728
+ impl UnwindSafe for StderrLock < ' _ > { }
729
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
730
+ impl RefUnwindSafe for StderrLock < ' _ > { }
731
+
715
732
/// Resets the thread-local stderr handle to the specified writer
716
733
///
717
734
/// This will replace the current thread's stderr handle, returning the old
@@ -816,7 +833,6 @@ pub use realstd::io::{_eprint, _print};
816
833
817
834
#[ cfg( test) ]
818
835
mod tests {
819
- use crate :: panic:: { UnwindSafe , RefUnwindSafe } ;
820
836
use crate :: thread;
821
837
use super :: * ;
822
838
0 commit comments