@@ -481,36 +481,43 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileNa
481
481
( odir, ofile)
482
482
}
483
483
484
- // Extract input (string or file and optional path) from matches.
484
+ /// Extract input (string or file and optional path) from matches.
485
+ /// This handles reading from stdin if `-` is provided.
485
486
fn make_input(
486
487
early_dcx: & EarlyDiagCtxt ,
487
488
free_matches: & [ String ] ,
488
489
) -> Result <Option <Input >, ErrorGuaranteed > {
489
- let [ ifile] = free_matches else { return Ok ( None ) } ;
490
- if ifile == "-" {
491
- let mut src = String :: new( ) ;
492
- if io:: stdin( ) . read_to_string( & mut src) . is_err( ) {
493
- // Immediately stop compilation if there was an issue reading
494
- // the input (for example if the input stream is not UTF-8).
495
- let reported =
496
- early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
497
- return Err ( reported) ;
498
- }
499
- if let Ok ( path) = env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
490
+ let [ input_file] = free_matches else { return Ok ( None ) } ;
491
+
492
+ if input_file != "-" {
493
+ // Normal `Input::File`
494
+ return Ok ( Some ( Input :: File ( PathBuf :: from( input_file) ) ) ) ;
495
+ }
496
+
497
+ // read from stdin as `Input::Str`
498
+ let mut input = String :: new( ) ;
499
+ if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
500
+ // Immediately stop compilation if there was an issue reading
501
+ // the input (for example if the input stream is not UTF-8).
502
+ let reported =
503
+ early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
504
+ return Err ( reported) ;
505
+ }
506
+
507
+ let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
508
+ Ok ( path) => {
500
509
let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
501
510
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
502
511
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
503
512
) ;
504
513
let line = isize :: from_str_radix( & line, 10 )
505
514
. expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
506
- let file_name = FileName :: doc_test_source_code( PathBuf :: from( path) , line) ;
507
- Ok ( Some ( Input :: Str { name: file_name, input: src } ) )
508
- } else {
509
- Ok ( Some ( Input :: Str { name: FileName :: anon_source_code( & src) , input: src } ) )
515
+ FileName :: doc_test_source_code( PathBuf :: from( path) , line)
510
516
}
511
- } else {
512
- Ok ( Some ( Input :: File ( PathBuf :: from( ifile) ) ) )
513
- }
517
+ Err ( _) => FileName :: anon_source_code( & input) ,
518
+ } ;
519
+
520
+ Ok ( Some ( Input :: Str { name, input } ) )
514
521
}
515
522
516
523
/// Whether to stop or continue compilation.
0 commit comments