Skip to content

Commit

Permalink
Rollup merge of #112359 - Nilstrieb:i-can-only-handle-so-many-backtra…
Browse files Browse the repository at this point in the history
…ces, r=compiler-errors

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.
  • Loading branch information
Dylan-DPC authored Jun 7, 2023
2 parents 42cf6da + 7098092 commit 1dc4b40
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
pub use diagnostic_impls::{
DiagnosticArgFromDisplay, DiagnosticSymbolList, LabelKind, SingleLabelManySpans,
};
use std::backtrace::Backtrace;
use std::backtrace::{Backtrace, BacktraceStatus};

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

Expand Down Expand Up @@ -1620,7 +1620,7 @@ impl HandlerInner {
if self.flags.report_delayed_bugs {
self.emit_diagnostic(&mut diagnostic);
}
let backtrace = std::backtrace::Backtrace::force_capture();
let backtrace = std::backtrace::Backtrace::capture();
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
}

Expand Down Expand Up @@ -1739,7 +1739,17 @@ impl DelayedDiagnostic {
}

fn decorate(mut self) -> Diagnostic {
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
match self.note.status() {
BacktraceStatus::Captured => {
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
}
// Avoid the needless newline when no backtrace has been captured,
// the display impl should just be a single line.
_ => {
self.inner.note(format!("delayed at {} - {}", self.inner.emitted_at, self.note));
}
}

self.inner
}
}
Expand Down

0 comments on commit 1dc4b40

Please sign in to comment.