Skip to content

Commit 5d62a73

Browse files
committedDec 31, 2022
Only deduplicate stack traces for good path bugs
1 parent 7c99186 commit 5d62a73

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed
 

‎compiler/rustc_driver/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
11991199
};
12001200

12011201
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1202-
// Don't do this for `ExplicitBug`, which has an unhelpful message and backtrace.
1203-
if !info.payload().is::<rustc_errors::ExplicitBug>() {
1202+
// Don't do this for `GoodPathBug`, which already emits its own more useful backtrace.
1203+
if !info.payload().is::<rustc_errors::GoodPathBug>() {
12041204
(*DEFAULT_HOOK)(info);
12051205

12061206
// Separate the output with an empty line
@@ -1237,7 +1237,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12371237

12381238
// a .span_bug or .bug call has already printed what
12391239
// it wants to print.
1240-
if !info.payload().is::<rustc_errors::ExplicitBug>() {
1240+
if !info.payload().is::<rustc_errors::ExplicitBug>()
1241+
&& !info.payload().is::<rustc_errors::GoodPathBug>()
1242+
{
12411243
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
12421244
handler.emit_diagnostic(&mut d);
12431245
}

‎compiler/rustc_errors/src/lib.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ use rustc_span::source_map::SourceMap;
4040
use rustc_span::HashStableContext;
4141
use rustc_span::{Loc, Span};
4242

43+
use std::any::Any;
4344
use std::borrow::Cow;
45+
use std::fmt;
4446
use std::hash::Hash;
4547
use std::num::NonZeroUsize;
4648
use std::panic;
4749
use std::path::Path;
48-
use std::{error, fmt};
4950

5051
use termcolor::{Color, ColorSpec};
5152

@@ -361,16 +362,11 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
361362

362363
/// Signifies that the compiler died with an explicit call to `.bug`
363364
/// or `.span_bug` rather than a failed assertion, etc.
364-
#[derive(Copy, Clone, Debug)]
365365
pub struct ExplicitBug;
366366

367-
impl fmt::Display for ExplicitBug {
368-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
369-
write!(f, "parser internal bug")
370-
}
371-
}
372-
373-
impl error::Error for ExplicitBug {}
367+
/// Signifies that the compiler died with an explicit call to `.delay_good_path_bug`
368+
/// rather than a failed assertion, etc.
369+
pub struct GoodPathBug;
374370

375371
pub use diagnostic::{
376372
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
@@ -507,7 +503,11 @@ impl Drop for HandlerInner {
507503

508504
if !self.has_errors() {
509505
let bugs = std::mem::replace(&mut self.delayed_span_bugs, Vec::new());
510-
self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
506+
self.flush_delayed(
507+
bugs,
508+
"no errors encountered even though `delay_span_bug` issued",
509+
ExplicitBug,
510+
);
511511
}
512512

513513
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
@@ -520,6 +520,7 @@ impl Drop for HandlerInner {
520520
self.flush_delayed(
521521
bugs.into_iter().map(DelayedDiagnostic::decorate),
522522
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
523+
GoodPathBug,
523524
);
524525
}
525526

@@ -1203,7 +1204,11 @@ impl Handler {
12031204
pub fn flush_delayed(&self) {
12041205
let mut inner = self.inner.lock();
12051206
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
1206-
inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
1207+
inner.flush_delayed(
1208+
bugs,
1209+
"no errors encountered even though `delay_span_bug` issued",
1210+
ExplicitBug,
1211+
);
12071212
}
12081213
}
12091214

@@ -1580,6 +1585,7 @@ impl HandlerInner {
15801585
&mut self,
15811586
bugs: impl IntoIterator<Item = Diagnostic>,
15821587
explanation: impl Into<DiagnosticMessage> + Copy,
1588+
panic_with: impl Any + Send + 'static,
15831589
) {
15841590
let mut no_bugs = true;
15851591
for mut bug in bugs {
@@ -1607,7 +1613,7 @@ impl HandlerInner {
16071613

16081614
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
16091615
if !no_bugs {
1610-
panic::panic_any(ExplicitBug);
1616+
panic::panic_any(panic_with);
16111617
}
16121618
}
16131619

0 commit comments

Comments
 (0)
Please sign in to comment.