about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-12 18:04:27 +0000
committerbors <bors@rust-lang.org>2024-11-12 18:04:27 +0000
commitf7273e0044ad8f35ad27282e4ab776af50b61a54 (patch)
tree1eba963b5f6af156604f649ae02a573a13ec0282 /compiler/rustc_errors/src/lib.rs
parent6503543d11583d1686d4989847b2afbec8d9fdba (diff)
parentf00a31c44de738755ed2628f00690f4b4163be4a (diff)
downloadrust-f7273e0044ad8f35ad27282e4ab776af50b61a54.tar.gz
rust-f7273e0044ad8f35ad27282e4ab776af50b61a54.zip
Auto merge of #132954 - matthiaskrgr:rollup-x3rww9h, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #131831 (extend the "if-unchanged" logic for compiler builds)
 - #132541 (Proper support for cross-crate recursive const stability checks)
 - #132657 (AIX: add run-make support)
 - #132901 (Warn about invalid `mir-enable-passes` pass names)
 - #132923 (Triagebot: Consolidate the T-compiler ad hoc assignment groups)
 - #132938 (Make precise capturing suggestion machine-applicable only if it has no APITs)
 - #132947 (clarify `must_produce_diag` ICE for debugging)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
-rw-r--r--compiler/rustc_errors/src/lib.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 94365a89adc..98200c367f9 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -623,12 +623,25 @@ impl Drop for DiagCtxtInner {
             self.flush_delayed()
         }
 
+        // Sanity check: did we use some of the expensive `trimmed_def_paths` functions
+        // unexpectedly, that is, without producing diagnostics? If so, for debugging purposes, we
+        // suggest where this happened and how to avoid it.
         if !self.has_printed && !self.suppressed_expected_diag && !std::thread::panicking() {
             if let Some(backtrace) = &self.must_produce_diag {
+                let suggestion = match backtrace.status() {
+                    BacktraceStatus::Disabled => String::from(
+                        "Backtraces are currently disabled: set `RUST_BACKTRACE=1` and re-run \
+                        to see where it happened.",
+                    ),
+                    BacktraceStatus::Captured => format!(
+                        "This happened in the following `must_produce_diag` call's backtrace:\n\
+                        {backtrace}",
+                    ),
+                    _ => String::from("(impossible to capture backtrace where this happened)"),
+                };
                 panic!(
-                    "must_produce_diag: `trimmed_def_paths` called but no diagnostics emitted; \
-                     `with_no_trimmed_paths` for debugging. \
-                     called at: {backtrace}"
+                    "`trimmed_def_paths` called, diagnostics were expected but none were emitted. \
+                    Use `with_no_trimmed_paths` for debugging. {suggestion}"
                 );
             }
         }