Inline and remove abort_on_err.

It's clumsy and doesn't improve readability.
This commit is contained in:
Nicholas Nethercote 2024-02-19 13:51:53 +11:00
parent 4da67fff61
commit f16c226af3
3 changed files with 16 additions and 20 deletions

View File

@ -144,16 +144,6 @@ pub(super) fn install() {}
pub const DEFAULT_BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\ 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"; ?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 { pub trait Callbacks {
/// Called before creating the compiler instance /// Called before creating the compiler instance
fn config(&mut self, _config: &mut interface::Config) {} fn config(&mut self, _config: &mut interface::Config) {}
@ -665,10 +655,11 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
}; };
} }
}; };
let result = compiler.codegen_backend.link(sess, codegen_results, &outputs); if compiler.codegen_backend.link(sess, codegen_results, &outputs).is_err() {
abort_on_err(result, sess); FatalError.raise();
}
} else { } else {
dcx.emit_fatal(RlinkNotAFile {}) dcx.emit_fatal(RlinkNotAFile {});
} }
} }

View File

@ -2,6 +2,7 @@
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast_pretty::pprust as pprust_ast; use rustc_ast_pretty::pprust as pprust_ast;
use rustc_errors::FatalError;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::bug; use rustc_middle::bug;
@ -18,7 +19,6 @@
pub use self::PpMode::*; pub use self::PpMode::*;
pub use self::PpSourceMode::*; pub use self::PpSourceMode::*;
use crate::abort_on_err;
struct AstNoAnn; struct AstNoAnn;
@ -243,7 +243,9 @@ fn tcx(&self) -> TyCtxt<'tcx> {
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
if ppm.needs_analysis() { 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); let (src, src_name) = get_source(sess);
@ -334,7 +336,9 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirTree => { ThirTree => {
let tcx = ex.tcx(); let tcx = ex.tcx();
let mut out = String::new(); 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"); debug!("pretty printing THIR tree");
for did in tcx.hir().body_owners() { for did in tcx.hir().body_owners() {
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_tree(did)); 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>) {
ThirFlat => { ThirFlat => {
let tcx = ex.tcx(); let tcx = ex.tcx();
let mut out = String::new(); 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"); debug!("pretty printing THIR flat");
for did in tcx.hir().body_owners() { for did in tcx.hir().body_owners() {
let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_flat(did)); let _ = writeln!(out, "{:?}:\n{}\n", did, tcx.thir_flat(did));

View File

@ -78,8 +78,7 @@
use std::process; use std::process;
use std::sync::{atomic::AtomicBool, Arc}; use std::sync::{atomic::AtomicBool, Arc};
use rustc_driver::abort_on_err; use rustc_errors::{ErrorGuaranteed, FatalError};
use rustc_errors::ErrorGuaranteed;
use rustc_interface::interface; use rustc_interface::interface;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup}; use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
@ -779,7 +778,7 @@ fn main_args(
} }
compiler.enter(|queries| { 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() { if sess.dcx().has_errors().is_some() {
sess.dcx().fatal("Compilation failed, aborting rustdoc"); sess.dcx().fatal("Compilation failed, aborting rustdoc");
} }