@@ -357,18 +357,26 @@ fn run_compiler(
357
357
let sess = & compiler. sess;
358
358
let codegen_backend = & * compiler. codegen_backend;
359
359
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. (`abort_if_errors` is used for early exits due
363
+ // to errors.)
364
+ let early_exit = || {
365
+ if let Some ( guar) = sess. dcx( ) . has_errors( ) { Err ( guar) } else { Ok ( ( ) ) }
366
+ } ;
367
+
360
368
// This implements `-Whelp`. It should be handled very early, like
361
369
// `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
362
370
// it must happen after lints are registered, during session creation.
363
371
if sess. opts. describe_lints {
364
372
describe_lints( sess) ;
365
- return sess . compile_status ( ) ;
373
+ return early_exit ( ) ;
366
374
}
367
375
368
376
let early_dcx = EarlyDiagCtxt :: new( sess. opts. error_format) ;
369
377
370
378
if print_crate_info( & early_dcx, codegen_backend, sess, has_input) == Compilation :: Stop {
371
- return sess . compile_status ( ) ;
379
+ return early_exit ( ) ;
372
380
}
373
381
374
382
if !has_input {
@@ -377,16 +385,16 @@ fn run_compiler(
377
385
378
386
if !sess. opts. unstable_opts. ls. is_empty( ) {
379
387
list_metadata( & early_dcx, sess, & * codegen_backend. metadata_loader( ) ) ;
380
- return sess . compile_status ( ) ;
388
+ return early_exit ( ) ;
381
389
}
382
390
383
391
if sess. opts. unstable_opts. link_only {
384
392
process_rlink( sess, compiler) ;
385
- return sess . compile_status ( ) ;
393
+ return early_exit ( ) ;
386
394
}
387
395
388
396
let linker = compiler. enter( |queries| {
389
- let early_exit = || sess . compile_status ( ) . map( |_| None ) ;
397
+ let early_exit = || early_exit ( ) . map( |_| None ) ;
390
398
queries. parse( ) ?;
391
399
392
400
if let Some ( ppm) = & sess. opts. pretty {
0 commit comments