Skip to content

Commit

Permalink
Inline and remove abort_on_err.
Browse files Browse the repository at this point in the history
It's clumsy and doesn't improve readability.
  • Loading branch information
nnethercote committed Feb 19, 2024
1 parent 6ac0689 commit 8d50bc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
17 changes: 4 additions & 13 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ pub const EXIT_FAILURE: i32 = 1;
pub const DEFAULT_BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\
?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";

pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, sess: &Session) -> T {
match result {
Err(..) => {
sess.dcx().abort_if_errors();
panic!("error reported but abort_if_errors didn't abort???");
}
Ok(x) => x,
}
}

pub trait Callbacks {
/// Called before creating the compiler instance
fn config(&mut self, _config: &mut interface::Config) {}
Expand Down Expand Up @@ -665,10 +655,11 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
};
}
};
let result = compiler.codegen_backend.link(sess, codegen_results, &outputs);
abort_on_err(result, sess);
if compiler.codegen_backend.link(sess, codegen_results, &outputs).is_err() {
FatalError.raise();
}
} else {
dcx.emit_fatal(RlinkNotAFile {})
dcx.emit_fatal(RlinkNotAFile {});
}
}

Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use rustc_ast as ast;
use rustc_ast_pretty::pprust as pprust_ast;
use rustc_errors::FatalError;
use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir;
use rustc_middle::bug;
Expand All @@ -18,7 +19,6 @@ use std::fmt::Write;

pub use self::PpMode::*;
pub use self::PpSourceMode::*;
use crate::abort_on_err;

struct AstNoAnn;

Expand Down Expand Up @@ -243,7 +243,9 @@ impl<'tcx> PrintExtra<'tcx> {

pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
if ppm.needs_analysis() {
abort_on_err(ex.tcx().analysis(()), sess);
if ex.tcx().analysis(()).is_err() {
FatalError.raise();
}
}

let (src, src_name) = get_source(sess);
Expand Down Expand Up @@ -334,7 +336,9 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirTree => {
let tcx = ex.tcx();
let mut out = String::new();
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
if rustc_hir_analysis::check_crate(tcx).is_err() {
FatalError.raise();
}
debug!("pretty printing THIR tree");
for did in tcx.hir().body_owners() {
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_tree(did));
Expand All @@ -344,7 +348,9 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirFlat => {
let tcx = ex.tcx();
let mut out = String::new();
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
if rustc_hir_analysis::check_crate(tcx).is_err() {
FatalError.raise();
}
debug!("pretty printing THIR flat");
for did in tcx.hir().body_owners() {
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_flat(did));
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ use std::io::{self, IsTerminal};
use std::process;
use std::sync::{atomic::AtomicBool, Arc};

use rustc_driver::abort_on_err;
use rustc_errors::ErrorGuaranteed;
use rustc_errors::{ErrorGuaranteed, FatalError};
use rustc_interface::interface;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
Expand Down Expand Up @@ -779,7 +778,7 @@ fn main_args(
}

compiler.enter(|queries| {
let mut gcx = abort_on_err(queries.global_ctxt(), sess);
let Ok(mut gcx) = queries.global_ctxt() else { FatalError.raise() };
if sess.dcx().has_errors().is_some() {
sess.dcx().fatal("Compilation failed, aborting rustdoc");
}
Expand Down

0 comments on commit 8d50bc1

Please sign in to comment.