Skip to content

Commit 143d980

Browse files
committed
Remove DiagCtxtInner::span_bug.
`DiagCtxt::span_bug` is different to the other `DiagCtxt::span_*` methods. This commit makes it the same, which requires: - introducing `DiagCtxt::struct_span_bug`; - changing `DiagCtxt::span_delayed_bug` a little.
1 parent 73714bb commit 143d980

File tree

1 file changed

+18
-13
lines changed
  • compiler/rustc_errors/src

1 file changed

+18
-13
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,19 @@ impl DiagCtxt {
720720
self.inner.borrow_mut().emit_stashed_diagnostics()
721721
}
722722

723+
/// Construct a builder at the `Bug` level at the given `span` and with the `msg`.
724+
#[rustc_lint_diagnostics]
725+
#[track_caller]
726+
pub fn struct_span_bug(
727+
&self,
728+
span: impl Into<MultiSpan>,
729+
msg: impl Into<DiagnosticMessage>,
730+
) -> DiagnosticBuilder<'_, BugAbort> {
731+
let mut result = self.struct_bug(msg);
732+
result.set_span(span);
733+
result
734+
}
735+
723736
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
724737
///
725738
/// Attempting to `.emit()` the builder will only emit if either:
@@ -965,7 +978,7 @@ impl DiagCtxt {
965978
}
966979

967980
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
968-
self.inner.borrow_mut().span_bug(span, msg)
981+
self.struct_span_bug(span, msg).emit()
969982
}
970983

971984
/// For documentation on this, see `Session::span_delayed_bug`.
@@ -978,14 +991,14 @@ impl DiagCtxt {
978991
sp: impl Into<MultiSpan>,
979992
msg: impl Into<DiagnosticMessage>,
980993
) -> ErrorGuaranteed {
981-
let mut inner = self.inner.borrow_mut();
982-
if inner.treat_next_err_as_bug() {
994+
let treat_next_err_as_bug = self.inner.borrow().treat_next_err_as_bug();
995+
if treat_next_err_as_bug {
983996
// FIXME: don't abort here if report_delayed_bugs is off
984-
inner.span_bug(sp, msg);
997+
self.span_bug(sp, msg);
985998
}
986999
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
9871000
diagnostic.set_span(sp);
988-
inner.emit_diagnostic(diagnostic).unwrap()
1001+
self.emit_diagnostic(diagnostic).unwrap()
9891002
}
9901003

9911004
// FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's
@@ -1515,14 +1528,6 @@ impl DiagCtxtInner {
15151528
self.err_count > 0
15161529
}
15171530

1518-
#[track_caller]
1519-
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1520-
let mut diag = Diagnostic::new(Bug, msg);
1521-
diag.set_span(sp);
1522-
self.emit_diagnostic(diag);
1523-
panic::panic_any(ExplicitBug);
1524-
}
1525-
15261531
fn failure_note(&mut self, msg: impl Into<DiagnosticMessage>) {
15271532
self.emit_diagnostic(Diagnostic::new(FailureNote, msg));
15281533
}

0 commit comments

Comments
 (0)