@@ -357,18 +357,25 @@ fn run_compiler(
357357 let sess = & compiler. sess;
358358 let codegen_backend = & * compiler. codegen_backend;
359359
360+ // This is used for early exits unrelated to errors. E.g. when just
361+ // printing some information without compiling, or exiting immediately
362+ // after parsing, etc.
363+ let early_exit = || {
364+ if let Some ( guar) = sess. dcx( ) . has_errors( ) { Err ( guar) } else { Ok ( ( ) ) }
365+ } ;
366+
360367 // This implements `-Whelp`. It should be handled very early, like
361368 // `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
362369 // it must happen after lints are registered, during session creation.
363370 if sess. opts. describe_lints {
364371 describe_lints( sess) ;
365- return sess . compile_status ( ) ;
372+ return early_exit ( ) ;
366373 }
367374
368375 let early_dcx = EarlyDiagCtxt :: new( sess. opts. error_format) ;
369376
370377 if print_crate_info( & early_dcx, codegen_backend, sess, has_input) == Compilation :: Stop {
371- return sess . compile_status ( ) ;
378+ return early_exit ( ) ;
372379 }
373380
374381 if !has_input {
@@ -377,16 +384,16 @@ fn run_compiler(
377384
378385 if !sess. opts. unstable_opts. ls. is_empty( ) {
379386 list_metadata( & early_dcx, sess, & * codegen_backend. metadata_loader( ) ) ;
380- return sess . compile_status ( ) ;
387+ return early_exit ( ) ;
381388 }
382389
383390 if sess. opts. unstable_opts. link_only {
384391 process_rlink( sess, compiler) ;
385- return sess . compile_status ( ) ;
392+ return early_exit ( ) ;
386393 }
387394
388395 let linker = compiler. enter( |queries| {
389- let early_exit = || sess . compile_status ( ) . map( |_| None ) ;
396+ let early_exit = || early_exit ( ) . map( |_| None ) ;
390397 queries. parse( ) ?;
391398
392399 if let Some ( ppm) = & sess. opts. pretty {
0 commit comments