@@ -144,16 +144,6 @@ pub const EXIT_FAILURE: i32 = 1;
144144pub  const  DEFAULT_BUG_REPORT_URL :  & str  = "https://github.com/rust-lang/rust/issues/new\  
145145     ?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md"; 
146146
147- pub  fn  abort_on_err<T >( result:  Result <T ,  ErrorGuaranteed >,  sess:  & Session )  -> T  { 
148-     match  result { 
149-         Err ( ..)  => { 
150-             sess. dcx( ) . abort_if_errors( ) ; 
151-             panic!( "error reported but abort_if_errors didn't abort???" ) ; 
152-         } 
153-         Ok ( x)  => x, 
154-     } 
155- } 
156- 
157147pub  trait  Callbacks  { 
158148    /// Called before creating the compiler instance 
159149     fn  config( & mut  self ,  _config:  & mut  interface:: Config )  { } 
@@ -349,27 +339,33 @@ fn run_compiler(
349339        } , 
350340    } ; 
351341
352-     callbacks. config( & mut  config) ; 
353- 
354-     default_early_dcx. abort_if_errors( ) ; 
355342    drop( default_early_dcx) ; 
356343
344+     callbacks. config( & mut  config) ; 
345+ 
357346    interface:: run_compiler( config,  |compiler| { 
358347        let  sess = & compiler. sess; 
359348        let  codegen_backend = & * compiler. codegen_backend; 
360349
350+         // This is used for early exits unrelated to errors. E.g. when just 
351+         // printing some information without compiling, or exiting immediately 
352+         // after parsing, etc. 
353+         let  early_exit = || { 
354+             if  let  Some ( guar)  = sess. dcx( ) . has_errors( )  {  Err ( guar)  }  else {  Ok ( ( ) )  } 
355+         } ; 
356+ 
361357        // This implements `-Whelp`. It should be handled very early, like 
362358        // `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because 
363359        // it must happen after lints are registered, during session creation. 
364360        if  sess. opts. describe_lints { 
365361            describe_lints( sess) ; 
366-             return  sess . compile_status ( ) ; 
362+             return  early_exit ( ) ; 
367363        } 
368364
369365        let  early_dcx = EarlyDiagCtxt :: new( sess. opts. error_format) ; 
370366
371367        if  print_crate_info( & early_dcx,  codegen_backend,  sess,  has_input)  == Compilation :: Stop  { 
372-             return  sess . compile_status ( ) ; 
368+             return  early_exit ( ) ; 
373369        } 
374370
375371        if  !has_input { 
@@ -378,16 +374,16 @@ fn run_compiler(
378374
379375        if  !sess. opts. unstable_opts. ls. is_empty( )  { 
380376            list_metadata( & early_dcx,  sess,  & * codegen_backend. metadata_loader( ) ) ; 
381-             return  sess . compile_status ( ) ; 
377+             return  early_exit ( ) ; 
382378        } 
383379
384380        if  sess. opts. unstable_opts. link_only { 
385381            process_rlink( sess,  compiler) ; 
386-             return  sess . compile_status ( ) ; 
382+             return  early_exit ( ) ; 
387383        } 
388384
389385        let  linker = compiler. enter( |queries| { 
390-             let  early_exit = || sess . compile_status ( ) . map( |_| None ) ; 
386+             let  early_exit = || early_exit ( ) . map( |_| None ) ; 
391387            queries. parse( ) ?; 
392388
393389            if  let  Some ( ppm)  = & sess. opts. pretty { 
@@ -659,10 +655,11 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
659655                } ; 
660656            } 
661657        } ; 
662-         let  result = compiler. codegen_backend. link( sess,  codegen_results,  & outputs) ; 
663-         abort_on_err( result,  sess) ; 
658+         if  compiler. codegen_backend. link( sess,  codegen_results,  & outputs) . is_err( )  { 
659+             FatalError . raise( ) ; 
660+         } 
664661    }  else { 
665-         dcx. emit_fatal( RlinkNotAFile  { } ) 
662+         dcx. emit_fatal( RlinkNotAFile  { } ) ; 
666663    } 
667664} 
668665
0 commit comments