@@ -235,21 +235,15 @@ fn run_compiler(
235
235
registry : diagnostics_registry ( ) ,
236
236
} ;
237
237
238
- match make_input ( & matches. free ) {
239
- Some ( ( input, input_file_path, input_err) ) => {
240
- if let Some ( err) = input_err {
241
- // Immediately stop compilation if there was an issue reading
242
- // the input (for example if the input stream is not UTF-8).
243
- early_error_no_abort ( config. opts . error_format , & err. to_string ( ) ) ;
244
- return Err ( ErrorReported ) ;
245
- }
246
-
238
+ match make_input ( config. opts . error_format , & matches. free ) {
239
+ Err ( ErrorReported ) => return Err ( ErrorReported ) ,
240
+ Ok ( Some ( ( input, input_file_path) ) ) => {
247
241
config. input = input;
248
242
config. input_path = input_file_path;
249
243
250
244
callbacks. config ( & mut config) ;
251
245
}
252
- None => match matches. free . len ( ) {
246
+ Ok ( None ) => match matches. free . len ( ) {
253
247
0 => {
254
248
callbacks. config ( & mut config) ;
255
249
interface:: run_compiler ( config, |compiler| {
@@ -469,19 +463,23 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
469
463
}
470
464
471
465
// Extract input (string or file and optional path) from matches.
472
- fn make_input ( free_matches : & [ String ] ) -> Option < ( Input , Option < PathBuf > , Option < io:: Error > ) > {
466
+ fn make_input (
467
+ error_format : ErrorOutputType ,
468
+ free_matches : & [ String ] ,
469
+ ) -> Result < Option < ( Input , Option < PathBuf > ) > , ErrorReported > {
473
470
if free_matches. len ( ) == 1 {
474
471
let ifile = & free_matches[ 0 ] ;
475
472
if ifile == "-" {
476
473
let mut src = String :: new ( ) ;
477
- let err = if io:: stdin ( ) . read_to_string ( & mut src) . is_err ( ) {
478
- Some ( io:: Error :: new (
479
- io:: ErrorKind :: InvalidData ,
474
+ if io:: stdin ( ) . read_to_string ( & mut src) . is_err ( ) {
475
+ // Immediately stop compilation if there was an issue reading
476
+ // the input (for example if the input stream is not UTF-8).
477
+ early_error_no_abort (
478
+ error_format,
480
479
"couldn't read from stdin, as it did not contain valid UTF-8" ,
481
- ) )
482
- } else {
483
- None
484
- } ;
480
+ ) ;
481
+ return Err ( ErrorReported ) ;
482
+ }
485
483
if let Ok ( path) = env:: var ( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
486
484
let line = env:: var ( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect (
487
485
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
@@ -490,14 +488,15 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>, Option
490
488
let line = isize:: from_str_radix ( & line, 10 )
491
489
. expect ( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
492
490
let file_name = FileName :: doc_test_source_code ( PathBuf :: from ( path) , line) ;
493
- return Some ( ( Input :: Str { name : file_name, input : src } , None , err) ) ;
491
+ Ok ( Some ( ( Input :: Str { name : file_name, input : src } , None ) ) )
492
+ } else {
493
+ Ok ( Some ( ( Input :: Str { name : FileName :: anon_source_code ( & src) , input : src } , None ) ) )
494
494
}
495
- Some ( ( Input :: Str { name : FileName :: anon_source_code ( & src) , input : src } , None , err) )
496
495
} else {
497
- Some ( ( Input :: File ( PathBuf :: from ( ifile) ) , Some ( PathBuf :: from ( ifile) ) , None ) )
496
+ Ok ( Some ( ( Input :: File ( PathBuf :: from ( ifile) ) , Some ( PathBuf :: from ( ifile) ) ) ) )
498
497
}
499
498
} else {
500
- None
499
+ Ok ( None )
501
500
}
502
501
}
503
502
0 commit comments