Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e55df62

Browse files
committed
Remove an unchecked_claim_error_was_emitted call.
When `catch_fatal_errors` catches a `FatalErrorMarker`, it returns an `ErrorGuaranteed` that is conjured out of thin air with `unchecked_claim_error_was_emitted`. But that `ErrorGuaranteed` is never used. This commit changes it to instead conjure a `FatalError` out of thin air. (A non-deprecated action!) This makes more sense because `FatalError` and `FatalErrorMarker` are a natural pairing -- a `FatalErrorMarker` is created by calling `FatalError::raise`, so this is effectively getting back the original `FatalError`. This requires a tiny change in `catch_with_exit_code`. The old result of the `catch_fatal_errors` call there was `Result<Result<(), ErrorGuaranteed>, ErrorGuaranteed>` which could be `flatten`ed into `Result<(), ErrorGuaranteed>`. The new result of the `catch_fatal_errors` calls is `Result<Result<(), ErrorGuaranteed>, FatalError>`, which can't be `flatten`ed but is still easily matched for the success case.
1 parent 8d1c20a commit e55df62

File tree

1 file changed

+8
-7
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+8
-7
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use rustc_data_structures::profiling::{
2424
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
2525
};
2626
use rustc_errors::registry::Registry;
27-
use rustc_errors::{markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, PResult};
27+
use rustc_errors::{
28+
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
29+
};
2830
use rustc_feature::find_gated_cfg;
2931
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
3032
use rustc_interface::{interface, Queries};
@@ -1231,11 +1233,10 @@ fn parse_crate_attrs<'a>(sess: &'a Session) -> PResult<'a, ast::AttrVec> {
12311233
/// The compiler currently unwinds with a special sentinel value to abort
12321234
/// compilation on fatal errors. This function catches that sentinel and turns
12331235
/// the panic into a `Result` instead.
1234-
pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorGuaranteed> {
1236+
pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, FatalError> {
12351237
catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| {
12361238
if value.is::<rustc_errors::FatalErrorMarker>() {
1237-
#[allow(deprecated)]
1238-
ErrorGuaranteed::unchecked_claim_error_was_emitted()
1239+
FatalError
12391240
} else {
12401241
panic::resume_unwind(value);
12411242
}
@@ -1245,9 +1246,9 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorGuarantee
12451246
/// Variant of `catch_fatal_errors` for the `interface::Result` return type
12461247
/// that also computes the exit code.
12471248
pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
1248-
match catch_fatal_errors(f).flatten() {
1249-
Ok(()) => EXIT_SUCCESS,
1250-
Err(_) => EXIT_FAILURE,
1249+
match catch_fatal_errors(f) {
1250+
Ok(Ok(())) => EXIT_SUCCESS,
1251+
_ => EXIT_FAILURE,
12511252
}
12521253
}
12531254

0 commit comments

Comments
 (0)