Skip to content

Commit 80543f7

Browse files
committed
Inline and remove Session::compile_status.
Because it's now simple enough that it doesn't provide much benefit.
1 parent b2e6fe1 commit 80543f7

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ fn collate_raw_dylibs<'a, 'b>(
487487
}
488488
}
489489
}
490-
sess.compile_status()?;
490+
if let Some(guar) = sess.dcx().has_errors() {
491+
return Err(guar);
492+
}
491493
Ok(dylib_table
492494
.into_iter()
493495
.map(|(name, imports)| {

compiler/rustc_driver_impl/src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -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 {

compiler/rustc_interface/src/queries.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ impl Linker {
261261
let (codegen_results, work_products) =
262262
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames);
263263

264-
sess.compile_status()?;
264+
if let Some(guar) = sess.dcx().has_errors() {
265+
return Err(guar);
266+
}
265267

266268
sess.time("serialize_work_products", || {
267269
rustc_incremental::save_work_product_index(sess, &self.dep_graph, work_products)

compiler/rustc_session/src/session.rs

-8
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,6 @@ impl Session {
317317
err
318318
}
319319

320-
pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> {
321-
if let Some(reported) = self.dcx().has_errors() {
322-
Err(reported)
323-
} else {
324-
Ok(())
325-
}
326-
}
327-
328320
/// Record the fact that we called `trimmed_def_paths`, and do some
329321
/// checking about whether its cost was justified.
330322
pub fn record_trimmed_def_paths(&self) {

src/tools/miri/src/bin/miri.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
6868
queries: &'tcx rustc_interface::Queries<'tcx>,
6969
) -> Compilation {
7070
queries.global_ctxt().unwrap().enter(|tcx| {
71-
if tcx.sess.compile_status().is_err() {
71+
if tcx.sess.dcx().has_errors().is_some() {
7272
tcx.dcx().fatal("miri cannot be run on programs that fail compilation");
7373
}
7474

0 commit comments

Comments
 (0)