Skip to content

Commit 7098092

Browse files
committed
Respect RUST_BACKTRACE for delayed bugs
Sometimes, especially with MIR validation, the backtraces from delayed bugs are noise and make it harder to look at them. Respect the environment variable and don't print it when the user doesn't want it.
1 parent e410606 commit 7098092

File tree

1 file changed

+14
-4
lines changed
  • compiler/rustc_errors/src

1 file changed

+14
-4
lines changed

compiler/rustc_errors/src/lib.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
383383
pub use diagnostic_impls::{
384384
DiagnosticArgFromDisplay, DiagnosticSymbolList, LabelKind, SingleLabelManySpans,
385385
};
386-
use std::backtrace::Backtrace;
386+
use std::backtrace::{Backtrace, BacktraceStatus};
387387

388388
/// A handler deals with errors and other compiler output.
389389
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
@@ -1331,7 +1331,7 @@ impl HandlerInner {
13311331
// once *any* errors were emitted (and truncate `delayed_span_bugs`
13321332
// when an error is first emitted, also), but maybe there's a case
13331333
// in which that's not sound? otherwise this is really inefficient.
1334-
let backtrace = std::backtrace::Backtrace::force_capture();
1334+
let backtrace = std::backtrace::Backtrace::capture();
13351335
self.delayed_span_bugs
13361336
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
13371337

@@ -1620,7 +1620,7 @@ impl HandlerInner {
16201620
if self.flags.report_delayed_bugs {
16211621
self.emit_diagnostic(&mut diagnostic);
16221622
}
1623-
let backtrace = std::backtrace::Backtrace::force_capture();
1623+
let backtrace = std::backtrace::Backtrace::capture();
16241624
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
16251625
}
16261626

@@ -1739,7 +1739,17 @@ impl DelayedDiagnostic {
17391739
}
17401740

17411741
fn decorate(mut self) -> Diagnostic {
1742-
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
1742+
match self.note.status() {
1743+
BacktraceStatus::Captured => {
1744+
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
1745+
}
1746+
// Avoid the needless newline when no backtrace has been captured,
1747+
// the display impl should just be a single line.
1748+
_ => {
1749+
self.inner.note(format!("delayed at {} - {}", self.inner.emitted_at, self.note));
1750+
}
1751+
}
1752+
17431753
self.inner
17441754
}
17451755
}

0 commit comments

Comments
 (0)