@@ -373,20 +373,21 @@ fn run_compiler(
373
373
374
374
let handler = EarlyErrorHandler :: new( sess. opts. error_format) ;
375
375
376
- let should_stop = print_crate_info( & handler, codegen_backend, sess, has_input) ;
376
+ if print_crate_info( & handler, codegen_backend, sess, has_input) == Compilation :: Stop {
377
+ return sess. compile_status( ) ;
378
+ }
377
379
378
380
if !has_input {
379
- if should_stop == Compilation :: Continue {
380
- handler. early_error( "no input filename given" )
381
- }
382
- return sess. compile_status( ) ;
381
+ handler. early_error( "no input filename given" ) ; // this is fatal
383
382
}
384
383
385
- let should_stop = should_stop
386
- . and_then( || list_metadata( & handler, sess, & * codegen_backend. metadata_loader( ) ) )
387
- . and_then( || try_process_rlink( sess, compiler) ) ;
384
+ if !sess. opts. unstable_opts. ls. is_empty( ) {
385
+ list_metadata( & handler, sess, & * codegen_backend. metadata_loader( ) ) ;
386
+ return sess. compile_status( ) ;
387
+ }
388
388
389
- if should_stop == Compilation :: Stop {
389
+ if sess. opts. unstable_opts. link_only {
390
+ process_rlink( sess, compiler) ;
390
391
return sess. compile_status( ) ;
391
392
}
392
393
@@ -539,15 +540,6 @@ pub enum Compilation {
539
540
Continue ,
540
541
}
541
542
542
- impl Compilation {
543
- fn and_then<F : FnOnce ( ) -> Compilation >( self , next: F ) -> Compilation {
544
- match self {
545
- Compilation :: Stop => Compilation :: Stop ,
546
- Compilation :: Continue => next( ) ,
547
- }
548
- }
549
- }
550
-
551
543
fn handle_explain( handler: & EarlyErrorHandler , registry: Registry , code: & str , color: ColorConfig ) {
552
544
let upper_cased_code = code. to_ascii_uppercase( ) ;
553
545
let normalised =
@@ -652,70 +644,60 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
652
644
}
653
645
}
654
646
655
- fn try_process_rlink( sess: & Session , compiler: & interface:: Compiler ) -> Compilation {
656
- if sess. opts. unstable_opts. link_only {
657
- if let Input :: File ( file) = & sess. io. input {
658
- let outputs = compiler. build_output_filenames( sess, & [ ] ) ;
659
- let rlink_data = fs:: read( file) . unwrap_or_else( |err| {
660
- sess. emit_fatal( RlinkUnableToRead { err } ) ;
661
- } ) ;
662
- let codegen_results = match CodegenResults :: deserialize_rlink( sess, rlink_data) {
663
- Ok ( codegen) => codegen,
664
- Err ( err) => {
665
- match err {
666
- CodegenErrors :: WrongFileType => sess. emit_fatal( RLinkWrongFileType ) ,
667
- CodegenErrors :: EmptyVersionNumber => {
668
- sess. emit_fatal( RLinkEmptyVersionNumber )
669
- }
670
- CodegenErrors :: EncodingVersionMismatch { version_array, rlink_version } => {
671
- sess. emit_fatal( RLinkEncodingVersionMismatch {
672
- version_array,
673
- rlink_version,
674
- } )
675
- }
676
- CodegenErrors :: RustcVersionMismatch { rustc_version } => {
677
- sess. emit_fatal( RLinkRustcVersionMismatch {
678
- rustc_version,
679
- current_version: sess. cfg_version,
680
- } )
681
- }
682
- } ;
683
- }
684
- } ;
685
- let result = compiler. codegen_backend( ) . link( sess, codegen_results, & outputs) ;
686
- abort_on_err( result, sess) ;
687
- } else {
688
- sess. emit_fatal( RlinkNotAFile { } )
689
- }
690
- Compilation :: Stop
647
+ fn process_rlink( sess: & Session , compiler: & interface:: Compiler ) {
648
+ assert!( sess. opts. unstable_opts. link_only) ;
649
+ if let Input :: File ( file) = & sess. io. input {
650
+ let outputs = compiler. build_output_filenames( sess, & [ ] ) ;
651
+ let rlink_data = fs:: read( file) . unwrap_or_else( |err| {
652
+ sess. emit_fatal( RlinkUnableToRead { err } ) ;
653
+ } ) ;
654
+ let codegen_results = match CodegenResults :: deserialize_rlink( sess, rlink_data) {
655
+ Ok ( codegen) => codegen,
656
+ Err ( err) => {
657
+ match err {
658
+ CodegenErrors :: WrongFileType => sess. emit_fatal( RLinkWrongFileType ) ,
659
+ CodegenErrors :: EmptyVersionNumber => sess. emit_fatal( RLinkEmptyVersionNumber ) ,
660
+ CodegenErrors :: EncodingVersionMismatch { version_array, rlink_version } => sess
661
+ . emit_fatal( RLinkEncodingVersionMismatch { version_array, rlink_version } ) ,
662
+ CodegenErrors :: RustcVersionMismatch { rustc_version } => {
663
+ sess. emit_fatal( RLinkRustcVersionMismatch {
664
+ rustc_version,
665
+ current_version: sess. cfg_version,
666
+ } )
667
+ }
668
+ } ;
669
+ }
670
+ } ;
671
+ let result = compiler. codegen_backend( ) . link( sess, codegen_results, & outputs) ;
672
+ abort_on_err( result, sess) ;
691
673
} else {
692
- Compilation :: Continue
674
+ sess . emit_fatal ( RlinkNotAFile { } )
693
675
}
694
676
}
695
677
696
678
fn list_metadata(
697
679
handler: & EarlyErrorHandler ,
698
680
sess: & Session ,
699
681
metadata_loader: & dyn MetadataLoader ,
700
- ) -> Compilation {
701
- let ls_kinds = & sess. opts. unstable_opts. ls;
702
- if !ls_kinds. is_empty( ) {
703
- match sess. io. input {
704
- Input :: File ( ref ifile) => {
705
- let path = & ( * ifile) ;
706
- let mut v = Vec :: new( ) ;
707
- locator:: list_file_metadata( & sess. target, path, metadata_loader, & mut v, ls_kinds)
708
- . unwrap( ) ;
709
- safe_println!( "{}" , String :: from_utf8( v) . unwrap( ) ) ;
710
- }
711
- Input :: Str { .. } => {
712
- handler. early_error( "cannot list metadata for stdin" ) ;
713
- }
682
+ ) {
683
+ match sess. io. input {
684
+ Input :: File ( ref ifile) => {
685
+ let path = & ( * ifile) ;
686
+ let mut v = Vec :: new( ) ;
687
+ locator:: list_file_metadata(
688
+ & sess. target,
689
+ path,
690
+ metadata_loader,
691
+ & mut v,
692
+ & sess. opts. unstable_opts. ls,
693
+ )
694
+ . unwrap( ) ;
695
+ safe_println!( "{}" , String :: from_utf8( v) . unwrap( ) ) ;
696
+ }
697
+ Input :: Str { .. } => {
698
+ handler. early_error( "cannot list metadata for stdin" ) ;
714
699
}
715
- return Compilation :: Stop ;
716
700
}
717
-
718
- Compilation :: Continue
719
701
}
720
702
721
703
fn print_crate_info(
0 commit comments