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