From ab0e2aaed2098cecf5eb9e2c2ee196e794d79db9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 16 Dec 2022 13:00:36 +0000 Subject: [PATCH] Revert "Don't PrintOnPanic on fatal errors" This reverts commit b5ac64b4cf33809b182a6f7c63a7c4e874fb3056. It entirely breaks PrintOnPanic as ICE seems to be considered a fatal error too. --- src/base.rs | 11 +++++------ src/driver/mod.rs | 3 +-- src/lib.rs | 8 ++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/base.rs b/src/base.rs index 7df11cf4aed..89d955e8bf2 100644 --- a/src/base.rs +++ b/src/base.rs @@ -29,9 +29,8 @@ pub(crate) fn codegen_and_compile_fn<'tcx>( module: &mut dyn Module, instance: Instance<'tcx>, ) { - let _inst_guard = crate::PrintOnPanic(Some(tcx.sess), || { - format!("{:?} {}", instance, tcx.symbol_name(instance).name) - }); + let _inst_guard = + crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name)); let cached_func = std::mem::replace(&mut cached_context.func, Function::new()); let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance); @@ -49,7 +48,7 @@ pub(crate) fn codegen_fn<'tcx>( debug_assert!(!instance.substs.needs_infer()); let mir = tcx.instance_mir(instance.def); - let _mir_guard = crate::PrintOnPanic(Some(tcx.sess), || { + let _mir_guard = crate::PrintOnPanic(|| { let mut buf = Vec::new(); with_no_trimmed_paths!({ rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf) @@ -177,7 +176,7 @@ pub(crate) fn compile_fn( write!(clif, " {}", isa_flag).unwrap(); } writeln!(clif, "\n").unwrap(); - crate::PrintOnPanic(None, move || { + crate::PrintOnPanic(move || { let mut clif = clif.clone(); ::cranelift_codegen::write::decorate_function( &mut &clif_comments_clone, @@ -498,7 +497,7 @@ fn codegen_stmt<'tcx>( #[allow(unused_variables)] cur_block: Block, stmt: &Statement<'tcx>, ) { - let _print_guard = crate::PrintOnPanic(Some(fx.tcx.sess), || format!("stmt {:?}", stmt)); + let _print_guard = crate::PrintOnPanic(|| format!("stmt {:?}", stmt)); fx.set_debug_loc(stmt.source_info); diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 1ab4fdf6155..6e925cea277 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -23,8 +23,7 @@ fn predefine_mono_items<'tcx>( match mono_item { MonoItem::Fn(instance) => { let name = tcx.symbol_name(instance).name; - let _inst_guard = - crate::PrintOnPanic(Some(tcx.sess), || format!("{:?} {}", instance, name)); + let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name)); let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance); let linkage = crate::linkage::get_clif_linkage( diff --git a/src/lib.rs b/src/lib.rs index 49b5dc32144..629d79d5012 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,11 +113,11 @@ mod prelude { pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue}; } -struct PrintOnPanic<'a, F: Fn() -> String>(Option<&'a Session>, F); -impl<'a, F: Fn() -> String> Drop for PrintOnPanic<'a, F> { +struct PrintOnPanic String>(F); +impl String> Drop for PrintOnPanic { fn drop(&mut self) { - if ::std::thread::panicking() && self.0.map_or(true, |sess| sess.has_errors().is_none()) { - println!("{}", (self.1)()); + if ::std::thread::panicking() { + println!("{}", (self.0)()); } } }