Skip to content

Commit e296ed3

Browse files
Move librustc panic handler into the new one
1 parent a8926a5 commit e296ed3

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed

src/librustc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ bitflags = "1.0"
1515
fmt_macros = { path = "../libfmt_macros" }
1616
graphviz = { path = "../libgraphviz" }
1717
jobserver = "0.1"
18-
lazy_static = "1.0.0"
1918
num_cpus = "1.0"
2019
scoped-tls = "1.0"
2120
log = { version = "0.4", features = ["release_max_level_info", "std"] }

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868

6969
#[macro_use] extern crate bitflags;
7070
extern crate getopts;
71-
#[macro_use] extern crate lazy_static;
7271
#[macro_use] extern crate scoped_tls;
7372
#[cfg(windows)]
7473
extern crate libc;

src/librustc/util/common.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ use rustc_data_structures::{fx::FxHashMap, sync::Lock};
55
use std::cell::{RefCell, Cell};
66
use std::fmt::Debug;
77
use std::hash::Hash;
8-
use std::panic;
9-
use std::env;
108
use std::time::{Duration, Instant};
119

1210
use std::sync::mpsc::{Sender};
1311
use syntax_pos::{SpanData};
1412
use syntax::symbol::{Symbol, sym};
1513
use rustc_macros::HashStable;
16-
use crate::ty::TyCtxt;
1714
use crate::dep_graph::{DepNode};
18-
use lazy_static;
1915
use crate::session::Session;
2016

2117
#[cfg(test)]
@@ -31,39 +27,6 @@ pub struct ErrorReported;
3127

3228
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
3329

34-
lazy_static! {
35-
static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
36-
let hook = panic::take_hook();
37-
panic::set_hook(Box::new(panic_hook));
38-
hook
39-
};
40-
}
41-
42-
fn panic_hook(info: &panic::PanicInfo<'_>) {
43-
(*DEFAULT_HOOK)(info);
44-
45-
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
46-
47-
if backtrace {
48-
TyCtxt::try_print_query_stack();
49-
}
50-
51-
#[cfg(windows)]
52-
unsafe {
53-
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
54-
extern "system" {
55-
fn DebugBreak();
56-
}
57-
// Trigger a debugger if we crashed during bootstrap.
58-
DebugBreak();
59-
}
60-
}
61-
}
62-
63-
pub fn install_panic_hook() {
64-
lazy_static::initialize(&DEFAULT_HOOK);
65-
}
66-
6730
/// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
6831
#[derive(Clone,Debug)]
6932
pub struct ProfQDumpParams {

src/librustc_driver/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use rustc::session::{early_error, early_warn};
3838
use rustc::lint::Lint;
3939
use rustc::lint;
4040
use rustc::hir::def_id::LOCAL_CRATE;
41-
use rustc::util::common::{ErrorReported, install_panic_hook, print_time_passes_entry};
42-
use rustc::util::common::{set_time_depth, time};
41+
use rustc::ty::TyCtxt;
42+
use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
4343
use rustc_metadata::locator;
4444
use rustc_metadata::cstore::CStore;
4545
use rustc_codegen_utils::codegen_backend::CodegenBackend;
@@ -164,8 +164,6 @@ pub fn run_compiler(
164164
None => return Ok(()),
165165
};
166166

167-
install_panic_hook();
168-
169167
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
170168

171169
let mut dummy_config = |sopts, cfg, diagnostic_output| {
@@ -1169,9 +1167,10 @@ lazy_static! {
11691167
}
11701168

11711169
pub fn report_ice(info: &panic::PanicInfo<'_>) {
1170+
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
11721171
(*DEFAULT_HOOK)(info);
11731172

1174-
// Thread panicked without emitting a fatal diagnostic
1173+
// Print the infamous ICE message
11751174
eprintln!();
11761175

11771176
let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
@@ -1212,6 +1211,24 @@ pub fn report_ice(info: &panic::PanicInfo<'_>) {
12121211
note,
12131212
errors::Level::Note);
12141213
}
1214+
1215+
// If backtraces are enabled, also print the query stack
1216+
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
1217+
1218+
if backtrace {
1219+
TyCtxt::try_print_query_stack();
1220+
}
1221+
1222+
#[cfg(windows)]
1223+
unsafe {
1224+
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
1225+
extern "system" {
1226+
fn DebugBreak();
1227+
}
1228+
// Trigger a debugger if we crashed during bootstrap
1229+
DebugBreak();
1230+
}
1231+
}
12151232
}
12161233

12171234
pub fn install_ice_hook() {

0 commit comments

Comments
 (0)