@@ -8,7 +8,6 @@ use crate::io::prelude::*;
8
8
use crate :: cell:: { Cell , RefCell } ;
9
9
use crate :: fmt;
10
10
use crate :: io:: { self , BufReader , IoSlice , IoSliceMut , LineWriter , Lines } ;
11
- use crate :: pin:: Pin ;
12
11
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
13
12
use crate :: sync:: { Arc , Mutex , MutexGuard , OnceLock } ;
14
13
use crate :: sys:: stdio;
@@ -526,7 +525,7 @@ pub struct Stdout {
526
525
// FIXME: this should be LineWriter or BufWriter depending on the state of
527
526
// stdout (tty or not). Note that if this is not line buffered it
528
527
// should also flush-on-panic or some form of flush-on-abort.
529
- inner : Pin < & ' static ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > ,
528
+ inner : & ' static ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > ,
530
529
}
531
530
532
531
/// A locked reference to the [`Stdout`] handle.
@@ -603,24 +602,20 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
603
602
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
604
603
pub fn stdout ( ) -> Stdout {
605
604
Stdout {
606
- inner : Pin :: static_ref ( & STDOUT ) . get_or_init_pin (
607
- || unsafe { ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) } ,
608
- |mutex| unsafe { mutex. init ( ) } ,
609
- ) ,
605
+ inner : STDOUT
606
+ . get_or_init ( || ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) ) ,
610
607
}
611
608
}
612
609
613
610
pub fn cleanup ( ) {
614
- if let Some ( instance) = STDOUT . get ( ) {
615
- // Flush the data and disable buffering during shutdown
616
- // by replacing the line writer by one with zero
617
- // buffering capacity.
618
- // We use try_lock() instead of lock(), because someone
619
- // might have leaked a StdoutLock, which would
620
- // otherwise cause a deadlock here.
621
- if let Some ( lock) = Pin :: static_ref ( instance) . try_lock ( ) {
622
- * lock. borrow_mut ( ) = LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ;
623
- }
611
+ // Flush the data and disable buffering during shutdown
612
+ // by replacing the line writer by one with zero
613
+ // buffering capacity.
614
+ // We use try_lock() instead of lock(), because someone
615
+ // might have leaked a StdoutLock, which would
616
+ // otherwise cause a deadlock here.
617
+ if let Some ( lock) = STDOUT . get ( ) . and_then ( ReentrantMutex :: try_lock) {
618
+ * lock. borrow_mut ( ) = LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ;
624
619
}
625
620
}
626
621
@@ -761,7 +756,7 @@ impl fmt::Debug for StdoutLock<'_> {
761
756
/// standard library or via raw Windows API calls, will fail.
762
757
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
763
758
pub struct Stderr {
764
- inner : Pin < & ' static ReentrantMutex < RefCell < StderrRaw > > > ,
759
+ inner : & ' static ReentrantMutex < RefCell < StderrRaw > > ,
765
760
}
766
761
767
762
/// A locked reference to the [`Stderr`] handle.
@@ -834,16 +829,12 @@ pub struct StderrLock<'a> {
834
829
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
835
830
pub fn stderr ( ) -> Stderr {
836
831
// Note that unlike `stdout()` we don't use `at_exit` here to register a
837
- // destructor. Stderr is not buffered , so there's no need to run a
832
+ // destructor. Stderr is not buffered, so there's no need to run a
838
833
// destructor for flushing the buffer
839
- static INSTANCE : OnceLock < ReentrantMutex < RefCell < StderrRaw > > > = OnceLock :: new ( ) ;
834
+ static INSTANCE : ReentrantMutex < RefCell < StderrRaw > > =
835
+ ReentrantMutex :: new ( RefCell :: new ( stderr_raw ( ) ) ) ;
840
836
841
- Stderr {
842
- inner : Pin :: static_ref ( & INSTANCE ) . get_or_init_pin (
843
- || unsafe { ReentrantMutex :: new ( RefCell :: new ( stderr_raw ( ) ) ) } ,
844
- |mutex| unsafe { mutex. init ( ) } ,
845
- ) ,
846
- }
837
+ Stderr { inner : & INSTANCE }
847
838
}
848
839
849
840
impl Stderr {
0 commit comments