diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-04 12:54:23 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-10 07:33:07 +1100 |
| commit | 2ea7a37e1113febac8603729e33fdd94f2738807 (patch) | |
| tree | 06b41ca2baec6e8b67695ae1fbb716e115b4653b /compiler/rustc_errors/src | |
| parent | 3c4f1d85af07f394da922f0bd9ff7c0a91e81f45 (diff) | |
| download | rust-2ea7a37e1113febac8603729e33fdd94f2738807.tar.gz rust-2ea7a37e1113febac8603729e33fdd94f2738807.zip | |
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`.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 18 |
1 files changed, 11 insertions, 7 deletions
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<DiagnosticMessage>) -> 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::<ErrorGuaranteed>::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::<ErrorGuaranteed>::new(self, DelayedBug, msg).span_mv(sp).emit() } // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's |
