From 1f08bfa383850e3f3e41d1a3baf82ee5cd054f3a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 20 Dec 2023 10:43:16 +1100 Subject: [PATCH] Remove `DiagCtxtInner::span_bug`. `DiagCtxt::span_bug` is different to the other `DiagCtxt::span_*` methods. This commit makes it the same, which requires changing `DiagCtxt::span_delayed_bug` to not do everything within the `inner.borrow_mut()`. --- compiler/rustc_errors/src/lib.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 119881d85b4..3f86f275051 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -978,7 +978,7 @@ pub fn span_warn_with_code( } pub fn span_bug(&self, span: impl Into, msg: impl Into) -> ! { - self.inner.borrow_mut().span_bug(span, msg) + self.struct_span_bug(span, msg).emit() } /// For documentation on this, see `Session::span_delayed_bug`. @@ -991,14 +991,14 @@ pub fn span_delayed_bug( sp: impl Into, msg: impl Into, ) -> ErrorGuaranteed { - let mut inner = self.inner.borrow_mut(); - if inner.treat_next_err_as_bug() { + let treat_next_err_as_bug = self.inner.borrow().treat_next_err_as_bug(); + if treat_next_err_as_bug { // FIXME: don't abort here if report_delayed_bugs is off - inner.span_bug(sp, msg); + self.span_bug(sp, msg); } let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg); diagnostic.set_span(sp); - inner.emit_diagnostic(diagnostic).unwrap() + self.emit_diagnostic(diagnostic).unwrap() } // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's @@ -1528,14 +1528,6 @@ fn has_errors(&self) -> bool { self.err_count > 0 } - #[track_caller] - fn span_bug(&mut self, sp: impl Into, msg: impl Into) -> ! { - let mut diag = Diagnostic::new(Bug, msg); - diag.set_span(sp); - self.emit_diagnostic(diag); - panic::panic_any(ExplicitBug); - } - fn failure_note(&mut self, msg: impl Into) { self.emit_diagnostic(Diagnostic::new(FailureNote, msg)); }