]> git.lizzy.rs Git - rust.git/commitdiff
Move librustc panic handler into the new one
authorJonas Schievink <jonasschievink@gmail.com>
Mon, 6 May 2019 22:14:40 +0000 (00:14 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Fri, 30 Aug 2019 10:34:20 +0000 (12:34 +0200)
src/librustc/Cargo.toml
src/librustc/lib.rs
src/librustc/util/common.rs
src/librustc_driver/lib.rs

index 0222a3dde7ab977e656d83a50685e891f663bd62..4ab982f6f91f59d311c56b0255bc01e02262753b 100644 (file)
@@ -15,7 +15,6 @@ bitflags = "1.0"
 fmt_macros = { path = "../libfmt_macros" }
 graphviz = { path = "../libgraphviz" }
 jobserver = "0.1"
-lazy_static = "1.0.0"
 num_cpus = "1.0"
 scoped-tls = "1.0"
 log = { version = "0.4", features = ["release_max_level_info", "std"] }
index 368f5bb64fe6c056afda13fd41fc31cabc1033ec..c2befabcb69b38ea21e3f66b9020fe0b1692d817 100644 (file)
@@ -68,7 +68,6 @@
 
 #[macro_use] extern crate bitflags;
 extern crate getopts;
-#[macro_use] extern crate lazy_static;
 #[macro_use] extern crate scoped_tls;
 #[cfg(windows)]
 extern crate libc;
index 7118d05204c3be500733e05294d2e26b879f256e..2475b93d95f32af84ee0ded0da2e2cc39f199347 100644 (file)
@@ -5,17 +5,13 @@
 use std::cell::{RefCell, Cell};
 use std::fmt::Debug;
 use std::hash::Hash;
-use std::panic;
-use std::env;
 use std::time::{Duration, Instant};
 
 use std::sync::mpsc::{Sender};
 use syntax_pos::{SpanData};
 use syntax::symbol::{Symbol, sym};
 use rustc_macros::HashStable;
-use crate::ty::TyCtxt;
 use crate::dep_graph::{DepNode};
-use lazy_static;
 use crate::session::Session;
 
 #[cfg(test)]
 
 thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
 
-lazy_static! {
-    static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
-        let hook = panic::take_hook();
-        panic::set_hook(Box::new(panic_hook));
-        hook
-    };
-}
-
-fn panic_hook(info: &panic::PanicInfo<'_>) {
-    (*DEFAULT_HOOK)(info);
-
-    let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
-
-    if backtrace {
-        TyCtxt::try_print_query_stack();
-    }
-
-    #[cfg(windows)]
-    unsafe {
-        if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
-            extern "system" {
-                fn DebugBreak();
-            }
-            // Trigger a debugger if we crashed during bootstrap.
-            DebugBreak();
-        }
-    }
-}
-
-pub fn install_panic_hook() {
-    lazy_static::initialize(&DEFAULT_HOOK);
-}
-
 /// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
 #[derive(Clone,Debug)]
 pub struct ProfQDumpParams {
index 5b7ac14ba3585bd7af27465db03ac7ca8e4ecae6..ece82233e995191c7456c1cbfa87dd8f549e8d5f 100644 (file)
@@ -38,8 +38,8 @@
 use rustc::lint::Lint;
 use rustc::lint;
 use rustc::hir::def_id::LOCAL_CRATE;
-use rustc::util::common::{ErrorReported, install_panic_hook, print_time_passes_entry};
-use rustc::util::common::{set_time_depth, time};
+use rustc::ty::TyCtxt;
+use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
 use rustc_metadata::locator;
 use rustc_metadata::cstore::CStore;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
@@ -164,8 +164,6 @@ pub fn run_compiler(
         None => return Ok(()),
     };
 
-    install_panic_hook();
-
     let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
 
     let mut dummy_config = |sopts, cfg, diagnostic_output| {
@@ -1169,9 +1167,10 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
 }
 
 pub fn report_ice(info: &panic::PanicInfo<'_>) {
+    // Invoke the default handler, which prints the actual panic message and optionally a backtrace
     (*DEFAULT_HOOK)(info);
 
-    // Thread panicked without emitting a fatal diagnostic
+    // Print the infamous ICE message
     eprintln!();
 
     let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
@@ -1212,6 +1211,24 @@ pub fn report_ice(info: &panic::PanicInfo<'_>) {
                      note,
                      errors::Level::Note);
     }
+
+    // If backtraces are enabled, also print the query stack
+    let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
+
+    if backtrace {
+        TyCtxt::try_print_query_stack();
+    }
+
+    #[cfg(windows)]
+    unsafe {
+        if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
+            extern "system" {
+                fn DebugBreak();
+            }
+            // Trigger a debugger if we crashed during bootstrap
+            DebugBreak();
+        }
+    }
 }
 
 pub fn install_ice_hook() {