From 2ea7a37e1113febac8603729e33fdd94f2738807 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 4 Jan 2024 12:54:23 +1100 Subject: Add `DiagCtxt::delayed_bug`. We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`. --- compiler/rustc_errors/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_errors') diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index e3aa9477874..a80058c596b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -865,10 +865,16 @@ impl DiagCtxt { /// For example, it can be used to create an [`ErrorGuaranteed`] /// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission /// directly). - /// - /// If no span is available, use [`DUMMY_SP`]. - /// - /// [`DUMMY_SP`]: rustc_span::DUMMY_SP + #[track_caller] + pub fn delayed_bug(&self, msg: impl Into) -> ErrorGuaranteed { + let treat_next_err_as_bug = self.inner.borrow().treat_next_err_as_bug(); + if treat_next_err_as_bug { + self.bug(msg); + } + DiagnosticBuilder::::new(self, DelayedBug, msg).emit() + } + + /// Like `delayed_bug`, but takes an additional span. /// /// Note: this function used to be called `delay_span_bug`. It was renamed /// to match similar functions like `span_err`, `span_warn`, etc. @@ -882,9 +888,7 @@ impl DiagCtxt { if treat_next_err_as_bug { self.span_bug(sp, msg); } - let mut diagnostic = Diagnostic::new(DelayedBug, msg); - diagnostic.span(sp); - self.emit_diagnostic(diagnostic).unwrap() + DiagnosticBuilder::::new(self, DelayedBug, msg).span_mv(sp).emit() } // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's -- cgit 1.4.1-3-g733a5