@@ -456,10 +456,13 @@ pub fn run_compiler<'a>(args: &[String],
456
456
None ) ;
457
457
458
458
let ( odir, ofile) = make_output ( & matches) ;
459
- let ( input, input_file_path) = match make_input ( & matches. free ) {
460
- Some ( ( input, input_file_path) ) => callbacks. some_input ( input, input_file_path) ,
459
+ let ( input, input_file_path, input_err) = match make_input ( & matches. free ) {
460
+ Some ( ( input, input_file_path, input_err) ) => {
461
+ let ( input, input_file_path) = callbacks. some_input ( input, input_file_path) ;
462
+ ( input, input_file_path, input_err)
463
+ } ,
461
464
None => match callbacks. no_input ( & matches, & sopts, & cfg, & odir, & ofile, & descriptions) {
462
- Some ( ( input, input_file_path) ) => ( input, input_file_path) ,
465
+ Some ( ( input, input_file_path) ) => ( input, input_file_path, None ) ,
463
466
None => return ( Ok ( ( ) ) , None ) ,
464
467
} ,
465
468
} ;
@@ -470,6 +473,13 @@ pub fn run_compiler<'a>(args: &[String],
470
473
sopts, input_file_path. clone ( ) , descriptions, codemap, emitter_dest,
471
474
) ;
472
475
476
+ if let Some ( err) = input_err {
477
+ // Immediately stop compilation if there was an issue reading
478
+ // the input (for example if the input stream is not UTF-8).
479
+ sess. err ( & format ! ( "{}" , err) ) ;
480
+ return ( Err ( CompileIncomplete :: Stopped ) , Some ( sess) ) ;
481
+ }
482
+
473
483
let trans = get_trans ( & sess) ;
474
484
475
485
rustc_lint:: register_builtins ( & mut sess. lint_store . borrow_mut ( ) , Some ( & sess) ) ;
@@ -512,17 +522,22 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
512
522
}
513
523
514
524
// Extract input (string or file and optional path) from matches.
515
- fn make_input ( free_matches : & [ String ] ) -> Option < ( Input , Option < PathBuf > ) > {
525
+ fn make_input ( free_matches : & [ String ] ) -> Option < ( Input , Option < PathBuf > , Option < io :: Error > ) > {
516
526
if free_matches. len ( ) == 1 {
517
527
let ifile = & free_matches[ 0 ] ;
518
528
if ifile == "-" {
519
529
let mut src = String :: new ( ) ;
520
- io:: stdin ( ) . read_to_string ( & mut src) . unwrap ( ) ;
530
+ let err = if io:: stdin ( ) . read_to_string ( & mut src) . is_err ( ) {
531
+ Some ( io:: Error :: new ( io:: ErrorKind :: InvalidData ,
532
+ "couldn't read from stdin, as it did not contain valid UTF-8" ) )
533
+ } else {
534
+ None
535
+ } ;
521
536
Some ( ( Input :: Str { name : FileName :: Anon , input : src } ,
522
- None ) )
537
+ None , err ) )
523
538
} else {
524
539
Some ( ( Input :: File ( PathBuf :: from ( ifile) ) ,
525
- Some ( PathBuf :: from ( ifile) ) ) )
540
+ Some ( PathBuf :: from ( ifile) ) , None ) )
526
541
}
527
542
} else {
528
543
None
0 commit comments