From 6077fdd219c521a6f039c7fe3e5aacfa15757edc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 5 May 2023 17:31:54 +0000 Subject: [PATCH] Mark `ErrorGuaranteed` constructor as deprecated so people don't use it --- compiler/rustc_driver_impl/src/lib.rs | 1 + .../rustc_errors/src/diagnostic_builder.rs | 1 + compiler/rustc_errors/src/lib.rs | 35 +++++++++++-------- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 6 +++- compiler/rustc_span/src/lib.rs | 1 + src/librustdoc/lib.rs | 7 +++- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 5fac485de64..2d529a34d8e 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1178,6 +1178,7 @@ fn extra_compiler_flags() -> Option<(Vec, bool)> { pub fn catch_fatal_errors R, R>(f: F) -> Result { catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| { if value.is::() { + #[allow(deprecated)] ErrorGuaranteed::unchecked_claim_error_was_emitted() } else { panic::resume_unwind(value); diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 1f1398342b1..ef528d87cb2 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -192,6 +192,7 @@ impl EmissionGuarantee for ErrorGuaranteed { became non-error ({:?}), after original `.emit()`", db.inner.diagnostic.level, ); + #[allow(deprecated)] ErrorGuaranteed::unchecked_claim_error_was_emitted() } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f9c062d3a21..fcbd9a53b48 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1069,26 +1069,29 @@ impl Handler { } pub fn has_errors(&self) -> Option { - self.inner.borrow().has_errors().then(ErrorGuaranteed::unchecked_claim_error_was_emitted) + self.inner.borrow().has_errors().then(|| { + #[allow(deprecated)] + ErrorGuaranteed::unchecked_claim_error_was_emitted() + }) } pub fn has_errors_or_lint_errors(&self) -> Option { - self.inner - .borrow() - .has_errors_or_lint_errors() - .then(ErrorGuaranteed::unchecked_claim_error_was_emitted) + self.inner.borrow().has_errors_or_lint_errors().then(|| { + #[allow(deprecated)] + ErrorGuaranteed::unchecked_claim_error_was_emitted() + }) } pub fn has_errors_or_delayed_span_bugs(&self) -> Option { - self.inner - .borrow() - .has_errors_or_delayed_span_bugs() - .then(ErrorGuaranteed::unchecked_claim_error_was_emitted) + self.inner.borrow().has_errors_or_delayed_span_bugs().then(|| { + #[allow(deprecated)] + ErrorGuaranteed::unchecked_claim_error_was_emitted() + }) } pub fn is_compilation_going_to_fail(&self) -> Option { - self.inner - .borrow() - .is_compilation_going_to_fail() - .then(ErrorGuaranteed::unchecked_claim_error_was_emitted) + self.inner.borrow().is_compilation_going_to_fail().then(|| { + #[allow(deprecated)] + ErrorGuaranteed::unchecked_claim_error_was_emitted() + }) } pub fn print_error_count(&self, registry: &Registry) { @@ -1333,6 +1336,7 @@ impl HandlerInner { .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace)); if !self.flags.report_delayed_bugs { + #[allow(deprecated)] return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); } } @@ -1411,7 +1415,10 @@ impl HandlerInner { self.bump_err_count(); } - guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + #[allow(deprecated)] + { + guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + } } else { self.bump_warn_count(); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index cbedbad1f38..9e78e6acba5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -854,9 +854,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let result = self .resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id) .or_else(|error| { + let guar = self + .tcx + .sess + .delay_span_bug(span, "method resolution should've emitted an error"); let result = match error { method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)), - _ => Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()), + _ => Err(guar), }; // If we have a path like `MyTrait::missing_method`, then don't register diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 8a900ca427e..5106bd8da1b 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2200,6 +2200,7 @@ pub struct ErrorGuaranteed(()); impl ErrorGuaranteed { /// To be used only if you really know what you are doing... ideally, we would find a way to /// eliminate all calls to this method. + #[deprecated = "`Session::delay_span_bug` should be preferred over this function"] pub fn unchecked_claim_error_was_emitted() -> Self { ErrorGuaranteed(()) } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 263ce3d93b9..1d4892bcb2a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -172,7 +172,11 @@ pub fn main() { let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() { Some(args) => main_args(&args), - _ => Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()), + _ => + { + #[allow(deprecated)] + Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()) + } }); process::exit(exit_code); } @@ -725,6 +729,7 @@ fn main_args(at_args: &[String]) -> MainResult { return if code == 0 { Ok(()) } else { + #[allow(deprecated)] Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()) }; }