@@ -442,8 +442,8 @@ struct DiagCtxtInner {
442
442
emitter : Box < DynEmitter > ,
443
443
444
444
/// 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 > ,
447
447
448
448
/// Has this diagnostic context printed any diagnostics? (I.e. has
449
449
/// `self.emitter.emit_diagnostic()` been called?
@@ -572,10 +572,11 @@ impl Drop for DiagCtxtInner {
572
572
}
573
573
574
574
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 {
576
576
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}"
579
580
) ;
580
581
}
581
582
}
@@ -721,7 +722,7 @@ impl DiagCtxt {
721
722
* delayed_bugs = Default :: default ( ) ;
722
723
* deduplicated_err_count = 0 ;
723
724
* deduplicated_warn_count = 0 ;
724
- * must_produce_diag = false ;
725
+ * must_produce_diag = None ;
725
726
* has_printed = false ;
726
727
* suppressed_expected_diag = false ;
727
728
* taught_diagnostics = Default :: default ( ) ;
@@ -1091,8 +1092,9 @@ impl DiagCtxt {
1091
1092
1092
1093
/// Used when trimmed_def_paths is called and we must produce a diagnostic
1093
1094
/// to justify its cost.
1095
+ #[ track_caller]
1094
1096
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 ( ) ) ;
1096
1098
}
1097
1099
}
1098
1100
@@ -1387,7 +1389,7 @@ impl DiagCtxtInner {
1387
1389
deduplicated_err_count : 0 ,
1388
1390
deduplicated_warn_count : 0 ,
1389
1391
emitter,
1390
- must_produce_diag : false ,
1392
+ must_produce_diag : None ,
1391
1393
has_printed : false ,
1392
1394
suppressed_expected_diag : false ,
1393
1395
taught_diagnostics : Default :: default ( ) ,
0 commit comments