Skip to content

Commit d798e22

Browse files
Rollup merge of rust-lang#106317 - compiler-errors:restore-the-backtraces, r=jyn514
Only deduplicate stack traces for good path bugs Fixes rust-lang#106267 Restores backtraces for `bug!` and `delay_span_bug` after rust-lang#106056. Only `delay_good_path_bug` needed its backtraces to be deduplicated, since it spits out the backtrace where it was created when it's being emitted. Before: ``` error: internal compiler error: /home/ubuntu/rust2/compiler/rustc_middle/src/ty/relate.rs:638:13: var types encountered in super_relate_consts: Const { ty: usize, kind: Infer(Var(_#0c)) } Const { ty: usize, kind: Param(N/#1) } note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.68.0-dev running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `<impl at /home/ubuntu/test.rs:7:1: 7:34>::trigger` #1 [typeck_item_bodies] type-checking all item bodies #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors ``` Hmm... that's a little bare. After: ``` error: internal compiler error: /home/ubuntu/rust2/compiler/rustc_middle/src/ty/relate.rs:638:13: var types encountered in super_relate_consts: Const { ty: usize, kind: Infer(Var(_#0c)) } Const { ty: usize, kind: Param(N/#1) } thread 'rustc' panicked at 'Box<dyn Any>', /home/ubuntu/rust2/compiler/rustc_errors/src/lib.rs:1599:9 stack backtrace: 0: 0x7ffb5b41bdd1 - std::backtrace_rs::backtrace::libunwind::trace::h26056f81198c6594 at /home/ubuntu/rust2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7ffb5b41bdd1 - std::backtrace_rs::backtrace::trace_unsynchronized::hacfb345a0c6d5bb1 at /home/ubuntu/rust2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7ffb5b41bdd1 - std::sys_common::backtrace::_print_fmt::h18ea6016ac8030f3 at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7ffb5b41bdd1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he35dde201d0c2d09 at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7ffb5b4a0308 - core::fmt::write::h094ad263467a053c at /home/ubuntu/rust2/library/core/src/fmt/mod.rs:1208:17 5: 0x7ffb5b43caf1 - std::io::Write::write_fmt::hd47b4e2324b4d9b7 at /home/ubuntu/rust2/library/std/src/io/mod.rs:1682:15 6: 0x7ffb5b41bbfa - std::sys_common::backtrace::_print::h43044162653a17fc at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7ffb5b41bbfa - std::sys_common::backtrace::print::hc8605da258fa5aeb at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7ffb5b3ffb87 - std::panicking::default_hook::{{closure}}::h9e37f23f75122a15 9: 0x7ffb5b3ff97b - std::panicking::default_hook::h602873a063f84da2 at /home/ubuntu/rust2/library/std/src/panicking.rs:286:9 10: 0x7ffb5be192b2 - <alloc[48d7b30605060536]::boxed::Box<dyn for<'a, 'b> core[672e3947e150d6c6]::ops::function::Fn<(&'a core[672e3947e150d6c6]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[672e3947e150d6c6]::marker::Send + core[672e3947e150d6c6]::marker::Sync> as core[672e3947e150d6c6]::ops::function::Fn<(&core[672e3947e150d6c6]::panic::panic_info::PanicInfo,)>>::call at /home/ubuntu/rust2/library/alloc/src/boxed.rs:2002:9 11: 0x7ffb5be192b2 - rustc_driver[f5b6d32d8905ecdd]::DEFAULT_HOOK::{closure#0}::{closure#0} at /home/ubuntu/rust2/compiler/rustc_driver/src/lib.rs:1204:17 12: 0x7ffb5b4000d3 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfd13333ca953ae8e at /home/ubuntu/rust2/library/alloc/src/boxed.rs:2002:9 13: 0x7ffb5b4000d3 - std::panicking::rust_panic_with_hook::h45753e10264ebe7e at /home/ubuntu/rust2/library/std/src/panicking.rs:692:13 14: 0x7ffb5e8b3a63 - std[3330b4673efabfce]::panicking::begin_panic::<rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>::{closure#0} [... FRAMES INTENTIONALLY OMITTED BECAUSE GITHUB GOT ANGRY ...] 186: 0x7ffb5bea5554 - <std[3330b4673efabfce]::thread::Builder>::spawn_unchecked_::<rustc_interface[947706ead88047d0]::util::run_in_thread_pool_with_globals<rustc_interface[947706ead88047d0]::interface::run_compiler<core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>, rustc_driver[f5b6d32d8905ecdd]::run_compiler::{closure#1}>::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#1} at /home/ubuntu/rust2/library/std/src/thread/mod.rs:549:30 187: 0x7ffb5bea5554 - <<std[3330b4673efabfce]::thread::Builder>::spawn_unchecked_<rustc_interface[947706ead88047d0]::util::run_in_thread_pool_with_globals<rustc_interface[947706ead88047d0]::interface::run_compiler<core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>, rustc_driver[f5b6d32d8905ecdd]::run_compiler::{closure#1}>::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#1} as core[672e3947e150d6c6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} at /home/ubuntu/rust2/library/core/src/ops/function.rs:250:5 188: 0x7ffb5b433968 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he8b26fc22c6f51ec at /home/ubuntu/rust2/library/alloc/src/boxed.rs:1988:9 189: 0x7ffb5b433968 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5cf9cbe75a8c3ddc at /home/ubuntu/rust2/library/alloc/src/boxed.rs:1988:9 190: 0x7ffb5b41199c - std::sys::unix::thread::Thread::new::thread_start::h2d6dd4455e97d031 at /home/ubuntu/rust2/library/std/src/sys/unix/thread.rs:108:17 191: 0x7ffb5441b609 - start_thread 192: 0x7ffb5b282133 - clone 193: 0x0 - <unknown> note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.68.0-dev running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `<impl at /home/ubuntu/test.rs:7:1: 7:34>::trigger` #1 [typeck_item_bodies] type-checking all item bodies #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0601`. ```
2 parents 7f930b4 + 5d62a73 commit d798e22

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)