@@ -331,19 +331,12 @@ fn run_compiler(
331
331
expanded_args: args,
332
332
} ;
333
333
334
- let has_input = match make_input( & default_early_dcx, & matches. free) {
335
- Err ( reported) => return Err ( reported) ,
336
- Ok ( Some ( input) ) => {
334
+ let has_input = match make_input( & default_early_dcx, & matches. free) ? {
335
+ Some ( input) => {
337
336
config. input = input;
338
337
true // has input: normal compilation
339
338
}
340
- Ok ( None ) => match matches. free. as_slice( ) {
341
- [ ] => false , // no input: we will exit early
342
- [ _] => panic!( "make_input should have provided valid inputs" ) ,
343
- [ fst, snd, ..] => default_early_dcx. early_fatal( format!(
344
- "multiple input filenames provided (first two filenames are `{fst}` and `{snd}`)"
345
- ) ) ,
346
- } ,
339
+ None => false , // no input: we will exit early
347
340
} ;
348
341
349
342
drop( default_early_dcx) ;
@@ -488,37 +481,40 @@ fn make_input(
488
481
early_dcx: & EarlyDiagCtxt ,
489
482
free_matches: & [ String ] ,
490
483
) -> Result <Option <Input >, ErrorGuaranteed > {
491
- let [ input_file] = free_matches else { return Ok ( None ) } ;
492
-
493
- if input_file != "-" {
494
- // Normal `Input::File`
495
- return Ok ( Some ( Input :: File ( PathBuf :: from( input_file) ) ) ) ;
496
- }
497
-
498
- // read from stdin as `Input::Str`
499
- let mut input = String :: new( ) ;
500
- if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
501
- // Immediately stop compilation if there was an issue reading
502
- // the input (for example if the input stream is not UTF-8).
503
- let reported =
504
- early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
505
- return Err ( reported) ;
506
- }
484
+ match free_matches {
485
+ [ ] => Ok ( None ) , // no input: we will exit early,
486
+ [ ifile] if ifile == "-" => {
487
+ // read from stdin as `Input::Str`
488
+ let mut input = String :: new( ) ;
489
+ if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
490
+ // Immediately stop compilation if there was an issue reading
491
+ // the input (for example if the input stream is not UTF-8).
492
+ let reported = early_dcx
493
+ . early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
494
+ return Err ( reported) ;
495
+ }
507
496
508
- let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
509
- Ok ( path) => {
510
- let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
511
- "when UNSTABLE_RUSTDOC_TEST_PATH is set \
497
+ let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
498
+ Ok ( path) => {
499
+ let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
500
+ "when UNSTABLE_RUSTDOC_TEST_PATH is set \
512
501
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
513
- ) ;
514
- let line = isize :: from_str_radix( & line, 10 )
515
- . expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
516
- FileName :: doc_test_source_code( PathBuf :: from( path) , line)
517
- }
518
- Err ( _) => FileName :: anon_source_code( & input) ,
519
- } ;
502
+ ) ;
503
+ let line = isize :: from_str_radix( & line, 10 )
504
+ . expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
505
+ FileName :: doc_test_source_code( PathBuf :: from( path) , line)
506
+ }
507
+ Err ( _) => FileName :: anon_source_code( & input) ,
508
+ } ;
520
509
521
- Ok ( Some ( Input :: Str { name, input } ) )
510
+ Ok ( Some ( Input :: Str { name, input } ) )
511
+ }
512
+ [ ifile] => Ok ( Some ( Input :: File ( PathBuf :: from( ifile) ) ) ) ,
513
+ _ => early_dcx. early_fatal( format!(
514
+ "multiple input filenames provided (first two filenames are `{}` and `{}`)" ,
515
+ free_matches[ 0 ] , free_matches[ 1 ] ,
516
+ ) ) ,
517
+ }
522
518
}
523
519
524
520
/// Whether to stop or continue compilation.
0 commit comments