Do not run the default panic hook inside procedural macros. Fixes #47812

This commit is contained in:
John Kåre Alsaker
2018-02-01 18:10:56 +01:00
parent 27a046e933
commit 9d3719bcfa
8 changed files with 40 additions and 3 deletions
+2
View File
@@ -1623,7 +1623,9 @@ dependencies = [
"fmt_macros 0.0.0",
"graphviz 0.0.0",
"jobserver 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc_macro 0.0.0",
"rustc_apfloat 0.0.0",
"rustc_back 0.0.0",
"rustc_const_math 0.0.0",
+6
View File
@@ -844,6 +844,12 @@ fn drop(&mut self) {
})
}
pub fn in_sess() -> bool
{
let p = CURRENT_SESS.with(|p| p.get());
!p.0.is_null()
}
pub fn with_sess<F, R>(f: F) -> R
where F: FnOnce((&ParseSess, Mark)) -> R
{
+2
View File
@@ -14,7 +14,9 @@ bitflags = "1.0"
fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
jobserver = "0.1"
lazy_static = "1.0.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
proc_macro = { path = "../libproc_macro" }
rustc_apfloat = { path = "../librustc_apfloat" }
rustc_back = { path = "../librustc_back" }
rustc_const_math = { path = "../librustc_const_math" }
+3
View File
@@ -60,6 +60,7 @@
#![feature(never_type)]
#![feature(non_exhaustive)]
#![feature(nonzero)]
#![feature(proc_macro_internals)]
#![feature(quote)]
#![feature(refcell_replace_swap)]
#![feature(rustc_diagnostic_macros)]
@@ -80,6 +81,7 @@
extern crate fmt_macros;
extern crate getopts;
extern crate graphviz;
#[macro_use] extern crate lazy_static;
#[cfg(windows)]
extern crate libc;
extern crate rustc_back;
@@ -91,6 +93,7 @@
#[macro_use] extern crate syntax;
extern crate syntax_pos;
extern crate jobserver;
extern crate proc_macro;
extern crate serialize as rustc_serialize; // used by deriving
+21
View File
@@ -16,6 +16,7 @@
use std::fmt::Debug;
use std::hash::{Hash, BuildHasher};
use std::iter::repeat;
use std::panic;
use std::path::Path;
use std::time::{Duration, Instant};
@@ -23,6 +24,8 @@
use syntax_pos::{SpanData};
use ty::maps::{QueryMsg};
use dep_graph::{DepNode};
use proc_macro;
use lazy_static;
// The name of the associated type for `Fn` return types
pub const FN_OUTPUT_NAME: &'static str = "Output";
@@ -34,6 +37,24 @@
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
lazy_static! {
static ref DEFAULT_HOOK: Box<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) {
if !proc_macro::__internal::in_sess() {
(*DEFAULT_HOOK)(info)
}
}
pub fn install_panic_hook() {
lazy_static::initialize(&DEFAULT_HOOK);
}
/// Initialized for -Z profile-queries
thread_local!(static PROFQ_CHAN: RefCell<Option<Sender<ProfileQueriesMsg>>> = RefCell::new(None));
+3 -1
View File
@@ -24,7 +24,7 @@
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::traits;
use rustc::util::common::{ErrorReported, time};
use rustc::util::common::{ErrorReported, time, install_panic_hook};
use rustc_allocator as allocator;
use rustc_borrowck as borrowck;
use rustc_incremental;
@@ -123,6 +123,8 @@ macro_rules! controller_entry_point {
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
let crate_name =
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
install_panic_hook();
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
phase_2_configure_and_expand(
sess,
@@ -9,6 +9,7 @@
// except according to those terms.
// aux-build:derive-panic.rs
// compile-flags:--error-format human
#[macro_use]
extern crate derive_panic;
@@ -1,7 +1,7 @@
error: proc-macro derive panicked
--> $DIR/load-panic.rs:16:10
--> $DIR/load-panic.rs:17:10
|
16 | #[derive(A)]
17 | #[derive(A)]
| ^
|
= help: message: nope!