Skip to content

Commit c665925

Browse files
committed
clarify must_produce_diag ICE for debugging
1 parent 9a9dadd commit c665925

File tree

1 file changed

+16
-3
lines changed
  • compiler/rustc_errors/src

1 file changed

+16
-3
lines changed

compiler/rustc_errors/src/lib.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,25 @@ impl Drop for DiagCtxtInner {
623623
self.flush_delayed()
624624
}
625625

626+
// Sanity check: did we use some of the expensive `trimmed_def_paths` functions
627+
// unexpectedly, that is, without producing diagnostics? If so, for debugging purposes, we
628+
// suggest where this happened and how to avoid it.
626629
if !self.has_printed && !self.suppressed_expected_diag && !std::thread::panicking() {
627630
if let Some(backtrace) = &self.must_produce_diag {
631+
let suggestion = match backtrace.status() {
632+
BacktraceStatus::Disabled => String::from(
633+
"Backtraces are currently disabled: set `RUST_BACKTRACE=1` and re-run \
634+
to see where it happened.",
635+
),
636+
BacktraceStatus::Captured => format!(
637+
"This happened in the following `must_produce_diag` call's backtrace:\n\
638+
{backtrace}",
639+
),
640+
_ => String::from("(impossible to capture backtrace where this happened)"),
641+
};
628642
panic!(
629-
"must_produce_diag: `trimmed_def_paths` called but no diagnostics emitted; \
630-
`with_no_trimmed_paths` for debugging. \
631-
called at: {backtrace}"
643+
"`trimmed_def_paths` called, diagnostics were expected but none were emitted. \
644+
Use `with_no_trimmed_paths` for debugging. {suggestion}"
632645
);
633646
}
634647
}

0 commit comments

Comments
 (0)