Rollup merge of #47933 - Zoxc:plugin-panics, r=nikomatsakis
Do not run the default panic hook inside procedural macros. Fixes #47812 r? @nikomatsakis
This commit is contained in:
commit
abf4d70da8
|
@ -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",
|
||||
|
|
|
@ -844,6 +844,12 @@ pub mod __internal {
|
|||
})
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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)]
|
||||
|
@ -81,6 +82,7 @@ extern crate core;
|
|||
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;
|
||||
|
@ -92,6 +94,7 @@ extern crate rustc_errors as errors;
|
|||
#[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
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use std::ffi::CString;
|
|||
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 std::sync::mpsc::{Sender};
|
|||
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 @@ pub struct ErrorReported;
|
|||
|
||||
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));
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use rustc::middle::cstore::CrateStore;
|
|||
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 @@ pub fn compile_input(trans: Box<TransCrate>,
|
|||
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!
|
||||
|
|
Loading…
Reference in New Issue