Skip to content

Commit 4da67ff

Browse files
committed
Replace unnecessary abort_if_errors.
Replace `abort_if_errors` calls that are certain to abort -- because we emit an error immediately beforehand -- with `FatalErro.raise()`.
1 parent 4400644 commit 4da67ff

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::CRATE_NODE_ID;
33
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
44
use rustc_data_structures::memmap::Mmap;
55
use rustc_data_structures::temp_dir::MaybeTempDir;
6-
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
6+
use rustc_errors::{DiagCtxt, ErrorGuaranteed, FatalError};
77
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
88
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
99
use rustc_metadata::find_native_static_library;
@@ -722,10 +722,7 @@ fn link_dwarf_object<'a>(
722722
Ok(())
723723
}) {
724724
Ok(()) => {}
725-
Err(e) => {
726-
sess.dcx().emit_err(errors::ThorinErrorWrapper(e));
727-
sess.dcx().abort_if_errors();
728-
}
725+
Err(e) => sess.dcx().emit_fatal(errors::ThorinErrorWrapper(e)),
729726
}
730727
}
731728

@@ -1001,7 +998,7 @@ fn link_natively<'a>(
1001998
sess.dcx().emit_note(errors::CheckInstalledVisualStudio);
1002999
sess.dcx().emit_note(errors::InsufficientVSCodeProduct);
10031000
}
1004-
sess.dcx().abort_if_errors();
1001+
FatalError.raise();
10051002
}
10061003
}
10071004

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
449449
let Some(llfn) = cx.declare_c_main(llfty) else {
450450
// FIXME: We should be smart and show a better diagnostic here.
451451
let span = cx.tcx().def_span(rust_main_def_id);
452-
let dcx = cx.tcx().dcx();
453-
dcx.emit_err(errors::MultipleMainFunctions { span });
454-
dcx.abort_if_errors();
455-
bug!();
452+
cx.tcx().dcx().emit_fatal(errors::MultipleMainFunctions { span });
456453
};
457454

458455
// `main` should respect same config for frame pointer elimination as rest of code

compiler/rustc_errors/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ impl DiagCtxt {
876876
}
877877
}
878878

879+
/// This excludes delayed bugs and stashed errors. Used for early aborts
880+
/// after errors occurred -- e.g. because continuing in the face of errors is
881+
/// likely to lead to bad results, such as spurious/uninteresting
882+
/// additional errors -- when returning an error `Result` is difficult.
879883
pub fn abort_if_errors(&self) {
880884
if self.has_errors().is_some() {
881885
FatalError.raise();

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,7 @@ pub fn start_codegen<'tcx>(
936936

937937
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
938938
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
939-
let dcx = tcx.dcx();
940-
dcx.emit_err(errors::CantEmitMIR { error });
941-
dcx.abort_if_errors();
939+
tcx.dcx().emit_fatal(errors::CantEmitMIR { error });
942940
}
943941
}
944942

compiler/rustc_session/src/output.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::errors::{
66
};
77
use crate::Session;
88
use rustc_ast::{self as ast, attr};
9+
use rustc_errors::FatalError;
910
use rustc_span::symbol::sym;
1011
use rustc_span::{Span, Symbol};
1112
use std::path::Path;
@@ -115,7 +116,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
115116
}
116117

117118
if err_count > 0 {
118-
sess.dcx().abort_if_errors();
119+
FatalError.raise();
119120
}
120121
}
121122

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::traits::{
2222
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
2323
use rustc_errors::{
2424
codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
25-
MultiSpan, StashKey, StringPart,
25+
FatalError, MultiSpan, StashKey, StringPart,
2626
};
2727
use rustc_hir as hir;
2828
use rustc_hir::def::{DefKind, Namespace, Res};
@@ -193,14 +193,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
193193
let mut err = self.build_overflow_error(predicate, span, suggest_increasing_limit);
194194
mutate(&mut err);
195195
err.emit();
196-
197-
self.dcx().abort_if_errors();
198-
// FIXME: this should be something like `build_overflow_error_fatal`, which returns
199-
// `DiagnosticBuilder<', !>`. Then we don't even need anything after that `emit()`.
200-
unreachable!(
201-
"did not expect compilation to continue after `abort_if_errors`, \
202-
since an error was definitely emitted!"
203-
);
196+
FatalError.raise();
204197
}
205198

206199
fn build_overflow_error<T>(

0 commit comments

Comments
 (0)