From bd04796d6e7d7fbbc891edd28d4b6fdd02496180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 23 Aug 2018 05:05:37 +0200 Subject: [PATCH] Move with_globals setup from run_compiler to run --- src/librustc_driver/lib.rs | 56 ++++++++++---------- src/test/run-pass-fulldeps/compiler-calls.rs | 4 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index f88c619bf77..a96c277d4b5 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 baf9e0d5dc5..6283d054373 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); }