Skip to content

Commit d398a91

Browse files
Store backtrace for must_produce_diag
1 parent cdb775c commit d398a91

File tree

1 file changed

+10
-8
lines changed
  • compiler/rustc_errors/src

1 file changed

+10
-8
lines changed

compiler/rustc_errors/src/lib.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ struct DiagCtxtInner {
442442
emitter: Box<DynEmitter>,
443443

444444
/// Must we produce a diagnostic to justify the use of the expensive
445-
/// `trimmed_def_paths` function?
446-
must_produce_diag: bool,
445+
/// `trimmed_def_paths` function? Backtrace is the location of the call.
446+
must_produce_diag: Option<Backtrace>,
447447

448448
/// Has this diagnostic context printed any diagnostics? (I.e. has
449449
/// `self.emitter.emit_diagnostic()` been called?
@@ -572,10 +572,11 @@ impl Drop for DiagCtxtInner {
572572
}
573573

574574
if !self.has_printed && !self.suppressed_expected_diag && !std::thread::panicking() {
575-
if self.must_produce_diag {
575+
if let Some(backtrace) = &self.must_produce_diag {
576576
panic!(
577-
"must_produce_diag: trimmed_def_paths called but no diagnostics emitted; \
578-
use `DelayDm` for lints or `with_no_trimmed_paths` for debugging"
577+
"must_produce_diag: `trimmed_def_paths` called but no diagnostics emitted; \
578+
use `DelayDm` for lints or `with_no_trimmed_paths` for debugging. \
579+
called at: {backtrace}"
579580
);
580581
}
581582
}
@@ -721,7 +722,7 @@ impl DiagCtxt {
721722
*delayed_bugs = Default::default();
722723
*deduplicated_err_count = 0;
723724
*deduplicated_warn_count = 0;
724-
*must_produce_diag = false;
725+
*must_produce_diag = None;
725726
*has_printed = false;
726727
*suppressed_expected_diag = false;
727728
*taught_diagnostics = Default::default();
@@ -1091,8 +1092,9 @@ impl DiagCtxt {
10911092

10921093
/// Used when trimmed_def_paths is called and we must produce a diagnostic
10931094
/// to justify its cost.
1095+
#[track_caller]
10941096
pub fn set_must_produce_diag(&self) {
1095-
self.inner.borrow_mut().must_produce_diag = true;
1097+
self.inner.borrow_mut().must_produce_diag = Some(Backtrace::capture());
10961098
}
10971099
}
10981100

@@ -1387,7 +1389,7 @@ impl DiagCtxtInner {
13871389
deduplicated_err_count: 0,
13881390
deduplicated_warn_count: 0,
13891391
emitter,
1390-
must_produce_diag: false,
1392+
must_produce_diag: None,
13911393
has_printed: false,
13921394
suppressed_expected_diag: false,
13931395
taught_diagnostics: Default::default(),

0 commit comments

Comments
 (0)