Skip to content

Commit 6077fdd

Browse files
Mark ErrorGuaranteed constructor as deprecated so people don't use it
1 parent 82cd953 commit 6077fdd

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
11781178
pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorGuaranteed> {
11791179
catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| {
11801180
if value.is::<rustc_errors::FatalErrorMarker>() {
1181+
#[allow(deprecated)]
11811182
ErrorGuaranteed::unchecked_claim_error_was_emitted()
11821183
} else {
11831184
panic::resume_unwind(value);

compiler/rustc_errors/src/diagnostic_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
192192
became non-error ({:?}), after original `.emit()`",
193193
db.inner.diagnostic.level,
194194
);
195+
#[allow(deprecated)]
195196
ErrorGuaranteed::unchecked_claim_error_was_emitted()
196197
}
197198
}

compiler/rustc_errors/src/lib.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -1069,26 +1069,29 @@ impl Handler {
10691069
}
10701070

10711071
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
1072-
self.inner.borrow().has_errors().then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
1072+
self.inner.borrow().has_errors().then(|| {
1073+
#[allow(deprecated)]
1074+
ErrorGuaranteed::unchecked_claim_error_was_emitted()
1075+
})
10731076
}
10741077

10751078
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
1076-
self.inner
1077-
.borrow()
1078-
.has_errors_or_lint_errors()
1079-
.then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
1079+
self.inner.borrow().has_errors_or_lint_errors().then(|| {
1080+
#[allow(deprecated)]
1081+
ErrorGuaranteed::unchecked_claim_error_was_emitted()
1082+
})
10801083
}
10811084
pub fn has_errors_or_delayed_span_bugs(&self) -> Option<ErrorGuaranteed> {
1082-
self.inner
1083-
.borrow()
1084-
.has_errors_or_delayed_span_bugs()
1085-
.then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
1085+
self.inner.borrow().has_errors_or_delayed_span_bugs().then(|| {
1086+
#[allow(deprecated)]
1087+
ErrorGuaranteed::unchecked_claim_error_was_emitted()
1088+
})
10861089
}
10871090
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
1088-
self.inner
1089-
.borrow()
1090-
.is_compilation_going_to_fail()
1091-
.then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
1091+
self.inner.borrow().is_compilation_going_to_fail().then(|| {
1092+
#[allow(deprecated)]
1093+
ErrorGuaranteed::unchecked_claim_error_was_emitted()
1094+
})
10921095
}
10931096

10941097
pub fn print_error_count(&self, registry: &Registry) {
@@ -1333,6 +1336,7 @@ impl HandlerInner {
13331336
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
13341337

13351338
if !self.flags.report_delayed_bugs {
1339+
#[allow(deprecated)]
13361340
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
13371341
}
13381342
}
@@ -1411,7 +1415,10 @@ impl HandlerInner {
14111415
self.bump_err_count();
14121416
}
14131417

1414-
guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
1418+
#[allow(deprecated)]
1419+
{
1420+
guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
1421+
}
14151422
} else {
14161423
self.bump_warn_count();
14171424
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
854854
let result = self
855855
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
856856
.or_else(|error| {
857+
let guar = self
858+
.tcx
859+
.sess
860+
.delay_span_bug(span, "method resolution should've emitted an error");
857861
let result = match error {
858862
method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
859-
_ => Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()),
863+
_ => Err(guar),
860864
};
861865

862866
// If we have a path like `MyTrait::missing_method`, then don't register

compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,7 @@ pub struct ErrorGuaranteed(());
22002200
impl ErrorGuaranteed {
22012201
/// To be used only if you really know what you are doing... ideally, we would find a way to
22022202
/// eliminate all calls to this method.
2203+
#[deprecated = "`Session::delay_span_bug` should be preferred over this function"]
22032204
pub fn unchecked_claim_error_was_emitted() -> Self {
22042205
ErrorGuaranteed(())
22052206
}

src/librustdoc/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ pub fn main() {
172172

173173
let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() {
174174
Some(args) => main_args(&args),
175-
_ => Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()),
175+
_ =>
176+
{
177+
#[allow(deprecated)]
178+
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
179+
}
176180
});
177181
process::exit(exit_code);
178182
}
@@ -725,6 +729,7 @@ fn main_args(at_args: &[String]) -> MainResult {
725729
return if code == 0 {
726730
Ok(())
727731
} else {
732+
#[allow(deprecated)]
728733
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
729734
};
730735
}

0 commit comments

Comments
 (0)