Skip to content

Commit

Permalink
Replace unnecessary abort_if_errors.
Browse files Browse the repository at this point in the history
Replace `abort_if_errors` calls that are certain to abort -- because
we emit an error immediately beforehand -- with `FatalErro.raise()`.
  • Loading branch information
nnethercote committed Feb 19, 2024
1 parent 85a86c8 commit 6ac0689
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_ast::CRATE_NODE_ID;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
use rustc_errors::{DiagCtxt, ErrorGuaranteed, FatalError};
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_metadata::find_native_static_library;
Expand Down Expand Up @@ -724,7 +724,7 @@ fn link_dwarf_object<'a>(
Ok(()) => {}
Err(e) => {
sess.dcx().emit_err(errors::ThorinErrorWrapper(e));
sess.dcx().abort_if_errors();
FatalError.raise();
}
}
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ fn link_natively<'a>(
sess.dcx().emit_note(errors::CheckInstalledVisualStudio);
sess.dcx().emit_note(errors::InsufficientVSCodeProduct);
}
sess.dcx().abort_if_errors();
FatalError.raise();
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
use rustc_data_structures::sync::par_map;
use rustc_data_structures::unord::UnordMap;
use rustc_errors::FatalError;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
Expand Down Expand Up @@ -451,8 +452,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let span = cx.tcx().def_span(rust_main_def_id);
let dcx = cx.tcx().dcx();
dcx.emit_err(errors::MultipleMainFunctions { span });
dcx.abort_if_errors();
bug!();
FatalError.raise();
};

// `main` should respect same config for frame pointer elimination as rest of code
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,10 @@ impl DiagCtxt {
}
}

/// This excludes delayed bugs and stashed errors. Used for early aborts
/// after errors occurred -- e.g. because continuing in the face of errors is
/// likely to lead to bad results, such as spurious/uninteresting
/// additional errors -- when returning an error `Result` is difficult.
pub fn abort_if_errors(&self) {
if self.has_errors().is_some() {
FatalError.raise();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::parallel;
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{Lrc, OnceLock, WorkerLocal};
use rustc_errors::PResult;
use rustc_errors::{FatalError, PResult};
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
use rustc_feature::Features;
use rustc_fs_util::try_canonicalize;
Expand Down Expand Up @@ -938,7 +938,7 @@ pub fn start_codegen<'tcx>(
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
let dcx = tcx.dcx();
dcx.emit_err(errors::CantEmitMIR { error });
dcx.abort_if_errors();
FatalError.raise();
}
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::errors::{
};
use crate::Session;
use rustc_ast::{self as ast, attr};
use rustc_errors::FatalError;
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
use std::path::Path;
Expand Down Expand Up @@ -115,7 +116,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
}

if err_count > 0 {
sess.dcx().abort_if_errors();
FatalError.raise();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::traits::{
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder,
ErrorGuaranteed, MultiSpan, StashKey, StringPart,
ErrorGuaranteed, FatalError, MultiSpan, StashKey, StringPart,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace, Res};
Expand Down Expand Up @@ -193,14 +193,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let mut err = self.build_overflow_error(predicate, span, suggest_increasing_limit);
mutate(&mut err);
err.emit();

self.dcx().abort_if_errors();
// FIXME: this should be something like `build_overflow_error_fatal`, which returns
// `DiagnosticBuilder<', !>`. Then we don't even need anything after that `emit()`.
unreachable!(
"did not expect compilation to continue after `abort_if_errors`, \
since an error was definitely emitted!"
);
FatalError.raise();
}

fn build_overflow_error<T>(
Expand Down

0 comments on commit 6ac0689

Please sign in to comment.