Skip to content

Commit 6ac0689

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 85a86c8 commit 6ac0689

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
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;
@@ -724,7 +724,7 @@ fn link_dwarf_object<'a>(
724724
Ok(()) => {}
725725
Err(e) => {
726726
sess.dcx().emit_err(errors::ThorinErrorWrapper(e));
727-
sess.dcx().abort_if_errors();
727+
FatalError.raise();
728728
}
729729
}
730730
}
@@ -1001,7 +1001,7 @@ fn link_natively<'a>(
10011001
sess.dcx().emit_note(errors::CheckInstalledVisualStudio);
10021002
sess.dcx().emit_note(errors::InsufficientVSCodeProduct);
10031003
}
1004-
sess.dcx().abort_if_errors();
1004+
FatalError.raise();
10051005
}
10061006
}
10071007

compiler/rustc_codegen_ssa/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
2020
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
2121
use rustc_data_structures::sync::par_map;
2222
use rustc_data_structures::unord::UnordMap;
23+
use rustc_errors::FatalError;
2324
use rustc_hir as hir;
2425
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2526
use rustc_hir::lang_items::LangItem;
@@ -451,8 +452,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
451452
let span = cx.tcx().def_span(rust_main_def_id);
452453
let dcx = cx.tcx().dcx();
453454
dcx.emit_err(errors::MultipleMainFunctions { span });
454-
dcx.abort_if_errors();
455-
bug!();
455+
FatalError.raise();
456456
};
457457

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

compiler/rustc_errors/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ impl DiagCtxt {
877877
}
878878
}
879879

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

compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
99
use rustc_data_structures::parallel;
1010
use rustc_data_structures::steal::Steal;
1111
use rustc_data_structures::sync::{Lrc, OnceLock, WorkerLocal};
12-
use rustc_errors::PResult;
12+
use rustc_errors::{FatalError, PResult};
1313
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
1414
use rustc_feature::Features;
1515
use rustc_fs_util::try_canonicalize;
@@ -938,7 +938,7 @@ pub fn start_codegen<'tcx>(
938938
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
939939
let dcx = tcx.dcx();
940940
dcx.emit_err(errors::CantEmitMIR { error });
941-
dcx.abort_if_errors();
941+
FatalError.raise();
942942
}
943943
}
944944

compiler/rustc_session/src/output.rs

+2-1
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

+2-9
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, Diagnostic, DiagnosticBuilder,
25-
ErrorGuaranteed, MultiSpan, StashKey, StringPart,
25+
ErrorGuaranteed, 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)