diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index f88c619bf7791..a96c277d4b555 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -185,27 +185,29 @@ pub fn run(run_compiler: F) -> isize where F: FnOnce() -> (CompileResult, Option) + Send + 'static { let result = monitor(move || { - let (result, session) = run_compiler(); - if let Err(CompileIncomplete::Errored(_)) = result { - match session { - Some(sess) => { - sess.abort_if_errors(); - panic!("error reported but abort_if_errors didn't abort???"); - } - None => { - let emitter = - errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, - None, - true, - false); - let handler = errors::Handler::with_emitter(true, false, Box::new(emitter)); - handler.emit(&MultiSpan::new(), - "aborting due to previous error(s)", - errors::Level::Fatal); - panic::resume_unwind(Box::new(errors::FatalErrorMarker)); + syntax::with_globals(|| { + let (result, session) = run_compiler(); + if let Err(CompileIncomplete::Errored(_)) = result { + match session { + Some(sess) => { + sess.abort_if_errors(); + panic!("error reported but abort_if_errors didn't abort???"); + } + None => { + let emitter = + errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, + None, + true, + false); + let handler = errors::Handler::with_emitter(true, false, Box::new(emitter)); + handler.emit(&MultiSpan::new(), + "aborting due to previous error(s)", + errors::Level::Fatal); + panic::resume_unwind(Box::new(errors::FatalErrorMarker)); + } } } - } + }); }); match result { @@ -471,17 +473,15 @@ pub fn run_compiler<'a>(args: &[String], emitter_dest: Option>) -> (CompileResult, Option) { - syntax::with_globals(|| { - let matches = match handle_options(args) { - Some(matches) => matches, - None => return (Ok(()), None), - }; + let matches = match handle_options(args) { + Some(matches) => matches, + None => return (Ok(()), None), + }; - let (sopts, cfg) = config::build_session_options_and_crate_config(&matches); + let (sopts, cfg) = config::build_session_options_and_crate_config(&matches); - driver::spawn_thread_pool(sopts, |sopts| { - run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest) - }) + driver::spawn_thread_pool(sopts, |sopts| { + run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest) }) } diff --git a/src/test/run-pass-fulldeps/compiler-calls.rs b/src/test/run-pass-fulldeps/compiler-calls.rs index baf9e0d5dc5a6..6283d054373c1 100644 --- a/src/test/run-pass-fulldeps/compiler-calls.rs +++ b/src/test/run-pass-fulldeps/compiler-calls.rs @@ -92,7 +92,9 @@ fn main() { let tc = TestCalls { count: &mut count }; // we should never get use this filename, but lets make sure they are valid args. let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; - rustc_driver::run_compiler(&args, Box::new(tc), None, None); + syntax::with_globals(|| { + rustc_driver::run_compiler(&args, Box::new(tc), None, None); + }); } assert_eq!(count, 30); }