@@ -197,12 +197,13 @@ pub struct StdinLock<'a> {
197
197
/// ```
198
198
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
199
199
pub fn stdin ( ) -> Stdin {
200
- static INSTANCE : Lazy < Mutex < BufReader < Maybe < StdinRaw > > > > = Lazy :: new ( stdin_init) ;
200
+ static INSTANCE : Lazy < Mutex < BufReader < Maybe < StdinRaw > > > > = unsafe { Lazy :: new ( stdin_init) } ;
201
201
return Stdin {
202
202
inner : INSTANCE . get ( ) . expect ( "cannot access stdin during shutdown" ) ,
203
203
} ;
204
204
205
205
fn stdin_init ( ) -> Arc < Mutex < BufReader < Maybe < StdinRaw > > > > {
206
+ // This must not reentrantly access `INSTANCE`
206
207
let stdin = match stdin_raw ( ) {
207
208
Ok ( stdin) => Maybe :: Real ( stdin) ,
208
209
_ => Maybe :: Fake
@@ -396,12 +397,13 @@ pub struct StdoutLock<'a> {
396
397
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
397
398
pub fn stdout ( ) -> Stdout {
398
399
static INSTANCE : Lazy < ReentrantMutex < RefCell < LineWriter < Maybe < StdoutRaw > > > > >
399
- = Lazy :: new ( stdout_init) ;
400
+ = unsafe { Lazy :: new ( stdout_init) } ;
400
401
return Stdout {
401
402
inner : INSTANCE . get ( ) . expect ( "cannot access stdout during shutdown" ) ,
402
403
} ;
403
404
404
405
fn stdout_init ( ) -> Arc < ReentrantMutex < RefCell < LineWriter < Maybe < StdoutRaw > > > > > {
406
+ // This must not reentrantly access `INSTANCE`
405
407
let stdout = match stdout_raw ( ) {
406
408
Ok ( stdout) => Maybe :: Real ( stdout) ,
407
409
_ => Maybe :: Fake ,
@@ -531,12 +533,14 @@ pub struct StderrLock<'a> {
531
533
/// ```
532
534
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
533
535
pub fn stderr ( ) -> Stderr {
534
- static INSTANCE : Lazy < ReentrantMutex < RefCell < Maybe < StderrRaw > > > > = Lazy :: new ( stderr_init) ;
536
+ static INSTANCE : Lazy < ReentrantMutex < RefCell < Maybe < StderrRaw > > > > =
537
+ unsafe { Lazy :: new ( stderr_init) } ;
535
538
return Stderr {
536
539
inner : INSTANCE . get ( ) . expect ( "cannot access stderr during shutdown" ) ,
537
540
} ;
538
541
539
542
fn stderr_init ( ) -> Arc < ReentrantMutex < RefCell < Maybe < StderrRaw > > > > {
543
+ // This must not reentrantly access `INSTANCE`
540
544
let stderr = match stderr_raw ( ) {
541
545
Ok ( stderr) => Maybe :: Real ( stderr) ,
542
546
_ => Maybe :: Fake ,
0 commit comments