Skip to content

Commit a094903

Browse files
committed
Inline and remove abort_on_err.
It's clumsy and doesn't improve readability.
1 parent 2eb88a7 commit a094903

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

compiler/rustc_driver_impl/src/lib.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,6 @@ pub const EXIT_FAILURE: i32 = 1;
144144
pub 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-
157147
pub trait Callbacks {
158148
/// Called before creating the compiler instance
159149
fn config(&mut self, _config: &mut interface::Config) {}
@@ -665,10 +655,11 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
665655
};
666656
}
667657
};
668-
let result = compiler.codegen_backend.link(sess, codegen_results, &outputs);
669-
abort_on_err(result, sess);
658+
if compiler.codegen_backend.link(sess, codegen_results, &outputs).is_err() {
659+
FatalError.raise();
660+
}
670661
} else {
671-
dcx.emit_fatal(RlinkNotAFile {})
662+
dcx.emit_fatal(RlinkNotAFile {});
672663
}
673664
}
674665

compiler/rustc_driver_impl/src/pretty.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use rustc_ast as ast;
44
use rustc_ast_pretty::pprust as pprust_ast;
5+
use rustc_errors::FatalError;
56
use rustc_hir as hir;
67
use rustc_hir_pretty as pprust_hir;
78
use rustc_middle::bug;
@@ -18,7 +19,6 @@ use std::fmt::Write;
1819

1920
pub use self::PpMode::*;
2021
pub use self::PpSourceMode::*;
21-
use crate::abort_on_err;
2222

2323
struct AstNoAnn;
2424

@@ -243,7 +243,9 @@ impl<'tcx> PrintExtra<'tcx> {
243243

244244
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
245245
if ppm.needs_analysis() {
246-
abort_on_err(ex.tcx().analysis(()), sess);
246+
if ex.tcx().analysis(()).is_err() {
247+
FatalError.raise();
248+
}
247249
}
248250

249251
let (src, src_name) = get_source(sess);
@@ -334,7 +336,9 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
334336
ThirTree => {
335337
let tcx = ex.tcx();
336338
let mut out = String::new();
337-
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
339+
if rustc_hir_analysis::check_crate(tcx).is_err() {
340+
FatalError.raise();
341+
}
338342
debug!("pretty printing THIR tree");
339343
for did in tcx.hir().body_owners() {
340344
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_tree(did));
@@ -344,7 +348,9 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
344348
ThirFlat => {
345349
let tcx = ex.tcx();
346350
let mut out = String::new();
347-
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
351+
if rustc_hir_analysis::check_crate(tcx).is_err() {
352+
FatalError.raise();
353+
}
348354
debug!("pretty printing THIR flat");
349355
for did in tcx.hir().body_owners() {
350356
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_flat(did));

src/librustdoc/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ use std::io::{self, IsTerminal};
7878
use std::process;
7979
use std::sync::{atomic::AtomicBool, Arc};
8080

81-
use rustc_driver::abort_on_err;
82-
use rustc_errors::ErrorGuaranteed;
81+
use rustc_errors::{ErrorGuaranteed, FatalError};
8382
use rustc_interface::interface;
8483
use rustc_middle::ty::TyCtxt;
8584
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
@@ -779,7 +778,7 @@ fn main_args(
779778
}
780779

781780
compiler.enter(|queries| {
782-
let mut gcx = abort_on_err(queries.global_ctxt(), sess);
781+
let Ok(mut gcx) = queries.global_ctxt() else { FatalError.raise() };
783782
if sess.dcx().has_errors().is_some() {
784783
sess.dcx().fatal("Compilation failed, aborting rustdoc");
785784
}

0 commit comments

Comments
 (0)