Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ab0e2aa

Browse files
committed
Revert "Don't PrintOnPanic on fatal errors"
This reverts commit b5ac64b. It entirely breaks PrintOnPanic as ICE seems to be considered a fatal error too.
1 parent 14ca1df commit ab0e2aa

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/base.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
2929
module: &mut dyn Module,
3030
instance: Instance<'tcx>,
3131
) {
32-
let _inst_guard = crate::PrintOnPanic(Some(tcx.sess), || {
33-
format!("{:?} {}", instance, tcx.symbol_name(instance).name)
34-
});
32+
let _inst_guard =
33+
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
3534

3635
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
3736
let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance);
@@ -49,7 +48,7 @@ pub(crate) fn codegen_fn<'tcx>(
4948
debug_assert!(!instance.substs.needs_infer());
5049

5150
let mir = tcx.instance_mir(instance.def);
52-
let _mir_guard = crate::PrintOnPanic(Some(tcx.sess), || {
51+
let _mir_guard = crate::PrintOnPanic(|| {
5352
let mut buf = Vec::new();
5453
with_no_trimmed_paths!({
5554
rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf)
@@ -177,7 +176,7 @@ pub(crate) fn compile_fn(
177176
write!(clif, " {}", isa_flag).unwrap();
178177
}
179178
writeln!(clif, "\n").unwrap();
180-
crate::PrintOnPanic(None, move || {
179+
crate::PrintOnPanic(move || {
181180
let mut clif = clif.clone();
182181
::cranelift_codegen::write::decorate_function(
183182
&mut &clif_comments_clone,
@@ -498,7 +497,7 @@ fn codegen_stmt<'tcx>(
498497
#[allow(unused_variables)] cur_block: Block,
499498
stmt: &Statement<'tcx>,
500499
) {
501-
let _print_guard = crate::PrintOnPanic(Some(fx.tcx.sess), || format!("stmt {:?}", stmt));
500+
let _print_guard = crate::PrintOnPanic(|| format!("stmt {:?}", stmt));
502501

503502
fx.set_debug_loc(stmt.source_info);
504503

src/driver/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ fn predefine_mono_items<'tcx>(
2323
match mono_item {
2424
MonoItem::Fn(instance) => {
2525
let name = tcx.symbol_name(instance).name;
26-
let _inst_guard =
27-
crate::PrintOnPanic(Some(tcx.sess), || format!("{:?} {}", instance, name));
26+
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
2827
let sig =
2928
get_function_sig(tcx, module.target_config().default_call_conv, instance);
3029
let linkage = crate::linkage::get_clif_linkage(

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ mod prelude {
113113
pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};
114114
}
115115

116-
struct PrintOnPanic<'a, F: Fn() -> String>(Option<&'a Session>, F);
117-
impl<'a, F: Fn() -> String> Drop for PrintOnPanic<'a, F> {
116+
struct PrintOnPanic<F: Fn() -> String>(F);
117+
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
118118
fn drop(&mut self) {
119-
if ::std::thread::panicking() && self.0.map_or(true, |sess| sess.has_errors().is_none()) {
120-
println!("{}", (self.1)());
119+
if ::std::thread::panicking() {
120+
println!("{}", (self.0)());
121121
}
122122
}
123123
}

0 commit comments

Comments
 (0)