Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move with_globals setup from run_compiler to run
  • Loading branch information
Zoxc committed Aug 27, 2018
1 parent 7219130 commit bd04796
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
56 changes: 28 additions & 28 deletions src/librustc_driver/lib.rs
Expand Up @@ -185,27 +185,29 @@ pub fn run<F>(run_compiler: F) -> isize
where F: FnOnce() -> (CompileResult, Option<Session>) + 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 {
Expand Down Expand Up @@ -471,17 +473,15 @@ pub fn run_compiler<'a>(args: &[String],
emitter_dest: Option<Box<dyn Write + Send>>)
-> (CompileResult, Option<Session>)
{
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)
})
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass-fulldeps/compiler-calls.rs
Expand Up @@ -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);
}

0 comments on commit bd04796

Please sign in to comment.