Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store backtrace for must_produce_diag #122299

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ struct DiagCtxtInner {
emitter: Box<DynEmitter>,

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

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

if !self.has_printed && !self.suppressed_expected_diag && !std::thread::panicking() {
if self.must_produce_diag {
if let Some(backtrace) = &self.must_produce_diag {
panic!(
"must_produce_diag: trimmed_def_paths called but no diagnostics emitted; \
use `DelayDm` for lints or `with_no_trimmed_paths` for debugging"
"must_produce_diag: `trimmed_def_paths` called but no diagnostics emitted; \
use `DelayDm` for lints or `with_no_trimmed_paths` for debugging. \
called at: {backtrace}"
);
}
}
Expand Down Expand Up @@ -721,7 +722,7 @@ impl DiagCtxt {
*delayed_bugs = Default::default();
*deduplicated_err_count = 0;
*deduplicated_warn_count = 0;
*must_produce_diag = false;
*must_produce_diag = None;
*has_printed = false;
*suppressed_expected_diag = false;
*taught_diagnostics = Default::default();
Expand Down Expand Up @@ -1091,8 +1092,13 @@ impl DiagCtxt {

/// Used when trimmed_def_paths is called and we must produce a diagnostic
/// to justify its cost.
#[track_caller]
pub fn set_must_produce_diag(&self) {
self.inner.borrow_mut().must_produce_diag = true;
assert!(
self.inner.borrow().must_produce_diag.is_none(),
"should only need to collect a backtrace once"
);
self.inner.borrow_mut().must_produce_diag = Some(Backtrace::capture());
compiler-errors marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1387,7 +1393,7 @@ impl DiagCtxtInner {
deduplicated_err_count: 0,
deduplicated_warn_count: 0,
emitter,
must_produce_diag: false,
must_produce_diag: None,
has_printed: false,
suppressed_expected_diag: false,
taught_diagnostics: Default::default(),
Expand Down
Loading